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