Improve physics check (needs to be reworked)

This commit is contained in:
mathiascode 2019-11-13 21:13:54 +02:00
parent 002007ece0
commit 8ad4bfe961

View file

@ -48,14 +48,12 @@ 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 < 300) { if (blockCount < 200) {
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.isLiquid() ||
coordBlock.getType() == Material.WATER || coordBlock.getType() == Material.OBSIDIAN) {
coordBlock.getType() == Material.OBSIDIAN) &&
block.getType() != coordBlock.getType()) {
blockCount++; blockCount++;
} }
@ -71,13 +69,12 @@ class BlockPhysics implements Listener {
@EventHandler @EventHandler
void onBlockPhysics(BlockPhysicsEvent event) { void onBlockPhysics(BlockPhysicsEvent event) {
final Material material = event.getSourceBlock().getType(); final Material material = event.getChangedType();
if (material == Material.FARMLAND) { if (material == Material.FARMLAND) {
event.setCancelled(true); event.setCancelled(true);
} else if (material == Material.LAVA || } else if (event.getBlock().isLiquid()) {
material == Material.WATER) { final Block block = event.getBlock();
final Block block = event.getSourceBlock();
final World world = block.getWorld(); final World world = block.getWorld();
final int radius = 5; final int radius = 5;
int blockCount = 0; int blockCount = 0;
@ -85,12 +82,11 @@ 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 < 300) { if (blockCount < 200) {
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.isLiquid() ||
coordBlock.getType() == Material.WATER ||
coordBlock.getType() == Material.OBSIDIAN) && coordBlock.getType() == Material.OBSIDIAN) &&
block.getType() != coordBlock.getType()) { block.getType() != coordBlock.getType()) {
blockCount++; blockCount++;
@ -107,7 +103,7 @@ class BlockPhysics implements Listener {
} else if (Main.nonSolidBlockList.contains(material) || } else if (Main.nonSolidBlockList.contains(material) ||
material == Material.AIR || material == Material.AIR ||
material == Material.CAVE_AIR) { material == Material.CAVE_AIR) {
final Block block = event.getSourceBlock(); 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;
@ -115,7 +111,7 @@ 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 < 42) { if (blockCount < 100) {
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);
@ -136,61 +132,7 @@ class BlockPhysics implements Listener {
} }
} }
} }
} /*else if (Main.nonSolidDoubleBlockList.contains(material)) { }
final Block block = event.getSourceBlock();
if (Main.nonSolidDoubleBlockList.contains(block.getRelative(BlockFace.DOWN).getType())) {
event.setCancelled(true);
} 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.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++) {
final World world = event.getBlock().getWorld();
final Block coordBlock = world.getBlockAt(new Location(world, block.getX(), y, block.getZ()));
if (Main.nonSolidDoubleBlockList.contains(coordBlock.getType()) ||
(block.getType() == Material.KELP_PLANT &&
coordBlock.getType() == Material.KELP)) {
coordBlock.setType(materialReplacement, false);
continue;
}
break;
}
event.setCancelled(true);
block.setType(materialReplacement, false);
}
} else if (Main.nonSolidSingularBlockList.contains(material)) {
final Block block = event.getSourceBlock();
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())) {
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;
}
event.setCancelled(true);
block.setType(materialReplacement, false);
}
}*/
} }
@EventHandler @EventHandler