Better underwater plant handling

This commit is contained in:
mathiascode 2019-10-04 16:42:11 +03:00
parent 9ec1c32b17
commit 38770f54c8
2 changed files with 104 additions and 30 deletions

View file

@ -22,6 +22,7 @@ public class Main extends JavaPlugin {
static HashSet<Material> nonSolidDoubleBlockList = new HashSet<>(); static HashSet<Material> nonSolidDoubleBlockList = new HashSet<>();
static HashSet<Material> nonSolidSingularBlockList = new HashSet<>(); static HashSet<Material> nonSolidSingularBlockList = new HashSet<>();
static HashSet<Material> nonSolidWallMountedBlockList = new HashSet<>(); static HashSet<Material> nonSolidWallMountedBlockList = new HashSet<>();
static HashSet<Material> nonSolidWaterBlockList = new HashSet<>();
public void onLoad() { public void onLoad() {
/* Fill lists */ /* Fill lists */
@ -605,6 +606,45 @@ public class Main extends JavaPlugin {
Material.TUBE_CORAL_WALL_FAN Material.TUBE_CORAL_WALL_FAN
); );
Collections.addAll(
nonSolidWaterBlockList,
Material.BRAIN_CORAL_FAN,
Material.BRAIN_CORAL_WALL_FAN,
Material.BUBBLE_CORAL_FAN,
Material.BUBBLE_CORAL_WALL_FAN,
Material.DEAD_BRAIN_CORAL_FAN,
Material.DEAD_BRAIN_CORAL_WALL_FAN,
Material.DEAD_BUBBLE_CORAL_FAN,
Material.DEAD_BUBBLE_CORAL_WALL_FAN,
Material.DEAD_FIRE_CORAL_FAN,
Material.DEAD_FIRE_CORAL_WALL_FAN,
Material.DEAD_HORN_CORAL_FAN,
Material.DEAD_HORN_CORAL_WALL_FAN,
Material.DEAD_TUBE_CORAL_FAN,
Material.DEAD_TUBE_CORAL_WALL_FAN,
Material.FIRE_CORAL_FAN,
Material.FIRE_CORAL_WALL_FAN,
Material.HORN_CORAL_FAN,
Material.HORN_CORAL_WALL_FAN,
Material.TUBE_CORAL_FAN,
Material.TUBE_CORAL_WALL_FAN,
Material.SEAGRASS,
Material.BRAIN_CORAL,
Material.BUBBLE_CORAL,
Material.DEAD_BRAIN_CORAL,
Material.DEAD_BUBBLE_CORAL,
Material.DEAD_FIRE_CORAL,
Material.DEAD_HORN_CORAL,
Material.DEAD_TUBE_CORAL,
Material.FIRE_CORAL,
Material.HORN_CORAL,
Material.TUBE_CORAL,
Material.SEA_PICKLE,
Material.KELP,
Material.KELP_PLANT,
Material.TALL_SEAGRASS
);
this.nonSolidBlockList.addAll(nonSolidDoubleBlockList); this.nonSolidBlockList.addAll(nonSolidDoubleBlockList);
this.nonSolidBlockList.addAll(nonSolidSingularBlockList); this.nonSolidBlockList.addAll(nonSolidSingularBlockList);
this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList); this.nonSolidBlockList.addAll(nonSolidWallMountedBlockList);

View file

@ -48,13 +48,14 @@ class BlockPhysics implements Listener {
for (int x = -radius; x <= radius; x++) { for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) { for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) { for (int z = -radius; z <= radius; z++) {
if (blockCount < 500) { if (blockCount < 300) {
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
final Block coordBlock = world.getBlockAt(blockLocation); final Block coordBlock = world.getBlockAt(blockLocation);
if (coordBlock.getType() == Material.LAVA || if ((coordBlock.getType() == Material.LAVA ||
coordBlock.getType() == Material.WATER || coordBlock.getType() == Material.WATER ||
coordBlock.getType() == Material.OBSIDIAN) { coordBlock.getType() == Material.OBSIDIAN) &&
block.getType() != coordBlock.getType()) {
blockCount++; blockCount++;
} }
@ -65,7 +66,7 @@ class BlockPhysics implements Listener {
} }
} }
if (blockCount == 500) { if (blockCount == 300) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -78,7 +79,6 @@ class BlockPhysics implements Listener {
event.setCancelled(true); event.setCancelled(true);
} else if (material == Material.LAVA || } else if (material == Material.LAVA ||
material == Material.WATER) { material == Material.WATER) {
final Block block = event.getBlock(); final Block block = event.getBlock();
final World world = block.getWorld(); final World world = block.getWorld();
final int radius = 5; final int radius = 5;
@ -86,13 +86,14 @@ class BlockPhysics implements Listener {
for (int x = -radius; x <= radius; x++) { for (int x = -radius; x <= radius; x++) {
for (int y = -radius; y <= radius; y++) { for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) { for (int z = -radius; z <= radius; z++) {
if (blockCount < 500) { if (blockCount < 300) {
final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z); final Location blockLocation = new Location(world, block.getX() + x, block.getY() + y, block.getZ() + z);
final Block coordBlock = world.getBlockAt(blockLocation); final Block coordBlock = world.getBlockAt(blockLocation);
if (coordBlock.getType() == Material.LAVA || if ((coordBlock.getType() == Material.LAVA ||
coordBlock.getType() == Material.WATER || coordBlock.getType() == Material.WATER ||
coordBlock.getType() == Material.OBSIDIAN) { coordBlock.getType() == Material.OBSIDIAN) &&
block.getType() != coordBlock.getType()) {
blockCount++; blockCount++;
} }
@ -102,6 +103,10 @@ class BlockPhysics implements Listener {
} }
} }
} }
if (blockCount == 300) {
block.setType(Material.AIR, false);
}
} else if (Main.nonSolidWallMountedBlockList.contains(material)) { } else if (Main.nonSolidWallMountedBlockList.contains(material)) {
final Block block = event.getBlock(); final Block block = event.getBlock();
final World world = block.getWorld(); final World world = block.getWorld();
@ -128,7 +133,13 @@ class BlockPhysics implements Listener {
} }
if (blockCount == 42) { if (blockCount == 42) {
event.setCancelled(true); Material materialReplacement = Material.AIR;
if (Main.nonSolidWaterBlockList.contains(material)) {
materialReplacement = Material.WATER;
}
block.setType(materialReplacement, false);
} }
} else if (Main.nonSolidDoubleBlockList.contains(material)) { } else if (Main.nonSolidDoubleBlockList.contains(material)) {
final Block block = event.getBlock(); final Block block = event.getBlock();
@ -136,28 +147,51 @@ class BlockPhysics implements Listener {
if (Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { if (Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) {
event.setCancelled(true); event.setCancelled(true);
} else if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || } else if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
(Main.nonSolidWaterBlockList.contains(material) &&
block.getRelative(BlockFace.DOWN).getType() == Material.WATER) ||
(Main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType()) && (Main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType()) &&
!Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType()))) { !Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType()))) {
Material materialReplacement = Material.AIR;
if (Main.nonSolidWaterBlockList.contains(material)) {
materialReplacement = Material.WATER;
}
for (int y = block.getRelative(BlockFace.UP).getY(); y <= 256; y++) { for (int y = block.getRelative(BlockFace.UP).getY(); y <= 256; y++) {
final World world = event.getBlock().getWorld(); final World world = event.getBlock().getWorld();
final Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ())); final Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ()));
if (Main.nonSolidDoubleBlockList.contains(coordBlock.getType())) { if (Main.nonSolidDoubleBlockList.contains(coordBlock.getType()) ||
coordBlock.setType(Material.AIR, false); (block.getType() == Material.KELP_PLANT &&
coordBlock.getType() == Material.KELP)) {
coordBlock.setType(materialReplacement, false);
continue; continue;
} }
break; break;
} }
block.setType(Material.AIR, false); block.setType(materialReplacement, false);
} }
} else if (Main.nonSolidSingularBlockList.contains(material)) { } else if (Main.nonSolidSingularBlockList.contains(material)) {
final Block block = event.getBlock(); final Block block = event.getBlock();
if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
(Main.nonSolidWaterBlockList.contains(material) &&
block.getRelative(BlockFace.DOWN).getType() == Material.WATER) ||
Main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) { Main.nonSolidBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) {
block.setType(Material.AIR, false); if (block.getType() == Material.KELP &&
block.getRelative(BlockFace.DOWN).getType() == Material.KELP_PLANT) {
return;
}
Material materialReplacement = Material.AIR;
if (Main.nonSolidWaterBlockList.contains(material)) {
materialReplacement = Material.WATER;
}
block.setType(materialReplacement, false);
} }
} }
} }