From 6cb88505a92ad504505f377c74b86bc973475f43 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 9 Feb 2022 13:11:58 +0000 Subject: [PATCH] Create utility method for layer index in GenChunk --- .../java/com/plotsquared/bukkit/queue/GenChunk.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java index 1fab185c3..ac40d26ce 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/GenChunk.java @@ -138,7 +138,7 @@ public class GenChunk extends ScopedQueueCoordinator { public void setCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull BlockState block) { if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) { for (int y = pos1.getY(); y <= pos2.getY(); y++) { - int layer = (y - getMin().getY()) >> 4; + int layer = getLayerIndex(y); BlockState[] data = result[layer]; if (data == null) { result[layer] = data = new BlockState[4096]; @@ -205,7 +205,7 @@ public class GenChunk extends ScopedQueueCoordinator { } private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) { - int i = (y - getMin().getY()) >> 4; + int i = getLayerIndex(y); BlockState[] v = this.result[i]; if (v == null) { this.result[i] = v = new BlockState[4096]; @@ -227,7 +227,7 @@ public class GenChunk extends ScopedQueueCoordinator { @Override public @Nullable BlockState getBlock(int x, int y, int z) { - int i = (y - getMin().getY()) >> 4; + int i = getLayerIndex(y); if (result == null) { return BukkitBlockUtil.get(chunkData.getType(x, y, z)); } @@ -277,4 +277,8 @@ public class GenChunk extends ScopedQueueCoordinator { return toReturn; } + private int getLayerIndex(int y) { + return (y - getMin().getY()) >> 4; + } + }