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:
Ursprung
c98538940d
Commit
2d151f4c33
47
src/main/java/org/bukkit/craftbukkit/CraftHeightMap.java
Normale Datei
47
src/main/java/org/bukkit/craftbukkit/CraftHeightMap.java
Normale Datei
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
22
src/test/java/org/bukkit/craftbukkit/HeightMapTest.java
Normale Datei
22
src/test/java/org/bukkit/craftbukkit/HeightMapTest.java
Normale Datei
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren