mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-30 11:17:14 -05:00
Better underwater plant handling
This commit is contained in:
parent
9ec1c32b17
commit
38770f54c8
2 changed files with 104 additions and 30 deletions
|
@ -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);
|
||||||
|
|
|
@ -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,30 +79,34 @@ 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;
|
int blockCount = 0;
|
||||||
int blockCount = 0;
|
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 < 300) {
|
||||||
if (blockCount < 500) {
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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,36 +133,65 @@ 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();
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue