diff --git a/src/main/java/org/bukkit/craftbukkit/CraftHeightMap.java b/src/main/java/org/bukkit/craftbukkit/CraftHeightMap.java new file mode 100644 index 0000000000..1c4a911577 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftHeightMap.java @@ -0,0 +1,47 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.HeightMap; + +final class CraftHeightMap { + + private CraftHeightMap() { + } + + public static net.minecraft.server.HeightMap.Type toNMS(HeightMap bukkitHeightMap) { + switch (bukkitHeightMap) { + case MOTION_BLOCKING_NO_LEAVES: + return net.minecraft.server.HeightMap.Type.MOTION_BLOCKING_NO_LEAVES; + case OCEAN_FLOOR: + return net.minecraft.server.HeightMap.Type.OCEAN_FLOOR; + case OCEAN_FLOOR_WG: + return net.minecraft.server.HeightMap.Type.OCEAN_FLOOR_WG; + case WORLD_SURFACE: + return net.minecraft.server.HeightMap.Type.WORLD_SURFACE; + case WORLD_SURFACE_WG: + return net.minecraft.server.HeightMap.Type.WORLD_SURFACE_WG; + case MOTION_BLOCKING: + return net.minecraft.server.HeightMap.Type.MOTION_BLOCKING; + default: + throw new EnumConstantNotPresentException(net.minecraft.server.HeightMap.Type.class, bukkitHeightMap.name()); + } + } + + public static HeightMap fromNMS(net.minecraft.server.HeightMap.Type nmsHeightMapType) { + switch (nmsHeightMapType) { + case WORLD_SURFACE_WG: + return HeightMap.WORLD_SURFACE_WG; + case WORLD_SURFACE: + return HeightMap.WORLD_SURFACE; + case OCEAN_FLOOR_WG: + return HeightMap.OCEAN_FLOOR_WG; + case OCEAN_FLOOR: + return HeightMap.OCEAN_FLOOR; + case MOTION_BLOCKING_NO_LEAVES: + return HeightMap.MOTION_BLOCKING_NO_LEAVES; + case MOTION_BLOCKING: + return HeightMap.MOTION_BLOCKING; + default: + throw new EnumConstantNotPresentException(HeightMap.class, nmsHeightMapType.name()); + } + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 1458b0a637..32bcbd7b42 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -71,7 +71,6 @@ import net.minecraft.server.ExceptionWorldConflict; import net.minecraft.server.Explosion; import net.minecraft.server.GameRules; import net.minecraft.server.GroupDataEntity; -import net.minecraft.server.HeightMap; import net.minecraft.server.IBlockData; import net.minecraft.server.IChunkAccess; import net.minecraft.server.MinecraftKey; @@ -291,8 +290,7 @@ public class CraftWorld implements World { @Override public int getHighestBlockYAt(int x, int z) { - // Transient load for this tick - return world.getChunkAt(x >> 4, z >> 4).a(HeightMap.Type.MOTION_BLOCKING, x, z); + return getHighestBlockYAt(x, z, org.bukkit.HeightMap.MOTION_BLOCKING); } @Override @@ -891,6 +889,27 @@ public class CraftWorld implements World { return getHighestBlockAt(location.getBlockX(), location.getBlockZ()); } + @Override + public int getHighestBlockYAt(int x, int z, org.bukkit.HeightMap heightMap) { + // Transient load for this tick + return world.getChunkAt(x >> 4, z >> 4).a(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); + } + + @Override + public Block getHighestBlockAt(Location location, org.bukkit.HeightMap heightMap) { + return getHighestBlockAt(location.getBlockX(), location.getBlockZ(), heightMap); + } + @Override public Biome getBiome(int x, int z) { return getBiome(x, 0, z); diff --git a/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java b/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java new file mode 100644 index 0000000000..6db64c5292 --- /dev/null +++ b/src/test/java/org/bukkit/craftbukkit/HeightMapTest.java @@ -0,0 +1,22 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.HeightMap; +import org.junit.Assert; +import org.junit.Test; + +public class HeightMapTest { + + @Test + public void heightMapConversionFromNMSToBukkitShouldNotThrowExceptio() { + for (net.minecraft.server.HeightMap.Type nmsHeightMapType : net.minecraft.server.HeightMap.Type.values()) { + Assert.assertNotNull("fromNMS", CraftHeightMap.fromNMS(nmsHeightMapType)); + } + } + + @Test + public void heightMapConversionFromBukkitToNMSShouldNotThrowExceptio() { + for (HeightMap bukkitHeightMap : HeightMap.values()) { + Assert.assertNotNull("toNMS", CraftHeightMap.toNMS(bukkitHeightMap)); + } + } +}