Mob don't target the Location(PathFinderGoals)

Discussion in 'Plugin Development' started by solrac200, Jan 5, 2016.

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

    solrac200

    The Mobs don't target a Location and there isn't a error message at the console.
    Sorry for my bad english.
    Here my code:
    Code:
    package EntitysNEW;
    
    import org.bukkit.Location;
    
    import net.minecraft.server.v1_8_R3.EntityInsentient;
    import net.minecraft.server.v1_8_R3.Navigation;
    import net.minecraft.server.v1_8_R3.PathEntity;
    import net.minecraft.server.v1_8_R3.PathfinderGoal;
    
    public class PathFinderGoalWalkToLoc extends PathfinderGoal{
    
         private EntityInsentient entity;
    
           private Location loc;
    
           private Navigation navigation;
    
        private double speed;
    
           public PathFinderGoalWalkToLoc(EntityInsentient entity, Location loc, double speed)
           {
             this.entity = entity;
             this.loc = loc;
             this.navigation = (Navigation) this.entity.getNavigation();
             this.speed = speed;
           }
           public boolean a()
           {
             return true;
           }
           public void c()
            {
                PathEntity pathEntity = this.navigation.a(loc.getX(), loc.getY(), loc.getZ());
    
                this.navigation.a(pathEntity, speed);
            }
        }
    Mob Class:
    Code:
    package EntitysNEW;
    
    import java.lang.reflect.Field;
    import java.util.List;
    
    import net.minecraft.server.v1_8_R3.EntityHuman;
    import net.minecraft.server.v1_8_R3.EntityVillager;
    import net.minecraft.server.v1_8_R3.EntityZombie;
    import net.minecraft.server.v1_8_R3.PathfinderGoalFloat;
    import net.minecraft.server.v1_8_R3.PathfinderGoalHurtByTarget;
    import net.minecraft.server.v1_8_R3.PathfinderGoalLookAtPlayer;
    import net.minecraft.server.v1_8_R3.PathfinderGoalMeleeAttack;
    import net.minecraft.server.v1_8_R3.PathfinderGoalMoveTowardsRestriction;
    import net.minecraft.server.v1_8_R3.PathfinderGoalNearestAttackableTarget;
    import net.minecraft.server.v1_8_R3.PathfinderGoalRandomLookaround;
    import net.minecraft.server.v1_8_R3.PathfinderGoalRandomStroll;
    import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
    import net.minecraft.server.v1_8_R3.World;
    
    import org.bukkit.Location;
    
    public class TLZombie extends EntityZombie{
    
        public TLZombie(World world, Location loc, Location spawn)
        {
            super(world);
    
            List goalB = (List)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
            List goalC = (List)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            List targetB = (List)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
            List targetC = (List)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();
           
            this.goalSelector.a(0, new PathfinderGoalFloat(this));
            this.goalSelector.a(1, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityVillager.class, 1.0D, true));
            this.goalSelector.a(4, new PathfinderGoalRandomStroll(this, 1.0D));
            this.goalSelector.a(5, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));
            this.goalSelector.a(6, new PathfinderGoalRandomLookaround(this));
            this.targetSelector.a(1, new PathFinderGoalWalkToLoc(this, loc, 5));
            this.targetSelector.a(2, new PathfinderGoalHurtByTarget(this, true));
            setLocation(spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getYaw(), spawn.getPitch());
        }
    
        public static Object getPrivateField(String fieldName, Class clazz, Object object)
        {
            Field field;
            Object o = null;
    
            try
            {
                field = clazz.getDeclaredField(fieldName);
    
                field.setAccessible(true);
    
                o = field.get(object);
            }
            catch(NoSuchFieldException e)
            {
                e.printStackTrace();
            }
            catch(IllegalAccessException e)
            {
                e.printStackTrace();
            }
    
            return o;
        }
    }
    register mob:
    Code:
    public void register(){
            try {
                Field c = EntityTypes.class.getDeclaredField("c");
                Field f = EntityTypes.class.getDeclaredField("f");
                f.setAccessible(true);
                c.setAccessible(true);
                try {
                    ((HashMap<Class<? extends EntityInsentient>, String>) c.get(null)).put(TLZombie.class, "Zombie");
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                }
                try {
                    ((HashMap<Class<? extends EntityInsentient>, Integer>) f.get(null)).put(TLZombie.class, 54);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            } catch (NoSuchFieldException | SecurityException e) {
                e.printStackTrace();
            }
        }
    Spawning mob:
    Code:
    World world = ((CraftWorld)Bukkit.getWorld("world")).getHandle();
                    TLZombie zombie = new TLZombie(world, loc2, loc);
                    world.addEntity(zombie);
     
  2. Offline

    mcdorli

    Can wesee that error?
     
  3. Offline

    solrac200

    There is no error the spawn but not target the location
     
  4. Offline

    AztroCreationz

    Uhmmm...
    EDIT: Semi-ninja'd
     
    Last edited: Jan 5, 2016
  5. Offline

    Zombie_Striker

  6. Offline

    solrac200

    I did it, but same problem
     
  7. I'm a bit too busy to compare code right now, but this was an issue that I ran into for a long time as well.
    After a while I managed to solve it, have a look and maybe you can find what you need to change ;)

    https://github.com/xorinzor/Warbuil...jorinvermeulen/warbuild/nms/EntityZombie.java

    note: this is still for the older 1.6 version, so you'd have to check the repositories what the nms variable names are for the current version
     
Thread Status:
Not open for further replies.

Share This Page