#1186: Move getHighestBlockYAt methods from World to RegionAccessor

By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
CraftBukkit/Spigot 2023-05-11 06:48:41 +10:00
parent 7b7d756683
commit 3842cba3fd
3 changed files with 45 additions and 15 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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());