specifying
This commit is contained in:
parent
315744c457
commit
9b97cc361f
1 changed files with 12 additions and 29 deletions
|
|
@ -2,10 +2,8 @@ package xyz.hynse.bbsdfia;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
@ -39,35 +37,20 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
// This method is called when a falling block entity changes its block
|
// This method is called when a falling block entity changes its block
|
||||||
// Register the method as an event handler for the EntityChangeBlockEvent
|
// Register the method as an event handler for the EntityChangeBlockEvent
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFallingBlockToBlock(EntityChangeBlockEvent e) {
|
public void onFallingBlockToBlock(EntityChangeBlockEvent event) {
|
||||||
// Check if the entity is a falling block
|
// Get the block that was changed
|
||||||
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
|
Block block = event.getBlock();
|
||||||
// Get the entity and its location and velocity
|
|
||||||
Entity entity = e.getEntity();
|
|
||||||
Location loc = entity.getLocation();
|
|
||||||
Vector vel = entity.getVelocity();
|
|
||||||
// Spawn loocation for new falling block
|
|
||||||
Location spawnlocation = new Location(Bukkit.getWorld("world_the_end"), 100, 50, 0);
|
|
||||||
// Get a reference to the world_the_end world
|
|
||||||
World endWorld = Bukkit.getWorld("world_the_end");
|
|
||||||
// Get the block that the entity is moving towards
|
|
||||||
Block movingTo = getBlockMovingTo(loc, vel);
|
|
||||||
// If the block it's moving towards is an end portal block
|
|
||||||
if (movingTo != null && movingTo.getType() == Material.END_PORTAL) {
|
|
||||||
|
|
||||||
// Spawn a new falling block entity in the end with the same material and block type as the old one
|
// Check if it was changed from a falling block
|
||||||
FallingBlock dummy = endWorld.spawnFallingBlock(spawnlocation, movingTo.getBlockData());
|
if (event.getEntityType() == EntityType.FALLING_BLOCK) {
|
||||||
|
// Spawn a new falling block at the same location as the old one
|
||||||
|
World world = Bukkit.getWorld("world_the_end"); // specify the world to spawn in
|
||||||
|
FallingBlock newBlock = world.spawnFallingBlock(block.getLocation(), ((FallingBlock) event.getEntity()).getBlockData());
|
||||||
|
|
||||||
// Copy the velocity of the original entity and invert the y component
|
// Set the same velocity as the old block
|
||||||
Vector dummyVel = vel.clone();
|
newBlock.setVelocity(((FallingBlock) event.getEntity()).getVelocity());
|
||||||
dummyVel.setY(-dummyVel.getY());
|
// Set the same custom name as the old block
|
||||||
// Double the velocity of the new entity
|
newBlock.setCustomName(((FallingBlock) event.getEntity()).getCustomName());
|
||||||
dummyVel.multiply(new Vector(2, 2, 2));
|
|
||||||
// Add a constant upward velocity to simulate gravity
|
|
||||||
dummyVel.add(new Vector(0, 0.3, 0));
|
|
||||||
// Set the velocity of the new entity to the modified velocity
|
|
||||||
dummy.setVelocity(dummyVel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue