NMS

Discussion in 'Plugin Development' started by Darris, Jan 20, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Darris

    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());
    }
    
     
  2. @Darris

    What part is not working? (Nothing happens? Errors in the console? Something completely different happens?)
     
  3. Offline

    Darris

    Nothing happens, there are no errors in the console.
     
  4. @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.)
     
  5. Offline

    Darris

    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
     
  6. @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.
     
  7. Offline

    Darris

    Okay, I understand the mistake. How to fix?
     
  8. @Darris

    My best guess is this:
    Code:
    ((CraftWorld) world).getHandle().addEntity(new MyZombie(world));
     
  9. Offline

    Darris

    No.
    Code:
    
     Entity e;
            switch (e.getType()) {
                case ZOMBIE: {
                    e = ((CraftWorld) world).getHandle().addEntity(new MyZombie(world));
                    break;
                }
                default: {
                    //other
                    break;
                }
            }
    
     
Thread Status:
Not open for further replies.

Share This Page