Close at least one of the streams in IBlocks.java

This commit is contained in:
MattBDev 2020-03-04 00:52:42 -05:00
parent b818c03f84
commit 8eab3d098c

View File

@ -52,13 +52,14 @@ public interface IBlocks extends Trimable {
buffer = new byte[1024];
}
BlockRegistry registry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry();
BlockRegistry registry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry();
FastByteArrayOutputStream sectionByteArray = new FastByteArrayOutputStream(buffer);
FaweOutputStream sectionWriter = new FaweOutputStream(sectionByteArray);
try {
try (FaweOutputStream sectionWriter = new FaweOutputStream(sectionByteArray)) {
for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) {
if (!this.hasSection(layer) || (bitMask & (1 << layer)) == 0) continue;
if (!this.hasSection(layer) || (bitMask & (1 << layer)) == 0) {
continue;
}
char[] ids = this.load(layer);
@ -78,46 +79,30 @@ public interface IBlocks extends Trimable {
}
sectionWriter.writeShort(nonEmpty); // non empty
FaweCache.Palette palette = FaweCache.IMP.toPalette(0, ids);
// if (false) { // short palette
// sectionWriter.writeByte(14); // globalPaletteBitsPerBlock
// BitArray4096 bits = new BitArray4096(14); // globalPaletteBitsPerBlock
// bits.setAt(0, 0);
// for (int i = 0; i < 4096; i++) {
// int ordinal = ids[i];
// BlockState state = BlockState.getFromOrdinal(ordinal);
// if (!state.getMaterial().isAir()) {
// int mcId = registry.getInternalBlockStateId(state).getAsInt();
// bits.setAt(i, mcId);
// }
// }
// sectionWriter.write(bits.getData());
// } else {
FaweCache.Palette palette = FaweCache.IMP.toPalette(0, ids);
sectionWriter.writeByte(palette.bitsPerEntry); // bits per block
sectionWriter.writeVarInt(palette.paletteToBlockLength);
for (int i = 0; i < palette.paletteToBlockLength; i++) {
int ordinal = palette.paletteToBlock[i];
switch (ordinal) {
case BlockID.__RESERVED__:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
case BlockID.AIR:
sectionWriter.write(0);
break;
default:
BlockState state = BlockState.getFromOrdinal(ordinal);
int mcId = registry.getInternalBlockStateId(state).getAsInt();
sectionWriter.writeVarInt(mcId);
break;
}
sectionWriter.writeByte(palette.bitsPerEntry); // bits per block
sectionWriter.writeVarInt(palette.paletteToBlockLength);
for (int i = 0; i < palette.paletteToBlockLength; i++) {
int ordinal = palette.paletteToBlock[i];
switch (ordinal) {
case BlockID.__RESERVED__:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
case BlockID.AIR:
sectionWriter.write(0);
break;
default:
BlockState state = BlockState.getFromOrdinal(ordinal);
int mcId = registry.getInternalBlockStateId(state).getAsInt();
sectionWriter.writeVarInt(mcId);
break;
}
sectionWriter.writeVarInt(palette.blockStatesLength);
for (int i = 0; i < palette.blockStatesLength; i++) {
sectionWriter.writeLong(palette.blockStates[i]);
}
// }
}
sectionWriter.writeVarInt(palette.blockStatesLength);
for (int i = 0; i < palette.blockStatesLength; i++) {
sectionWriter.writeLong(palette.blockStates[i]);
}
}
if (full) {
for (int z = 0; z < 16; z++) {