Hello! My nms entity not working. Please help. I use method handle on spawn my custom entity with command (/entity [id] config). My code: Code: public static Entity handle(Entity e, EntityType type, Location l, World world) { net.minecraft.server.v1_8_R3.Entity myEntity = null; WorldServer w = ((CraftWorld) world).getHandle(); switch (type) { case ZOMBIE: { myEntity = new MyZombie(world); break; } default: { return e; } } myEntity.setPosition(l.getX(), l.getY(), l.getZ()); w.removeEntity(((CraftEntity) e).getHandle()); w.addEntity(myEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); e = (myEntity).getBukkitEntity(); return e; } Code: public class MyZombie extends EntityZombie{ public MyZombie(World world) { super(world); this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0, false)); } public MyZombie(org.bukkit.World world) { this(((CraftWorld) world).getHandle()); } } Code: public void spawn(Location l) { EntityType type; Entity entity = location.getWorld().spawnEntity(l, type); entity = CustomEntities.handle(entity, type, l, l.getWorld()); }
@Darris What part is not working? (Nothing happens? Errors in the console? Something completely different happens?)
@Darris I see what goes wrong: Your spawn method doesn't work because the custom entity will not be spawned. You are only replacing your own entity variable by the custom entity, but not the entity in the worlds entity list. I think you need to get the handle of the CraftWorld and invoke its spawnEntity method. (Or something similar.)
No. The method spawn works for me, not working adding to the Moba NMS (e = entity = CustomEntities.handle(entity, type, l, l.getWorld (), so I don't know what to do
@Darris This line Code: Entity entity = location.getWorld().spawnEntity(l, type); spawns a normal entity. This line Code: entity = CustomEntities.handle(entity, type, l, l.getWorld()); is useless because the original entity is already spawned and you are not doing anything with the custom entity.
@Darris My best guess is this: Code: ((CraftWorld) world).getHandle().addEntity(new MyZombie(world));
No. Code: Entity e; switch (e.getType()) { case ZOMBIE: { e = ((CraftWorld) world).getHandle().addEntity(new MyZombie(world)); break; } default: { //other break; } }