From 07c300164aa0318c0064d629ff71247c96731e7c Mon Sep 17 00:00:00 2001 From: ryanbennitt Date: Fri, 1 Jan 2016 14:03:17 +0000 Subject: [PATCH] SPIGOT-1390: Fixed issues with Array.fill upper bound in setRegion --- .../bukkit/craftbukkit/generator/CraftChunkData.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index 438bed8cf1..01264a7ed4 100644 --- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -97,7 +97,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { if (xMin >= xMax || yMin >= yMax || zMin >= zMax) { return; } - char typeChar = (char) (blockId << 4 | data); + char typeChar = (char) ((blockId << 4) | data); if (xMin == 0 && xMax == 0x10) { if (zMin == 0 && zMax == 0x10) { for (int y = yMin & 0xf0; y < yMax; y += 0x10) { @@ -110,7 +110,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { // First chunk section Arrays.fill(section, (yMin & 0xf) << 8, 0x1000, typeChar); } - } else if (y + 0x10 >= yMax) { + } else if (y + 0x10 > yMax) { // Last chunk section Arrays.fill(section, 0, (yMax & 0xf) << 8, typeChar); } else { @@ -123,7 +123,8 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { char[] section = getChunkSection(y, true); int offsetBase = (y & 0xf) << 8; int min = offsetBase | (zMin << 4); - int max = offsetBase | (zMax << 4); + // Need to add zMax as it can be 16, which overlaps the y coordinate bits + int max = offsetBase + (zMax << 4); Arrays.fill(section, min, max, typeChar); } } @@ -132,8 +133,9 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { char[] section = getChunkSection(y, true); int offsetBase = (y & 0xf) << 8; for (int z = zMin; z < zMax; z++) { - int offset = offsetBase | z << 4; - Arrays.fill(section, offset | xMin, offset | xMax, typeChar); + int offset = offsetBase | (z << 4); + // Need to add xMax as it can be 16, which overlaps the z coordinate bits + Arrays.fill(section, offset | xMin, offset + xMax, typeChar); } } }