This commit is contained in:
MidnightTale 2023-04-24 22:44:42 +07:00
commit faa0cf94c8

View file

@ -34,9 +34,6 @@ public class FoliaFlow extends JavaPlugin implements Listener {
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
Location centerLocation = new Location(Bukkit.getWorld("world_the_end"), 100, 48.5, 0);
double radius = 1.0;
checkFallingBlock(centerLocation, radius);
// Get the region scheduler for the server // Get the region scheduler for the server
try { try {
@ -73,35 +70,55 @@ public class FoliaFlow extends JavaPlugin implements Listener {
super.onDisable(); super.onDisable();
} }
public void checkFallingBlock(Location centerLocation, double radius) { // @EventHandler
World world = centerLocation.getWorld(); // public void onFallingBlockLand(EntityChangeBlockEvent event) {
double x = centerLocation.getX(); // Entity entity = event.getEntity();
double y = centerLocation.getY(); // if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
double z = centerLocation.getZ(); // getLogger().info("found falling block" + entity);
// Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0);
// Location loc = entity.getLocation();
// if (loc.distance(centerLoc) <= 1) {
// if (!velocitiesMap.containsKey(entity)) {
// getLogger().info("add velocity falling block" + entity);
// int index = counter % 4;
// getLogger().info("[1]" + entity);
// counter++;
// getLogger().info("[2]" + entity);
// Vector velocity = velocities[index];
// getLogger().info("[3]" + entity);
// entity.setVelocity(velocity);
// getLogger().info("[4]" + entity);
// velocitiesMap.put(entity, velocity); // Store the velocity in the map
// getLogger().info("[5]" + entity);
// movingBlocks.add(entity.getLocation()); // Add the location to the set
// getLogger().info("[6]" + entity);
// }
// }
// }
// }
for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) { @EventHandler
if (entity instanceof FallingBlock && entity.getLocation().getBlockY() == y && entity.getLocation().getBlockX() == x && entity.getLocation().getBlockZ() == z) { public void onFallingBlockLand(EntityChangeBlockEvent event) {
if (!velocitiesMap.containsKey(entity)) { // Check if the entity is a falling block and has landed in the End dimension
getLogger().info("add velocity falling block" + entity); Entity entity = event.getEntity();
int index = counter % 4; if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
getLogger().info("[1]" + entity); // Spawn a new falling block entity with velocity to the north and upward
counter++; World world = entity.getWorld();
getLogger().info("[2]" + entity); Location location = entity.getLocation();
Vector velocity = velocities[index]; Vector velocity = new Vector(0, 1.2, -6);
getLogger().info("[3]" + entity); Material material = ((FallingBlock) entity).getBlockData().getMaterial();
entity.setVelocity(velocity); byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
getLogger().info("[4]" + entity); FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
velocitiesMap.put(entity, velocity); // Store the velocity in the map newFallingBlock.setVelocity(velocity);
getLogger().info("[5]" + entity);
movingBlocks.add(entity.getLocation()); // Add the location to the set // Remove the original falling block entity
getLogger().info("[6]" + entity); entity.remove();
}
}
} }
} }
@EventHandler @EventHandler
public void onFallingBlockToBlock(EntityChangeBlockEvent e){ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
if(e.getEntityType() == EntityType.FALLING_BLOCK){ if(e.getEntityType() == EntityType.FALLING_BLOCK){