This commit is contained in:
MidnightTale 2023-04-11 15:44:16 +07:00
commit b480c3640b

View file

@ -1,8 +1,8 @@
package xyz.hynse.bbsdfia; package xyz.hynse.bbsdfia;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -10,16 +10,10 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.Map;
public class Bbsdfia extends JavaPlugin implements Listener { public class Bbsdfia extends JavaPlugin implements Listener {
private final Map<Entity, Vector> teleportedFallingBlocks = new HashMap<>();
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
@ -40,32 +34,23 @@ public class Bbsdfia extends JavaPlugin implements Listener {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
Vector vel = entity.getVelocity(); Vector vel = entity.getVelocity();
Block movingTo = getBlockMovingTo(loc, vel); Block movingTo = getBlockMovingTo(loc, vel);
Location loc2 = new Location(Bukkit.getWorld("world_the_end"), 100, 50, 0);
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
Location spawnLoc = movingTo.getLocation(); /*
spawnLoc.setX(spawnLoc.getX()+0.5); World world = Bukkit.getServer().getWorld("world");
spawnLoc.setY(spawnLoc.getY()+0.5); Location spawnLoc = new Location(world, 100, 50, 0);
spawnLoc.setZ(spawnLoc.getZ()+0.5); */
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); FallingBlock dummy = loc2.getWorld().spawnFallingBlock(loc2, ((FallingBlock) entity).getBlockData());
Vector dummyVel = vel.clone();
dummyVel.setY(-dummyVel.getY());
dummyVel.multiply(new Vector(2, 2, 2)); // double the velocity
// Store the velocity of the falling block entity // add a constant downward velocity to simulate gravity
teleportedFallingBlocks.put(dummy, vel.clone()); dummyVel.add(new Vector(0, 0.3, 0));
// Set the velocity of the dummy entity to 0 to prevent it from moving dummy.setVelocity(dummyVel);
dummy.setVelocity(new Vector(0, 0, 0));
}
}
}
@EventHandler
public void onEntityTeleport(EntityTeleportEvent e) {
Entity entity = e.getEntity();
if (entity.getType() == EntityType.FALLING_BLOCK && e.getTo().getWorld().getEnvironment() == World.Environment.THE_END) {
// Check if the falling block entity has been teleported through the end portal
if (teleportedFallingBlocks.containsKey(entity)) {
Vector vel = teleportedFallingBlocks.remove(entity);
entity.setVelocity(vel);
} }
} }
} }