Push WIP physics code

This commit is contained in:
mathiascode 2019-10-13 16:14:25 +03:00
parent 81014126d0
commit 4d4d01893a
5 changed files with 44 additions and 58 deletions

View file

@ -479,7 +479,6 @@ public class Main extends JavaPlugin {
Material.OXEYE_DAISY, Material.OXEYE_DAISY,
Material.BROWN_MUSHROOM, Material.BROWN_MUSHROOM,
Material.RED_MUSHROOM, Material.RED_MUSHROOM,
Material.FIRE,
Material.WHEAT, Material.WHEAT,
Material.RAIL, Material.RAIL,
Material.STONE_PRESSURE_PLATE, Material.STONE_PRESSURE_PLATE,
@ -541,6 +540,7 @@ public class Main extends JavaPlugin {
Collections.addAll( Collections.addAll(
nonSolidWallMountedBlockList, nonSolidWallMountedBlockList,
Material.FIRE,
Material.TORCH, Material.TORCH,
Material.WALL_TORCH, Material.WALL_TORCH,
Material.LADDER, Material.LADDER,
@ -603,7 +603,9 @@ public class Main extends JavaPlugin {
Material.HORN_CORAL_FAN, Material.HORN_CORAL_FAN,
Material.HORN_CORAL_WALL_FAN, Material.HORN_CORAL_WALL_FAN,
Material.TUBE_CORAL_FAN, Material.TUBE_CORAL_FAN,
Material.TUBE_CORAL_WALL_FAN Material.TUBE_CORAL_WALL_FAN,
Material.CHORUS_FLOWER,
Material.CHORUS_PLANT
); );
Collections.addAll( Collections.addAll(

View file

@ -52,26 +52,3 @@ class BlockCheck implements Listener {
} }
} }
} }
/*class TileEntityCheck extends BukkitRunnable {
private Main main;
public TileEntityCheck(Main main) {
this.main = main;
}
public void run() {
for (final World world : Bukkit.getServer().getWorlds()) {
for (final Chunk chunk : world.getLoadedChunks()) {
try {
chunk.getTileEntities();
} catch (Exception e) {
new BukkitRunnable() {
public void run() {
world.regenerateChunk(chunk.getX(), chunk.getZ());
}
}.runTask(main);
}
}
}
}
}*/

View file

@ -60,29 +60,28 @@ class BlockPhysics implements Listener {
} }
continue; continue;
} else {
event.setCancelled(true);
return;
} }
break;
} }
} }
} }
if (blockCount == 300) {
event.setCancelled(true);
}
} }
@EventHandler @EventHandler
void onBlockPhysics(BlockPhysicsEvent event) { void onBlockPhysics(BlockPhysicsEvent event) {
final Material material = event.getChangedType(); final Material material = event.getSourceBlock().getType();
if (material == Material.FARMLAND) { if (material == Material.FARMLAND) {
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.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;
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++) {
@ -98,17 +97,17 @@ class BlockPhysics implements Listener {
} }
continue; continue;
} else {
event.setCancelled(true);
return;
} }
break;
} }
} }
} }
} else if (Main.nonSolidBlockList.contains(material) ||
if (blockCount == 300) { material == Material.AIR ||
block.setType(Material.AIR, false); material == Material.CAVE_AIR) {
} final Block block = event.getSourceBlock();
} else if (Main.nonSolidWallMountedBlockList.contains(material)) {
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;
@ -120,29 +119,25 @@ class BlockPhysics implements Listener {
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 || if (Main.nonSolidBlockList.contains(coordBlock.getType())) {
Main.nonSolidWallMountedBlockList.contains(coordBlock.getType())) {
blockCount++; blockCount++;
} }
continue; continue;
} else {
for (BlockFace face : BlockFace.values()) {
if (Main.nonSolidBlockList.contains(block.getRelative(face).getType())) {
event.setCancelled(true);
return;
}
}
return;
} }
break;
} }
} }
} }
} /*else if (Main.nonSolidDoubleBlockList.contains(material)) {
if (blockCount == 42) { final Block block = event.getSourceBlock();
Material materialReplacement = Material.AIR;
if (Main.nonSolidWaterBlockList.contains(material)) {
materialReplacement = Material.WATER;
}
block.setType(materialReplacement, false);
}
} else if (Main.nonSolidDoubleBlockList.contains(material)) {
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);
@ -171,10 +166,11 @@ class BlockPhysics implements Listener {
break; break;
} }
event.setCancelled(true);
block.setType(materialReplacement, 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.getSourceBlock();
if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR || if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
(Main.nonSolidWaterBlockList.contains(material) && (Main.nonSolidWaterBlockList.contains(material) &&
@ -191,9 +187,10 @@ class BlockPhysics implements Listener {
materialReplacement = Material.WATER; materialReplacement = Material.WATER;
} }
event.setCancelled(true);
block.setType(materialReplacement, false); block.setType(materialReplacement, false);
} }
} }*/
} }
@EventHandler @EventHandler

View file

@ -69,7 +69,9 @@ class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onBlockDispense(BlockDispenseEvent event) { void onBlockDispense(BlockDispenseEvent event) {
System.out.println("lol");
try { try {
event.getBlock().getState();
event.getItem().getItemMeta(); event.getItem().getItemMeta();
} catch (Exception exception) { } catch (Exception exception) {
event.setCancelled(true); event.setCancelled(true);

View file

@ -13,6 +13,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -149,7 +150,14 @@ class PlayerConnection implements Listener {
for (final Chunk chunk : world.getLoadedChunks()) { for (final Chunk chunk : world.getLoadedChunks()) {
try { try {
if (chunk.getTileEntities(false).length == 0); int data = 0;
for (BlockState block : chunk.getTileEntities()) {
data = data + block.getBlockData().getAsString().length();
}
if (data > 1285579) {
world.regenerateChunk(chunk.getX(), chunk.getZ());
}
} catch (Exception exception) { } catch (Exception exception) {
world.regenerateChunk(chunk.getX(), chunk.getZ()); world.regenerateChunk(chunk.getX(), chunk.getZ());
} }