Custom Mob does not have PathFinderGoals

Discussion in 'Plugin Development' started by AndrewAnderVille, Jan 19, 2015.

Thread Status:
Not open for further replies.
  1. I tried to make a "subtype" for the mob, but it seems there is no movement in the zombies that spawn.

    Code for the Entity
    Code:java
    1.  
    2. import java.lang.reflect.Field;
    3.  
    4. import net.minecraft.server.v1_7_R3.Block;
    5. import net.minecraft.server.v1_7_R3.EntityHuman;
    6. import net.minecraft.server.v1_7_R3.EntityZombie;
    7. import net.minecraft.server.v1_7_R3.GenericAttributes;
    8. import net.minecraft.server.v1_7_R3.Item;
    9. import net.minecraft.server.v1_7_R3.PathfinderGoalFloat;
    10. import net.minecraft.server.v1_7_R3.PathfinderGoalHurtByTarget;
    11. import net.minecraft.server.v1_7_R3.PathfinderGoalLookAtPlayer;
    12. import net.minecraft.server.v1_7_R3.PathfinderGoalMeleeAttack;
    13. import net.minecraft.server.v1_7_R3.PathfinderGoalMoveThroughVillage;
    14. import net.minecraft.server.v1_7_R3.PathfinderGoalMoveTowardsRestriction;
    15. import net.minecraft.server.v1_7_R3.PathfinderGoalNearestAttackableTarget;
    16. import net.minecraft.server.v1_7_R3.PathfinderGoalRandomLookaround;
    17. import net.minecraft.server.v1_7_R3.PathfinderGoalRandomStroll;
    18. import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
    19. import net.minecraft.server.v1_7_R3.World;
    20.  
    21. import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    22. import org.bukkit.entity.Zombie;
    23. import org.bukkit.potion.PotionEffect;
    24. import org.bukkit.potion.PotionEffectType;
    25.  
    26. public class GZombieEntity extends EntityZombie{
    27.  
    28. boolean vampire = false;
    29. double damage = 3.2D;
    30. double movementspeed = .25D;
    31. double followrange = 35D;
    32. double melee = 1.2D;
    33. float lookat = 9F;
    34.  
    35. public GZombieEntity(World world){
    36. super(world);
    37.  
    38. }
    39.  
    40. public void setUpProperties(){
    41.  
    42.  
    43. Zombie z = (Zombie)getBukkitEntity();
    44. z.setBaby(false);
    45. z.setVillager(false);
    46. z.setCanPickupItems(false);
    47. z.getEquipment().clear();
    48. if(vampire){
    49. z.setVillager(true);
    50. z.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
    51. damage = 2.6D;
    52. movementspeed = .27D;
    53. followrange = 50D;
    54. melee = 1.7D;
    55. lookat = 11F;
    56. }
    57.  
    58.  
    59.  
    60. getNavigation().b(true);
    61. //Removes all pathfindergoals
    62. try {
    63. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    64. bField.setAccessible(true);
    65. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    66. cField.setAccessible(true);
    67. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    68. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    69. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    70. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    71. } catch (Exception exc) {
    72. exc.printStackTrace();
    73. }
    74. //New pathfinders
    75. this.goalSelector.a(0, new PathfinderGoalFloat(this));
    76. this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, melee, false)); //originally 1.0
    77. this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    78. this.goalSelector.a(6, new PathfinderGoalMoveThroughVillage(this, 1.0D, false));
    79. this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
    80. this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, lookat)); //originally 8.0
    81. this.goalSelector.a(8, new PathfinderGoalRandomLookaround(this));
    82. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, true));
    83. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 0, true));
    84.  
    85. }
    86.  
    87.  
    88.  
    89.  
    90. //e is damage
    91. //d is movement speed
    92. //b follow range
    93. @Override
    94. protected void aC() {
    95. super.aC();
    96. getAttributeInstance(GenericAttributes.e).setValue(damage);
    97. getAttributeInstance(GenericAttributes.b).setValue(followrange);
    98. getAttributeInstance(GenericAttributes.d).setValue(movementspeed);0.23000000417232513D
    99. getAttributeInstance(bp).setValue(0);
    100. }
    101.  
    102. public void setVampire(){
    103. vampire = true;
    104. Zombie z = (Zombie)getBukkitEntity();
    105. z.setVillager(true);
    106. }
    107.  
    108. protected String t() {
    109. if(vampire){
    110. return "mob.endermen.idle";
    111. }else{
    112. return "mob.zombie.say";
    113. }
    114. }
    115.  
    116. protected String aS() {
    117. if(vampire){
    118. return "random.fizz";
    119. }else{
    120. return "mob.zombie.hurt";
    121. }
    122.  
    123. }
    124.  
    125. protected String aT() {
    126. if(vampire){
    127. return "mob.ghast.scream";
    128. }else{
    129. return "mob.zombie.death";
    130. }
    131.  
    132. }
    133.  
    134. protected void a(int i, int j, int k, Block block) {
    135. if(vampire){
    136.  
    137. }else{
    138. makeSound("mob.zombie.step", 0.15F, 1.0F);
    139. }
    140.  
    141. }
    142.  
    143. protected Item getLoot() {
    144. return null;
    145. }
    146.  
    147.  
    148. protected void getRareDrop(int i) {
    149.  
    150. }
    151.  
    152.  
    153.  
    154. public void setOnFire(int i)
    155. {
    156. if(vampire){
    157. int j = i * 20;
    158. if (this.fireTicks < j)this.fireTicks = j;
    159. }
    160. }
    161.  
    162. public int getExpReward()
    163. {
    164. return 0;
    165. }
    166.  
    167. }
    168.  


    Here is how I spawn them.
    Code:java
    1.  
    2. GZombieEntity vet = new GZombieEntity(((CraftWorld)event.getLocation().getWorld()).getHandle());
    3. vet.setVampire();
    4. vet.setUpProperties();
    5. vet.setLocation(x, y, z, 0, 0);
    6. ((CraftWorld)event.getLocation().getWorld()).getHandle().addEntity(vet, CreatureSpawnEvent.SpawnReason.CUSTOM);
    7.  
     
  2. Offline

    TGRHavoc

  3. See the second snippet of code.
     
  4. Offline

    TGRHavoc

    @AndrewAnderVille
    Ah, fair point. Any reason you're not calling this method inside of the class itself and instead calling it externally?
     
  5. Basically its so there can be two versions of the mob. I need to change what the subtype is before I call setUpProperties().
     
  6. Offline

    DemKazoo

    Code:
     getAttributeInstance(GenericAttributes.d).setValue(movementspeed);0.23000000417232513D
    Your code just makes me think,
    [​IMG]


    Anyway you don't need to create a "sub-type" just create a different class which also extends the entity you want, but then you would need to also register it in your entitymanager.
     
  7. In the original code that's commented out. It's a copy and paste issue. And ok I'll try that
     
Thread Status:
Not open for further replies.

Share This Page