fix(chunkloader): support trapdoor ceilings and creeper-specific spawning on simulated platforms
This commit is contained in:
@@ -465,7 +465,7 @@ final class ChunkLoaders {
|
|||||||
int baseZ = loader.chunkZ() << 4;
|
int baseZ = loader.chunkZ() << 4;
|
||||||
ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int rx = baseX + rnd.nextInt(16);
|
int rx = baseX + rnd.nextInt(16);
|
||||||
int rz = baseZ + rnd.nextInt(16);
|
int rz = baseZ + rnd.nextInt(16);
|
||||||
int topY = Math.max(w.getMinHeight() + 2, Math.min(w.getMaxHeight() - 2, loader.y() + rnd.nextInt(-24, 25)));
|
int topY = Math.max(w.getMinHeight() + 2, Math.min(w.getMaxHeight() - 2, loader.y() + rnd.nextInt(-24, 25)));
|
||||||
@@ -474,15 +474,30 @@ final class ChunkLoaders {
|
|||||||
Block space = w.getBlockAt(rx, topY, rz);
|
Block space = w.getBlockAt(rx, topY, rz);
|
||||||
Block spaceAbove = w.getBlockAt(rx, topY + 1, rz);
|
Block spaceAbove = w.getBlockAt(rx, topY + 1, rz);
|
||||||
|
|
||||||
if (!ground.getType().isSolid() || !space.getType().isAir() || !spaceAbove.getType().isAir()) {
|
if (!ground.getType().isSolid() || ground.isLiquid() || ground.getType() == Material.LAVA || ground.getType() == Material.WATER) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ground.isLiquid() || ground.getType() == Material.LAVA || ground.getType() == Material.WATER) {
|
if (!space.getType().isAir()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isAirAbove = spaceAbove.getType().isAir();
|
||||||
|
boolean isTrapdoorAbove = isTrapdoor(spaceAbove.getType());
|
||||||
|
if (!isAirAbove && !isTrapdoorAbove) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int light = space.getLightLevel();
|
int light = space.getLightLevel();
|
||||||
EntityType toSpawn = pickEntityType(w, space, light);
|
EntityType toSpawn;
|
||||||
|
if (isTrapdoorAbove) {
|
||||||
|
if (light > 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
toSpawn = EntityType.CREEPER;
|
||||||
|
} else {
|
||||||
|
toSpawn = pickEntityType(w, space, light);
|
||||||
|
}
|
||||||
|
|
||||||
if (toSpawn == null) {
|
if (toSpawn == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -497,6 +512,11 @@ final class ChunkLoaders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean isTrapdoor(Material mat) {
|
||||||
|
if (mat == null) return false;
|
||||||
|
return mat.name().endsWith("_TRAPDOOR");
|
||||||
|
}
|
||||||
|
|
||||||
static EntityType pickEntityType(World w, Block space, int light) {
|
static EntityType pickEntityType(World w, Block space, int light) {
|
||||||
boolean isSlime = false;
|
boolean isSlime = false;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -212,6 +212,16 @@ class ChunkLoaderTest {
|
|||||||
assertTrue(loader.timeLeft().contains("h"));
|
assertTrue(loader.timeLeft().contains("h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void recognizesTrapdoorsCorrectly() {
|
||||||
|
assertTrue(ChunkLoaders.isTrapdoor(org.bukkit.Material.OAK_TRAPDOOR));
|
||||||
|
assertTrue(ChunkLoaders.isTrapdoor(org.bukkit.Material.IRON_TRAPDOOR));
|
||||||
|
assertTrue(ChunkLoaders.isTrapdoor(org.bukkit.Material.SPRUCE_TRAPDOOR));
|
||||||
|
assertFalse(ChunkLoaders.isTrapdoor(org.bukkit.Material.AIR));
|
||||||
|
assertFalse(ChunkLoaders.isTrapdoor(org.bukkit.Material.STONE));
|
||||||
|
assertFalse(ChunkLoaders.isTrapdoor(null));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void simulationSafelyNoopsWithNullPlugin() {
|
void simulationSafelyNoopsWithNullPlugin() {
|
||||||
loaders.startSimulation();
|
loaders.startSimulation();
|
||||||
|
|||||||
Reference in New Issue
Block a user