[Tutorial] Creating custom entities with PathfinderGoals

Discussion in 'Spigot Plugin Development' started by XlordalX, May 11, 2014.

  1. Code (Text):
      public static void spawnEntity(Entity entity, Location loc)
       {
         entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
         ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
       }
    The method setLocation() is undefined for the type Entity!
     
    • Optimistic Optimistic x 1
  2. add the complete source?
     
    • Optimistic Optimistic x 1
  3. Are you using the Bukkit Entity?
     
  4. Code (Java):
    ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
    Doubt he is.

    @MrGriefer_HGamer the method you are looking for is setPositionRotation, if memory serves me right.
     
  5. @XlordalX Yes! I am using Bukkit Entity!

    @DarkSeraphim Also setPositionRotation is undefined.

    Maybe because I am using CraftBukkit as my Build Path and I should be using Spigot?

    EDIT: The method setLocation and setPositionRotation is undefined in Spigot!
     
  6. You have to use an NMS entity.
     
  7. Ok! I have a few questions:
    1- I am trying to make a custom Pig and I don't want player to hurt the Pig, how do i make that?

    2- I don't want the Pig to move, how can i make?

    3- Is there a way to make the Pig unpushable, which means no players can push the Pig. If there was a way then how?

    If there is already Pathfinder Goal for all 3 and what are they.

    If there wasn't then how to i make them?

    Thank you!
    Sorry for my bad English!
     
  8. I created a command to spawn 3 entities using this tut, there are no errors or anything. They just don't spawn?
     
  9. For 1, listen to entity damagebyentityevent ad see if it's ur custom pig being damaged by a player, if it is then cancel the event.
    2, to make it not move just clear all pathfinder goals... It states that in he tutorial.
     
  10. So I was able to use this tutorial perfectly with no issues when making a custom villager. I then tried it with a custom sheep but when I leave the chunk/go far away, it despawns. I have setRemoveWhenFarAway(False) in the code. I believe it is a plugin interfering but I am not 100% positive. Regular sheeps that are named are not removed.
     
    • Create a class which extends EntityPig
    • Override the damageEntity method(DamageCause, float), let it do nothing
    • Override g(double, double, double), let it do nothing.
     
  11. I love you man! You saved muy life ;*
     
  12. Nice tutorial it helped me out :p
     
  13. Hey ! Nice tutorial ;)

    I have a question , how could i make the entity fly when the player is flying ? I know thats possible but i don't know how , I tried to change de motY value in method g(float f, float f1) but it moves constantly to the top :c

    Thanks :D

    EDIT: Ok i've make the entity fly , but it is too slow :c

    EDIT: Nevermind i found how to ! It's the aM varibale :)

    Example:
    this.aM = 0.3F;
     
    #94 Seveningful, Jun 21, 2015
    Last edited: Jun 27, 2015
  14. Will this remove the normal zombie entity?
     
  15. Depends on which maps you override.
     
  16. SO if I follow this tut exactly, I will have my custom zombie, and also the old one?
     
  17. Yes.
     
  18. Hey @XlordalX ,

    Great and very useful tutorial! Many thanks for that. However, I have one question. Have you made this tutorial?
    Or maybe you have some code fragments of that?

    Thanks.
     
  19. @GodPlay
    Just use the method to check if the entity's location is on or near the location.

    You can use the distance method (using the distance formula) to check if the entity is this amount away from the location.
    There are tons of ways for checking if the entity is on or near the specified location. Just check if such is false, if so then return true, that way the other method will be run to get the entity moving back to that location