onEntitySpawn
This commit is contained in:
parent
8efc7bdc42
commit
279aaa0b6d
1 changed files with 7 additions and 16 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
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.World;
|
||||||
|
|
@ -8,17 +7,16 @@ 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;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
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.ItemSpawnEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
|
||||||
public class Bbsdfia extends JavaPlugin implements Listener {
|
public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private Material detectedMaterial = null;
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
|
@ -57,19 +55,14 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFallingBlockLand(EntityChangeBlockEvent event) {
|
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||||
// Check if the entity is a falling block and has landed in the End dimension
|
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
// Spawn a new falling block entity with velocity to the north and upward
|
// Spawn a new falling block entity with velocity to the north and upward
|
||||||
World world = entity.getWorld();
|
World world = entity.getWorld();
|
||||||
Location location = entity.getLocation();
|
Location location = entity.getLocation();
|
||||||
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
|
|
||||||
World worldend = Bukkit.getWorld("world_the_end");
|
|
||||||
Location locationblock = new Location(worldend, 100, 49, 0);
|
|
||||||
Block block = locationblock.getBlock();
|
|
||||||
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
|
|
||||||
Vector velocity = switch (counter % 4) {
|
Vector velocity = switch (counter % 4) {
|
||||||
case 0 -> new Vector(0, 0.5, -1);
|
case 0 -> new Vector(0, 0.5, -1);
|
||||||
case 1 -> new Vector(-1, 0.5, 0);
|
case 1 -> new Vector(-1, 0.5, 0);
|
||||||
|
|
@ -77,17 +70,15 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
default -> new Vector(1, 0.5, 0);
|
default -> new Vector(1, 0.5, 0);
|
||||||
};
|
};
|
||||||
counter++;
|
counter++;
|
||||||
|
Material material = ((FallingBlock) entity).getBlockData().getMaterial();
|
||||||
|
byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0];
|
||||||
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data);
|
||||||
newFallingBlock.setVelocity(velocity);
|
newFallingBlock.setVelocity(velocity);
|
||||||
|
entity.remove();
|
||||||
// Remove the original block
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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