Skeletons stand still and still shoot?

Discussion in 'Plugin Development' started by Gamesareme, Oct 3, 2014.

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

    Gamesareme

    I have been racking the Bukkit GitHub page for solutions as well as the forums, but I can not work out how to make so skeletons do not move, but still attacks something that comes to close to it. I am trying to make the skeleton like a tower. I have tried to make a custom PathfinderGoalNearestAttackableTarget but I have had no luck. (Manly because I could not get EntitySelectorNearestAttackableTarget to compile). I would be great if someone could help me work out how to make so that skeletons stand still but still shoot things that come into range, with out moving towards them.
     
  2. Every x milliseconds teleport the skeleton to the location you want it, sorta like it's not moving
     
  3. Offline

    Gamesareme

    legostarwarszach I will give that a try, but it may look a little weird. I am open to other suggestions as well.

    legostarwarszach That kind of looks messy, so the idea I cam up with is letting the entity walk to the spot it needs to be, every time it has no targets near by. I am having a problem though. I have made custom zombies that walk where I want, so I think I know how to do this. Any way no mater what I try, even using the same code I used for the zombies, I can not get the skeleton to walk to the spot allocated. Can some one see what I am lacking. I am really confused as the code I am using works for anther entity.
    CustomEntityTower
    Code:java
    1. import java.lang.reflect.Field;
    2. import java.util.List;
    3. import java.util.Map;
    4.  
    5. import net.minecraft.server.v1_7_R3.BiomeBase;
    6. import net.minecraft.server.v1_7_R3.BiomeMeta;
    7. import net.minecraft.server.v1_7_R3.EntityInsentient;
    8. import net.minecraft.server.v1_7_R3.EntitySkeleton;
    9. import net.minecraft.server.v1_7_R3.EntityTypes;
    10.  
    11. import org.bukkit.entity.EntityType;
    12.  
    13. public enum CustomEntityTypeTower {
    14.  
    15. SKELETON("Skeleton", 51, EntityType.SKELETON, EntitySkeleton.class,
    16. CustomEntityTower.class);
    17.  
    18. private String name;
    19. private int id;
    20. private EntityType entityType;
    21. private Class<? extends EntityInsentient> nmsClass;
    22. private Class<? extends EntityInsentient> customClass;
    23.  
    24. private CustomEntityTypeTower(String name, int id, EntityType entityType,
    25. Class<? extends EntityInsentient> nmsClass,
    26. Class<? extends EntityInsentient> customClass) {
    27. this.name = name;
    28. this.id = id;
    29. this.entityType = entityType;
    30. this.nmsClass = nmsClass;
    31. this.customClass = customClass;
    32. }
    33.  
    34. public String getName() {
    35. return name;
    36. }
    37.  
    38. public int getID() {
    39. return id;
    40. }
    41.  
    42. public EntityType getEntityType() {
    43. return entityType;
    44. }
    45.  
    46. public Class<? extends EntityInsentient> getNMSClass() {
    47. return nmsClass;
    48. }
    49.  
    50. public Class<? extends EntityInsentient> getCustomClass() {
    51. return customClass;
    52. }
    53.  
    54. public static void registerEntities() {
    55. for (CustomEntityTypeTower entity : values())
    56. a(entity.getCustomClass(), entity.getName(), entity.getID());
    57.  
    58. BiomeBase[] biomes;
    59. try {
    60. biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
    61. } catch (Exception exc) {
    62. return;
    63. }
    64. for (BiomeBase biomeBase : biomes) {
    65. if (biomeBase == null)
    66. break;
    67.  
    68. for (String field : new String[] { "as", "at", "au", "av" })
    69. try {
    70. Field list = BiomeBase.class.getDeclaredField(field);
    71. list.setAccessible(true);
    72. @SuppressWarnings("unchecked")
    73. List<BiomeMeta> mobList = (List<BiomeMeta>) list
    74. .get(biomeBase);
    75.  
    76. for (BiomeMeta meta : mobList)
    77. for (CustomEntityTypeTower entity : values())
    78. if (entity.getNMSClass().equals(meta.b))
    79. meta.b = entity.getCustomClass();
    80. } catch (Exception e) {
    81. e.printStackTrace();
    82. }
    83. }
    84. }
    85.  
    86. @SuppressWarnings("rawtypes")
    87. public static void unregisterEntities() {
    88. for (CustomEntityTypeTower entity : values()) {
    89. // Remove our class references.
    90. try {
    91. ((Map) getPrivateStatic(EntityTypes.class, "d")).remove(entity
    92. .getCustomClass());
    93. } catch (Exception e) {
    94. e.printStackTrace();
    95. }
    96.  
    97. try {
    98. ((Map) getPrivateStatic(EntityTypes.class, "f")).remove(entity
    99. .getCustomClass());
    100. } catch (Exception e) {
    101. e.printStackTrace();
    102. }
    103. }
    104.  
    105. for (CustomEntityTypeTower entity : values())
    106. try {
    107. // Unregister each entity by writing the NMS back in place of
    108. // the custom class.
    109. a(entity.getNMSClass(), entity.getName(), entity.getID());
    110. } catch (Exception e) {
    111. e.printStackTrace();
    112. }
    113.  
    114. // Biomes#biomes was made private so use reflection to get it.
    115. BiomeBase[] biomes;
    116. try {
    117. biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
    118. } catch (Exception exc) {
    119. // Unable to fetch.
    120. return;
    121. }
    122. for (BiomeBase biomeBase : biomes) {
    123. if (biomeBase == null)
    124. break;
    125.  
    126. // The list fields changed names but update the meta regardless.
    127. for (String field : new String[] { "as", "at", "au", "av" })
    128. try {
    129. Field list = BiomeBase.class.getDeclaredField(field);
    130. list.setAccessible(true);
    131. @SuppressWarnings("unchecked")
    132. List<BiomeMeta> mobList = (List<BiomeMeta>) list
    133. .get(biomeBase);
    134.  
    135. // Make sure the NMS class is written back over our custom
    136. // class.
    137. for (BiomeMeta meta : mobList)
    138. for (CustomEntityTypeTower entity : values())
    139. if (entity.getCustomClass().equals(meta.b))
    140. meta.b = entity.getNMSClass();
    141. } catch (Exception e) {
    142. e.printStackTrace();
    143. }
    144. }
    145. }
    146.  
    147. @SuppressWarnings("rawtypes")
    148. private static Object getPrivateStatic(Class clazz, String f)
    149. throws Exception {
    150. Field field = clazz.getDeclaredField(f);
    151. field.setAccessible(true);
    152. return field.get(null);
    153. }
    154.  
    155. @SuppressWarnings({ "unchecked", "rawtypes" })
    156. private static void a(Class paramClass, String paramString, int paramInt) {
    157. try {
    158. ((Map) getPrivateStatic(EntityTypes.class, "c")).put(paramString,
    159. paramClass);
    160. ((Map) getPrivateStatic(EntityTypes.class, "d")).put(paramClass,
    161. paramString);
    162. ((Map) getPrivateStatic(EntityTypes.class, "f")).put(paramClass,
    163. Integer.valueOf(paramInt));
    164. ((Map) getPrivateStatic(EntityTypes.class, "g")).put(paramString,
    165. Integer.valueOf(paramInt));
    166. } catch (Exception exc) {
    167. }
    168. }
    169. }


    This is where I have changed what I want the skeleton to do.

    CustomEntitySkeleton

    Code:java
    1. import java.lang.reflect.Field;
    2.  
    3. import net.minecraft.server.v1_7_R3.EntitySkeleton;
    4. import net.minecraft.server.v1_7_R3.PathfinderGoalFloat;
    5. import net.minecraft.server.v1_7_R3.PathfinderGoalHurtByTarget;
    6. import net.minecraft.server.v1_7_R3.PathfinderGoalLookAtPlayer;
    7. import net.minecraft.server.v1_7_R3.PathfinderGoalNearestAttackableTarget;
    8. import net.minecraft.server.v1_7_R3.PathfinderGoalSelector;
    9. import net.minecraft.server.v1_7_R3.World;
    10.  
    11. import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;
    12.  
    13. public class CustomEntityTower extends EntitySkeleton{
    14.  
    15. public CustomEntityTower(World world) {
    16. super(world);
    17. try {
    18. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
    19. bField.setAccessible(true);
    20. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
    21. cField.setAccessible(true);
    22. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    23. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    24. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
    25. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
    26. } catch (Exception exc) {
    27. exc.printStackTrace();
    28. }
    29. this.goalSelector.a(1, new PathfinderGoalFloat(this));
    30. this.goalSelector.a(4, new PathfinderGoalTower(this, (float) 1.0));
    31. this.goalSelector.a(6, new PathfinderGoalLookAtPlayer(this, CustomEntityPigZombie.class, 8.0F));
    32. this.targetSelector.a(1, new PathfinderGoalHurtByTarget(this, false));
    33. this.targetSelector.a(2, new PathfinderGoalNearestAttackableTarget(this, CustomEntityPigZombie.class, 0, true));
    34. }
    35. }
    36.  


    This is the custom path finder.


    PathfinderGoalSkeleton

    Code:java
    1. import net.minecraft.server.v1_7_R3.EntityCreature;
    2. import net.minecraft.server.v1_7_R3.PathfinderGoal;
    3.  
    4. public class PathfinderGoalTower extends PathfinderGoal {
    5.  
    6. // public boolean willWalkToTile = true;
    7.  
    8. float speed;
    9. private EntityCreature entitycreature;
    10.  
    11. public PathfinderGoalTower(EntityCreature entitycreature, float speed) {
    12. this.speed = speed;
    13. this.entitycreature = entitycreature;
    14. }
    15.  
    16. @Override
    17. public boolean a() {
    18. if (this.entitycreature instanceof CustomEntityTower) {
    19. if (this.entitycreature.target == null) {
    20. return true;
    21. }
    22. if (this.entitycreature.target != null && this.entitycreature.target.isAlive() == false) {
    23. return true;
    24. } else {
    25. return false;
    26. }
    27. }
    28. return false;
    29. }
    30.  
    31. @Override
    32. public void e() {
    33. this.entitycreature.getNavigation().a(60, 60, 100, speed);
    34. }
    35.  
    36. }


    As I said before, this works for zombies, so I have no idea why it does not work here. Any help would be great.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page