Set zombie's target to something out of range?

Discussion in 'Plugin Development' started by Plo124, Apr 26, 2014.

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

    Plo124

    So Im trying to make a Police system and there are 2 police stations on the other sides of the maps, and when a player kills another 2 police are sent to the killer. When I try to set their target to something big like 100 blocks away, outside their range, the zombie wont actually go there, even if I use the EntityTargetEvent.

    Any ways to do this, NMS code is ok (using 1.7_R2).
    I have no experience with overriding mobs and making them walk somewhere.
     
  2. Offline

    ZeusAllMighty11

    You can set their attribute for follow range to a higher amount, but it may cause lag.
     
  3. Offline

    Plo124

    ZeusAllMighty11
    Which param under EntityZombie / EntityLiving does this? Its all obfuscated and I have no idea :(
     
  4. Offline

    TryB4

    Plo124 likes this.
  5. Offline

    Plo124

    ZeusAllMighty11 TryB4
    I'm trying to summon my custom zombies now, but they dont appear. Instead my minecraft crashes for an IOException. No error on the console.

    Code:java
    1. package me.Plo457.cop;
    2.  
    3. import java.lang.reflect.Field;
    4.  
    5. import net.minecraft.server.v1_7_R2.EntityZombie;
    6. import net.minecraft.server.v1_7_R2.GenericAttributes;
    7. import net.minecraft.server.v1_7_R2.PathfinderGoalFloat;
    8. import net.minecraft.server.v1_7_R2.PathfinderGoalSelector;
    9. import net.minecraft.server.v1_7_R2.World;
    10.  
    11. import org.bukkit.craftbukkit.v1_7_R2.util.UnsafeList;
    12.  
    13.  
    14. public class CustomEntityZombie extends EntityZombie {
    15.  
    16. public CustomEntityZombie(World world) {
    17. super(world);
    18.  
    19. try {
    20. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    21. bField.setAccessible(true);
    22. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    23. cField.setAccessible(true);
    24. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    25. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    26. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    27. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    28. } catch (Exception exc) {
    29. exc.printStackTrace();
    30. }
    31. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    32. this.targetSelector.a(1, new PathfinderGoalKillTarget(this));
    33. }
    34. @Override
    35. protected void aD() {
    36. super.aD();
    37. this.getAttributeInstance(GenericAttributes.b).setValue(300.0D); // Original 3.0D
    38. }
    39. }
    40.  

    Code:java
    1. package me.Plo457.cop;
    2.  
    3. import java.util.Map.Entry;
    4.  
    5. import net.minecraft.server.v1_7_R2.Entity;
    6. import net.minecraft.server.v1_7_R2.EntityCreature;
    7. import net.minecraft.server.v1_7_R2.PathfinderGoal;
    8.  
    9. import org.bukkit.entity.Player;
    10.  
    11. public class PathfinderGoalKillTarget extends PathfinderGoal {
    12. private EntityCreature entitycreature;
    13. public PathfinderGoalKillTarget(EntityCreature entitycreature){
    14. this.entitycreature = entitycreature;
    15. }
    16.  
    17.  
    18. @Override
    19. public boolean a() {
    20. return true;
    21. }
    22. @Override
    23. public void c(){
    24. Player target = null;
    25. for (Entry<String, Crime> crime : CrimeHandler.crimes.entrySet()){
    26. if (crime.getValue().cops.contains(this.entitycreature)){
    27. target = crime.getValue().getPlayer();
    28. }
    29. }
    30. if (target != null){
    31. this.entitycreature.getNavigation().a((Entity) target);
    32. } else {
    33. this.entitycreature.getNavigation().a(this.entitycreature.locX,this.entitycreature.locY,this.entitycreature.locZ);
    34. }
    35. }
    36. }
    37.  

    Code:java
    1. CustomEntityZombie zombie = new CustomEntityZombie(((CraftWorld)location.getWorld()).getHandle());
    2. zombie.setLocation(station.getLocation().getX(),station.getLocation().getY(),station.getLocation().getZ(),0,0);
    3. ((CraftWorld)location.getWorld()).getHandle().addEntity(zombie);
     
  6. Offline

    Plo124

    bump, the question is now how to summon a custom zombie
     
  7. Offline

    TryB4

    Plo124
    Code:java
    1. zombie.setLocation(station.getLocation().getX(),station.getLocation().getY(),station.getLocation().getZ(),station.getLocation().getYaw(),station.getLocation().getPitch());
    2.  
    3. ((CraftWorld) world).getHandle().addEntity(zombie, SpawnReason.CUSTOM);
    4.  
    5.  


    Don't get the zombie's world as it hasn't spawned yet.
     
  8. Offline

    Plo124

    TryB4
    location.getWorld() is the location the zombie will spawn, its not calling zombie.getWorld().
     
Thread Status:
Not open for further replies.

Share This Page