Tutorial [1.8] Pet following + pet speed [1.7 too]

Discussion in 'Resources' started by matanrak, Nov 30, 2014.

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

    Skionz

    @Cheesepro He did.
     
  2. Offline

    Cheesepro

    @Skionz oh... sry xD my bad.
    But @matanrak can you add a teleport listener in your api? Since when ever I teleport to another world a error will display in the console:
    Code:
    [22:09:24] [Server thread/WARN]: [CheeseEssentials] Task #14 for CheeseEssentials v1 generated an exception
    java.lang.IllegalArgumentException: Cannot measure distance between world and plot
        at org.bukkit.Location.distanceSquared(Location.java:448) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.Location.distance(Location.java:431) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at me.cheesepro.ce.extra.PetAPI$1.run(PetAPI.java:59) ~[?:?]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:600) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    PetAPI.java:59
    Code:
    int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(pet.getLocation());
    It will be so nice of you if you include that feature! It is a GREAT API :D
     
  3. Offline

    Jaaakee224

    @matanrak
    Does this work with flying mobs such as a blaze or bat?
     
  4. Offline

    Cheesepro

    @matanrak
    I added world teleport and player logout feature to your API to prevent errors :D

    Code:
        public void petFollow(final Player player , final Entity pet , final double speed){
            new BukkitRunnable(){
                @SuppressWarnings("deprecation")
                public void run(){
                    if ((!pet.isValid() || (!player.isOnline()))){
                        this.cancel();
                    }
                    net.minecraft.server.v1_7_R4.Entity pett = ((CraftEntity) pet).getHandle();
                    Object petf = ((CraftEntity) pet).getHandle();
                    Location targetLocation = player.getLocation();
                    PathEntity path;
                    path = ((EntityInsentient) petf).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
                    if (path != null) {
                        ((EntityInsentient) petf).getNavigation().a(path, 1.0D);
                        ((EntityInsentient) petf).getNavigation().a(2.0D);
                    }
                    if(player.getWorld().getName().equalsIgnoreCase(pet.getWorld().getName()) ){
                        if(!player.isOnline()){
                            pet.remove();
                        }else{
                            distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(pet.getLocation());
                            if (distance > 10 && !pet.isDead() && player.isOnGround()) {
                                pet.teleport(player.getLocation());
                            }
                        }
                    }else{
                        if(!player.isOnline()){
                            pet.remove();
                        }else{
                            pet.teleport(player);
                        }
                    }
                    AttributeInstance attributes = ((EntityInsentient)((CraftEntity)pet).getHandle()).getAttributeInstance(GenericAttributes.d);
                    attributes.setValue(speed);
                }}.runTaskTimer(plugin, 0L, 20L);}
     
  5. Offline

    matanrak

    No, but i am working on a version that will work for them to!

    My full code had pet teleport with a distance :D
    Btw if you want you can add this:
    Code:
    if (pet.getLocation().getBlockY() - player.getLocation().getBlockY() > 2 || pet.getLocation().getBlockY() - player.getLocation().getBlockY() < -2 && player.isOnGround() ) {
    pet.teleport(player.getLocation());}
    
    it will make sure that if the "Y" distance between the owner and the pet cant be over 2 blocks

    If you need any help just comment on this post!
    sorry i haven't been online much but i was buys, i will be on a lot more now!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  6. Offline

    Jaaakee224

    Last edited by a moderator: Jul 8, 2015
  7. Offline

    Cheesepro

    @matanrak
    It will be very useful if you add a option which you can remove the pet :D
     
  8. Offline

    TheMintyMate

    Actually, Spigot have recently released their version of Bukkit 1.8 and CraftBukkit 1.8 - which though wasn't produced by Bukkit developers, it functions exactly the same. For this reason, I am more than happy to say that this is a good resource, and that I like how recent resources and library's are providing 1.8 versions. Peace.

    - Minty
     
  9. Offline

    Jaaakee224

    This was already stated.
     
  10. Offline

    AdamQpzm

    @TheMintyMate No matter how many people say it, it's still not true. Spigot's "Bukkit" release IS NOT Bukkit. Bukkit cannot be released by anyone other than the Bukkit team, and the Spigot team is not the Bukkit team. And you're wrong - it does not function exactly like Bukkit. One thing it does, for instance, is allows 1.8 clients to connect. Bukkit does not do this. Ergo, it cannot possibly be considered "exactly the same".
     
  11. Offline

    TheMintyMate

    Um, yeah... it's 1.8 CraftBukkit/Bukkit - of course it is going to allow 1.8 clients to connect... *facepalm* And yeah, I did state that it wasn't created by the Bukkit developers, but after using it to continue developement of my private plugin, I have found it to function exactly like Bukkit's last release (just with a few 1.8 additions - obviously).
     
  12. Offline

    AdamQpzm

    @TheMintyMate Nevertheless, it's still not "Bukkit" just because someone wanted to call it that. There's a very big difference between "Bukkit" and "a fork of Bukkit".
     
  13. Offline

    TheMintyMate

    @AdamQpzm
    Take this up with Spigot if it is such an issue. Yes, I'm aware that it isn't "Bukkit". I have said that all along. I have just been purely saying that It 'functions' exactly 'like' the last Bukkit release (1.7.....)

    I'm not going to make another comment on this subject, as it is not related to this thread, and therefore not really helping matanrak

    - Minty
     
  14. Offline

    AdamQpzm

    @TheMintyMate I wasn't saying it was an issue (as I've said before, despite its legal and technical issues), I was simply saying (at the time) that resources dedicated to Spigot-made software should be on Spigot's site, not Bukkit's site. That doesn't sound too unreasonable, does it?
     
  15. Offline

    matanrak

    just kill it.
    with pet.remove()
     
  16. Offline

    Cheesepro

    @matanrak
    I know that and I am killing it when the player logout, but pet.remove() does not work outside the method right? for instance if I made a command /pet remove how can I remove the pet in the onCommand() section?
     
  17. Offline

    Skionz

    @Cheesepro pet.remove()? You need the instance though, so just store it somewhere.
     
  18. Offline

    Jaaakee224

    Use a HashMap to get the player's pet and remove it.
     
  19. Offline

    matanrak

    i use hash maps to store pets, but in my following code as its a runnable i test if the player is online and if he is not then i kill the pet and stop the task
     
  20. Offline

    SeaniePlays

    @matanrak Thank you for the great resource works perfectly :D, Just to let you know it said that the method "has a constructor name" so i just changed the method name and it got rid of the message ;)
     
    matanrak likes this.
  21. Offline

    coco5843

    Are you able to make hostile mob to friendly ?
     
  22. Offline

    matanrak

    Yeah! Just cancel the mob target event for pets!

    Thanks! I wanted a following code for a long time and when I found it a year ago I had so much fun with making it better and better and playing around with pets, so i tought more people can ejoy using it!
    Thanks and have a lovely day!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  23. Offline

    coco5843

    I managed to made my own :)
     
  24. Offline

    coco5843

    Code:
    11:57:48 WARN]: net.minecraft.server.v1_7_R4.ReportedException: Saving entity NBT
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.e(Entity.java:1143)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.d(Entity.java:1091)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkRegionLoader.a(ChunkRegionLoader.java:258)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkRegionLoader.a(ChunkRegionLoader.java:141)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkProviderServer.saveChunk(ChunkProviderServer.java:252)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkProviderServer.saveChunks(ChunkProviderServer.java:314)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.WorldServer.save(WorldServer.java:804)
    [11:57:48 WARN]: at org.bukkit.craftbukkit.v1_7_R4.CraftWorld.save(CraftWorld.java:695)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:608)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)
    [11:57:48 WARN]: Caused by: java.lang.NullPointerException
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MerchantRecipe.i(MerchantRecipe.java:91)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MerchantRecipeList.a(MerchantRecipeList.java:90)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.EntityVillager.b(SourceFile:166)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.e(Entity.java:1130)
    [11:57:48 WARN]: ... 10 more
    [11:57:48 WARN]: net.minecraft.server.v1_7_R4.ReportedException: Saving entity NBT
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.e(Entity.java:1143)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.d(Entity.java:1091)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkRegionLoader.a(ChunkRegionLoader.java:258)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkRegionLoader.a(ChunkRegionLoader.java:141)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkProviderServer.saveChunk(ChunkProviderServer.java:252)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ChunkProviderServer.saveChunks(ChunkProviderServer.java:314)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.WorldServer.save(WorldServer.java:804)
    [11:57:48 WARN]: at org.bukkit.craftbukkit.v1_7_R4.CraftWorld.save(CraftWorld.java:695)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:608)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)
    [11:57:48 WARN]: Caused by: java.lang.NullPointerException
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MerchantRecipe.i(MerchantRecipe.java:91)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.MerchantRecipeList.a(MerchantRecipeList.java:90)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.EntityVillager.b(SourceFile:166)
    [11:57:48 WARN]: at net.minecraft.server.v1_7_R4.Entity.e(Entity.java:1130)
     
  25. Offline

    matanrak

    Try to run spigot
     
  26. Offline

    coco5843

    it was spigot :)
     
  27. Offline

    NonameSL

    Looks very nice, just a reminder that method names need to be in lower camel case, justLikeThis.
    Instead of PetFollow you should name it petFollow.
    For everyone arguing about craftbukkit 1.8: He just said that the same thing can be done by just changing the package name. But NOOO, all you guys had to create 100 replies just for someone to come and say this.
     
    matanrak likes this.
  28. Offline

    DuskFireHD

    @matanrak Hey do you know how it would be able to ride the mobs in 1.8 like with wasd and I have seen the other resource but I still cant get it to work
     
  29. Offline

    matanrak

Thread Status:
Not open for further replies.

Share This Page