From 8eab3d098c3ef85ac67f2e08084e3b8d658e684c Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 4 Mar 2020 00:52:42 -0500 Subject: [PATCH] Close at least one of the streams in IBlocks.java --- .../java/com/boydti/fawe/beta/IBlocks.java | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index 79cfd9a51..a74c8393c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -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++) {