From 3842cba3fdeedc82bd9127e77c70a2bf015f39af Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 11 May 2023 06:48:41 +1000 Subject: [PATCH] #1186: Move getHighestBlockYAt methods from World to RegionAccessor By: Jishuna --- .../craftbukkit/CraftRegionAccessor.java | 20 +++++++++++++++ .../org/bukkit/craftbukkit/CraftWorld.java | 15 ----------- .../generator/CraftLimitedRegion.java | 25 +++++++++++++++++++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index cdad8217c7..c42d4b2e5a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -305,6 +305,26 @@ public abstract class CraftRegionAccessor implements RegionAccessor { setBlockData(x, y, z, material.createBlockData()); } + @Override + public int getHighestBlockYAt(int x, int z) { + return getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING); + } + + @Override + public int getHighestBlockYAt(Location location) { + return getHighestBlockYAt(location.getBlockX(), location.getBlockZ()); + } + + @Override + public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) { + return getHandle().getHeight(CraftHeightMap.toNMS(heightMap), x, z); + } + + @Override + public int getHighestBlockYAt(Location location, org.bukkit.HeightMap heightMap) { + return getHighestBlockYAt(location.getBlockX(), location.getBlockZ(), heightMap); + } + @Override public boolean generateTree(Location location, Random random, TreeType treeType) { BlockPosition pos = CraftLocation.toBlockPosition(location); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 4b593de347..aba7b9e850 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -172,11 +172,6 @@ public class CraftWorld extends CraftRegionAccessor implements World { return CraftBlock.at(world, new BlockPosition(x, y, z)); } - @Override - public int getHighestBlockYAt(int x, int z) { - return getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING); - } - @Override public Location getSpawnLocation() { BlockPosition spawn = world.getSharedSpawnPos(); @@ -708,11 +703,6 @@ public class CraftWorld extends CraftRegionAccessor implements World { return getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } - @Override - public int getHighestBlockYAt(Location location) { - return getHighestBlockYAt(location.getBlockX(), location.getBlockZ()); - } - @Override public Chunk getChunkAt(Location location) { return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4); @@ -749,11 +739,6 @@ public class CraftWorld extends CraftRegionAccessor implements World { return world.getChunk(x >> 4, z >> 4).getHeight(CraftHeightMap.toNMS(heightMap), x, z); } - @Override - public int getHighestBlockYAt(Location location, org.bukkit.HeightMap heightMap) { - return getHighestBlockYAt(location.getBlockX(), location.getBlockZ(), heightMap); - } - @Override public Block getHighestBlockAt(int x, int z, org.bukkit.HeightMap heightMap) { return getBlockAt(x, getHighestBlockYAt(x, z, heightMap), z); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java index e10d76b9d5..c9663aafed 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.ProtoChunk; +import org.bukkit.HeightMap; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.TreeType; @@ -198,6 +199,30 @@ public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRe super.setBlockData(x, y, z, blockData); } + @Override + public int getHighestBlockYAt(int x, int z) { + Preconditions.checkArgument(isInRegion(x, region.getCenter().getBlockY(), z), "Coordinates %s, %s are not in the region", x, z); + return super.getHighestBlockYAt(x, z); + } + + @Override + public int getHighestBlockYAt(Location location) { + Preconditions.checkArgument(isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + return super.getHighestBlockYAt(location); + } + + @Override + public int getHighestBlockYAt(int x, int z, HeightMap heightMap) { + Preconditions.checkArgument(isInRegion(x, region.getCenter().getBlockY(), z), "Coordinates %s, %s are not in the region", x, z); + return super.getHighestBlockYAt(x, z, heightMap); + } + + @Override + public int getHighestBlockYAt(Location location, HeightMap heightMap) { + Preconditions.checkArgument(isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + return super.getHighestBlockYAt(location, heightMap); + } + @Override public boolean generateTree(Location location, Random random, TreeType treeType) { Preconditions.checkArgument(isInRegion(location), "Coordinates %s, %s, %s are not in the region", location.getBlockX(), location.getBlockY(), location.getBlockZ());