3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

#624: Add an API for passing the heightmap to getHighestBlockAt* method

Dieser Commit ist enthalten in:
ysl3000 2020-02-09 10:31:07 +11:00 committet von md_5
Ursprung c98538940d
Commit 2d151f4c33
3 geänderte Dateien mit 91 neuen und 3 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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