[Lib][1.7.9] PetMaker V1.0 - How to make pets!

Discussion in 'Resources' started by bigteddy98, May 30, 2014.

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

    bigteddy98

    done, thanks ;)

    added, thanks ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  2. Offline

    unforgiven5232

  3. Offline

    MineCrypt

    I seem to be having problems with this code, I'm just wondering what release of Bukkit 1.7.9 you are using? See if that resolves the issue.
     
  4. Offline

    coco5843

    bigteddy98
    I change your class for bukkit 1.7.2:

    But how can I change the speed of entity

    Code:java
    1. package PetRiderEffect;
    2.  
    3. import java.lang.reflect.Field;
    4.  
    5. import net.minecraft.server.v1_7_R1.EntityInsentient;
    6. import net.minecraft.server.v1_7_R1.PathEntity;
    7. import net.minecraft.server.v1_7_R1.PathfinderGoal;
    8. import net.minecraft.server.v1_7_R1.PathfinderGoalFloat;
    9. import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
    10.  
    11. import org.bukkit.Location;
    12. import org.bukkit.craftbukkit.v1_7_R1.entity.CraftLivingEntity;
    13. import org.bukkit.craftbukkit.v1_7_R1.util.UnsafeList;
    14. import org.bukkit.entity.LivingEntity;
    15. import org.bukkit.entity.Player;
    16.  
    17. public class PetMaker {
    18.  
    19. private static Field gsa;
    20. private static Field goalSelector;
    21. private static Field targetSelector;
    22.  
    23. static {
    24. try {
    25. gsa = PathfinderGoalSelector.class.getDeclaredField("b");
    26. gsa.setAccessible(true);
    27.  
    28. goalSelector = EntityInsentient.class.getDeclaredField("goalSelector");
    29. goalSelector.setAccessible(true);
    30.  
    31. targetSelector = EntityInsentient.class.getDeclaredField("targetSelector");
    32. targetSelector.setAccessible(true);
    33. } catch (Exception e) {
    34. e.printStackTrace();
    35. }
    36. }
    37.  
    38. @SuppressWarnings("deprecation")
    39. public static void makePet(LivingEntity e, Player toFollow) {
    40. try {
    41. Object nms_entity = ((CraftLivingEntity) e).getHandle();
    42. if (nms_entity instanceof EntityInsentient) {
    43.  
    44. PathfinderGoalSelector goal = (PathfinderGoalSelector) goalSelector.get(nms_entity);
    45. PathfinderGoalSelector target = (PathfinderGoalSelector) targetSelector.get(nms_entity);
    46.  
    47. gsa.set(goal, new UnsafeList<Object>());
    48. gsa.set(target, new UnsafeList<Object>());
    49.  
    50. goal.a(0, new PathfinderGoalFloat((EntityInsentient) nms_entity));
    51. goal.a(1, new PathfinderGoalWalktoTile((EntityInsentient) nms_entity, toFollow));
    52.  
    53. } else {
    54. throw new IllegalArgumentException(e.getType().getName() + " is not an instance of an EntityInsentient.");
    55. }
    56. } catch (Exception ex) {
    57. ex.printStackTrace();
    58. }
    59. }
    60.  
    61. public static class PathfinderGoalWalktoTile extends PathfinderGoal {
    62.  
    63. private EntityInsentient entity;
    64. private PathEntity path;
    65. private Player p;
    66.  
    67. public PathfinderGoalWalktoTile(EntityInsentient entitycreature, Player p) {
    68. this.entity = entitycreature;
    69. this.p = p;
    70. }
    71.  
    72. @Override
    73. public boolean a() {
    74. Location targetLocation = p.getLocation();
    75.  
    76. boolean flag = this.entity.getNavigation().c();
    77.  
    78. this.entity.getNavigation().b(false);
    79. this.path = this.entity.getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
    80. this.entity.getNavigation().b(flag);
    81.  
    82. if (this.path != null) {
    83. this.c();
    84. }
    85. return this.path != null;
    86. }
    87.  
    88. @Override
    89. public void c() {
    90. this.entity.getNavigation().a(this.path, 1D);
    91. }
    92. }
    93. }
     
  5. Offline

    bigteddy98

    At line 90, there currently is a double with value 1. Change it to whatever you want to increase/decrease speed.
     
    coco5843 likes this.
  6. Offline

    ZodiacTheories

  7. Offline

    paully104

    bigteddy98, Thanks for the resource i'm toying around with it, I am not very knowledgeable with nms but i'm trying. To get to the point i'm trying to modify the resource so that the pets will attack anyone who attacks the person they belong to. I tried using settarget to see if its as simple as that. I've also tried some slight modifications such as
    Code:
                    goal.a(2, new PathfinderGoalFloat((EntityInsentient) nms_entity));
                    goal.a(3, new PathfinderGoalWalktoTile((EntityInsentient) nms_entity, toFollow));
                    goal.a(1, new PathfinderGoalMeleeAttack((EntityCreature) nms_entity, Monster.class, 1.0D, true));
                    goal.a(0, new PathfinderGoalNearestAttackableTarget((EntityCreature) nms_entity, Monster.class, 0, true));
    I was hoping you could lead me in the right direction ^^.
     
  8. Offline

    Elimnator

    bigteddy98
    It works for creepers but I tried using it for Zombie Pigmen and it doesn't work?

    Can anyone help me?
     
  9. Offline

    xTigerRebornx

    Garris0n likes this.
  10. Offline

    Elimnator

    xTigerRebornx
    When I try to over ride it, it says: "must override or implement a supertype method"
     
  11. Offline

    xTigerRebornx

  12. Offline

    Elimnator

    xTigerRebornx
    I have the default class that is on the OP, I just tried to add the override and it isn't working. That class has nothing to do with Pig Zombies so IDK how I'm supposed to do the override.
     
  13. Offline

    xTigerRebornx

    Elimnator Ah.....I see.
    Currently, I don't believe the OPs code supports an Entity has its pathfinders disabled.
     
  14. Offline

    Elimnator

    xTigerRebornx
    Nothing is disabled, I copied that exact class and used it in my plugin, when I use it for a creeper he follows me fine.
    But I want a zombie pigman to follow me, but it wont work for him. I just need some help to get it to work for
    zombie pigmen.
     
  15. Offline

    xTigerRebornx

    Elimnator Its because EntityCreeper (nms creeper) overrides the method to return true, allowing for it to accept pathfinders. Since EntityPigZombie (nms pigman) returns false, it won't accept the pathfinders, making it impossible to use without extending it (or another form of modifying its return).
    To sum it up, the class currently can't work with Zombie Pigman.
     
  16. Offline

    PandazNWafflez

  17. Offline

    Elimnator

    xTigerRebornx
    If I create a custom ZombiePigman and override that method in it to return true. Then will the pet thing work?
     
  18. Offline

    xTigerRebornx

    Elimnator You'll have to make sure all zombie pigman spawned are yours and all previous are also made yours (overriding an entity requires some work)
     
  19. Offline

    Elimnator

    xTigerRebornx
    I'm only planing in doing this to a custom spawned Entity that extends PigZombie.
    So it should work if I do that?
     
  20. Offline

    xTigerRebornx

    Elimnator Assuming you spawn that PigZombie rather then a normal one (requires using the NMS World as CB methods will spawn in CB entities), yes.
     
  21. Offline

    Elimnator

    xTigerRebornx
    I'm trying to spawn my custom entity but whenever my code runs, my Minecraft client crashes:
    Code:
    net.minecraft.server.v1_7_R3.World mcWorld = ((CraftWorld) p.getWorld()).getHandle();
    EntityCannibal ec = new EntityCannibal(mcWorld);
    ec.setPosition(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
    mcWorld.addEntity(ec, SpawnReason.CUSTOM);
     
  22. Offline

    xTigerRebornx

  23. Offline

    Elimnator

    xTigerRebornx
    OK I tired the patch thing but nothing changed.
    I fixed the crash, but when I spawn the entity nothing happens now.

    bigteddy98
    Can anyone help me with this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  24. Offline

    iMurder

    bigteddy98 Why do the following mobs simply act normally, instead of doing the normal pet following thing?
    Slime, Magma Cube, Squid, Spider (probably cave spider too), Enderman, Blaze and Ender Dragon?
    :/
     
Thread Status:
Not open for further replies.

Share This Page