Leash on zombies?

Discussion in 'Spigot Plugin Development' started by Nosmakos, May 26, 2016.

  1. Hey guys it is possible to leash a zombie? meaning if player is right click with leash to a zombie it will make the zombie have a leash like when doing it on a horse and if the zombie has a leash it will become something like a pet for the player?
     
  2. this is what i have tested so far

    Code (Text):
        @EventHandler
        public void onLeash(PlayerInteractEntityEvent event){
            System.out.print("touched");
            Zombie zombie = (Zombie) event.getRightClicked();
            Player p = event.getPlayer();
            if (!(p.getInventory().getItemInHand().getType() == Material.LEASH)){
                return;
            }else{
                zombie.setLeashHolder(p);
            }
        }
    its just making the leash to get dropped not making the zombie to get leash
     
  3. You have to flip your parameters around. instead of 'p.setLeashHolder(zombie)', do 'zombie.setLeashHolder(p);'.
     
  4. Don't do this. Instead use
    Code (Text):
    if (p.getInventory().getItemInHand().getType() != Material.LEASH) {
    return;
    }
    Also no need for the else, just put your code there.
     
    • Agree Agree x 1
  5. i did it like this
    Code (Text):
        @EventHandler
        public void onLeash(PlayerInteractEntityEvent event){
            System.out.print("touched");
            Zombie zombie = (Zombie) event.getRightClicked();
            Player p = event.getPlayer();
            if (p.getInventory().getItemInHand().getType() != Material.LEASH) {
                return;
            }
            zombie.setLeashHolder(p);
        }
    it keep throwing leash for no reason
     
  6. Could you elaborate?
     
  7. i tried
    Code (Text):
    zombie.setLeashHolder(p);
    but zombie throws a leash
    if i do
    Code (Text):
    p.setLeashHolder(zombie);
    it does nothing.
     
  8. What do mean by zombie throws a leash? Like the zombie literally throws a leash item onto the ground? Or are you getting some sort of error message?
     
  9. i don't get any error message its just throwing a leash on the ground lmao :D
     
  10. I think Minecraft doesn't allow you to leash unleashable entitys like players and zombies. If you really want to leash zombies, you have to find out where minecraft decides to throwing leash, and find a way to work around that. Alternativ you could try to use a invisible animal to work around the leash throwing.
     
  11. The Spigot API makes it out to seem like you can leash almost any mob though because it says you can leash any mob besides the few that it specifically says you can't. Might just take some messing around with, but it seems like it should be possible.
     
  12. but dropping leash this is weird lol
     
  13. I think it's the same code that handels the leash breaking, if the leash gets too long.
     
  14. yeah it seems like this! but im close to the zombie thought