ok
This commit is contained in:
parent
f98be2cfa9
commit
ae48f26ba8
1 changed files with 16 additions and 30 deletions
|
|
@ -82,40 +82,26 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
public void onFallingBlockSpawn(EntitySpawnEvent e) {
|
||||||
Entity entity = event.getEntity();
|
if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
if (!(entity instanceof FallingBlock)) {
|
Entity entity = e.getEntity();
|
||||||
return;
|
Location loc = entity.getLocation();
|
||||||
}
|
|
||||||
if (entity.getWorld().getEnvironment() != World.Environment.THE_END) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Location blockLoc = event.getBlock().getLocation();
|
|
||||||
if (movingBlocks.contains(blockLoc)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
debug("EntityChangeBlock event received for falling block at location " + entity.getLocation());
|
|
||||||
entity.remove();
|
|
||||||
movingBlocks.add(blockLoc);
|
|
||||||
Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0);
|
|
||||||
block.getBlock().setType(Material.AIR);
|
|
||||||
World world = entity.getWorld();
|
|
||||||
Location location = entity.getLocation();
|
|
||||||
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
|
|
||||||
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
|
|
||||||
|
|
||||||
int index = counter % 4;
|
debug("Falling block spawned at location " + loc);
|
||||||
Vector velocity = velocities[index];
|
|
||||||
counter++;
|
|
||||||
debug("Spawning new falling block of material " + material + " at location " + location + " with velocity " + velocity.toString());
|
|
||||||
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
|
||||||
newFallingBlock.setVelocity(velocity);
|
|
||||||
|
|
||||||
// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
|
// Set the initial velocity of the falling block
|
||||||
getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(blockLoc), 20L);
|
int index = counter % 4;
|
||||||
|
counter ++;
|
||||||
|
Vector velocity = velocities[index];
|
||||||
|
entity.setVelocity(velocity);
|
||||||
|
|
||||||
|
// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
|
||||||
|
getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Block getBlockMovingTo(Location loc, Vector vel) {
|
Block getBlockMovingTo(Location loc, Vector vel) {
|
||||||
double absMax = 0, max = 0;
|
double absMax = 0, max = 0;
|
||||||
char dir = ' ';
|
char dir = ' ';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue