From 17a97f2f190b4244a72bf6ea9c23818f2c602dd5 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 20 Sep 2021 14:15:08 +0100 Subject: [PATCH] Fix lack of handling of custom world heights in CharFilterBlock --- .../extent/filter/block/CharFilterBlock.java | 60 ++++--------------- .../implementation/blocks/CharBlocks.java | 19 +++--- 2 files changed, 21 insertions(+), 58 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java index ffe30d7ec..2db4ad91a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/filter/block/CharFilterBlock.java @@ -31,6 +31,8 @@ public class CharFilterBlock extends ChunkFilterBlock { private static final SetDelegate FULL = (block, value) -> block.setArr[block.index] = value; private static final SetDelegate NULL = (block, value) -> block.initSet().set(block, value); + private int maxLayer; + private int minLayer; private CharGetBlocks get; private IChunkSet set; private char[] getArr; @@ -65,6 +67,8 @@ public class CharFilterBlock extends ChunkFilterBlock { @Override public final ChunkFilterBlock initLayer(IBlocks iget, IChunkSet iset, int layer) { this.get = (CharGetBlocks) iget; + minLayer = this.get.getMinSectionPosition(); + maxLayer = this.get.getMaxSectionPosition(); this.layer = layer; if (!iget.hasSection(layer)) { getArr = FaweCache.IMP.EMPTY_CHAR_4096; @@ -327,7 +331,7 @@ public class CharFilterBlock extends ChunkFilterBlock { if (y > 0) { return states[getArr[index - 256]]; } - if (layer > 0) { + if (layer > minLayer) { final int newLayer = layer - 1; final CharGetBlocks chunk = this.get; return states[chunk.sections[newLayer].get(chunk, newLayer, index + 3840)]; @@ -340,7 +344,7 @@ public class CharFilterBlock extends ChunkFilterBlock { if (y < 16) { return states[getArr[index + 256]]; } - if (layer < 16) { + if (layer < maxLayer) { final int newLayer = layer + 1; final CharGetBlocks chunk = this.get; return states[chunk.sections[newLayer].get(chunk, newLayer, index - 3840)]; @@ -352,52 +356,12 @@ public class CharFilterBlock extends ChunkFilterBlock { public final BlockState getBlockRelativeY(int y) { final int newY = this.y + y; final int layerAdd = newY >> 4; - switch (layerAdd) { - case 0: - return states[getArr[this.index + (y << 8)]]; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: { - final int newLayer = layer + layerAdd; - if (newLayer < 16) { - final int index = this.index + ((y & 15) << 8); - return states[get.sections[newLayer].get(get, newLayer, index)]; - } - break; - } - case -1: - case -2: - case -3: - case -4: - case -5: - case -6: - case -7: - case -8: - case -9: - case -10: - case -11: - case -12: - case -13: - case -14: - case -15: - final int newLayer = layer + layerAdd; - if (newLayer >= 0) { - final int index = this.index + ((y & 15) << 8); - return states[get.sections[newLayer].get(get, newLayer, index)]; - } - break; + if (layerAdd == 0) { + return states[getArr[this.index + (y << 8)]]; + } else if ((layerAdd > 0 && layerAdd < (maxLayer - layer)) || (layerAdd < 0 && layerAdd < (minLayer - layer))) { + final int newLayer = layer + layerAdd; + final int index = this.index + ((y & 15) << 8); + return states[get.sections[newLayer].get(get, newLayer, index)]; } return BlockTypes.__RESERVED__.getDefaultState(); } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharBlocks.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharBlocks.java index 919565138..882cbe682 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharBlocks.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/CharBlocks.java @@ -211,34 +211,33 @@ public abstract class CharBlocks implements IBlocks { */ public final char get(int layer, int index) { - layer -= minSectionPosition; - return sections[layer].get(this, layer, index); + return sections[layer - minSectionPosition].get(this, layer, index); } - public final void set(int layer, int index, char value) throws - ArrayIndexOutOfBoundsException { - layer -= minSectionPosition; - sections[layer].set(this, layer, index, value); + public final void set(int layer, int index, char value) throws ArrayIndexOutOfBoundsException { + sections[layer - minSectionPosition].set(this, layer, index, value); } public abstract static class Section { - public abstract char[] get(CharBlocks blocks, int layer); + abstract char[] get(CharBlocks blocks, int layer); - public abstract char[] get(CharBlocks blocks, int layer, boolean aggressive); + abstract char[] get(CharBlocks blocks, int layer, boolean aggressive); public abstract boolean isFull(); public final char get(CharBlocks blocks, int layer, int index) { - char[] section = get(blocks, layer); + int normalized = layer - blocks.minSectionPosition; + char[] section = get(blocks, normalized); if (section == null) { blocks.reset(layer); - section = blocks.empty.get(blocks, layer, false); + section = blocks.empty.get(blocks, normalized, false); } return section[index]; } public final synchronized void set(CharBlocks blocks, int layer, int index, char value) { + layer -= blocks.minSectionPosition; get(blocks, layer)[index] = value; }