From a346e3964a5d9fd9e2d778e2e0592f914b22d704 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 31 Jan 2019 10:56:34 +0200 Subject: [PATCH] Reserve correct space for 2 high mobs. Used for shulkers. --- .../populators/EntitiesPopulator.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/caveblock/generators/populators/EntitiesPopulator.java b/src/main/java/world/bentobox/caveblock/generators/populators/EntitiesPopulator.java index b0ffc7b..e8da544 100644 --- a/src/main/java/world/bentobox/caveblock/generators/populators/EntitiesPopulator.java +++ b/src/main/java/world/bentobox/caveblock/generators/populators/EntitiesPopulator.java @@ -134,7 +134,17 @@ public class EntitiesPopulator extends BlockPopulator } - + /** + * This method is not completed. It must reserve space for entities to spawn, but + * current implementation just allows to spawn 2 high mobs that can be in single + * place. + * @param world - World were mob must be spawned. + * @param block - Block that was choosed by random. + * @param entity - Entity that must be spawned. + * @param x - ChunkX coordinate. + * @param z - ChunkY coordinate. + * @param originalMaterial - replacement manterial. + */ private void tryToPlaceEntity(World world, Block block, EntityType entity, int x, int z, Material originalMaterial) { if (this.isValidBlock(world, block, x, z) && block.getType().equals(originalMaterial)) @@ -210,6 +220,28 @@ public class EntitiesPopulator extends BlockPopulator height = 1; break; } + + Block otherBlock = world.getBlockAt(block.getX(), block.getY() + 1, block.getZ()); + + if (!otherBlock.getType().equals(originalMaterial)) + { + otherBlock = world.getBlockAt(block.getX(), block.getY() - 1, block.getZ()); + } + + if (otherBlock.getType().equals(originalMaterial)) + { + block.setType(Material.CAVE_AIR); + otherBlock.setType(Material.CAVE_AIR); + + if (otherBlock.getY() < block.getY()) + { + world.spawnEntity(otherBlock.getLocation(), entity); + } + else + { + world.spawnEntity(block.getLocation(), entity); + } + } } else {