Horse?

Discussion in 'Plugin Development' started by Nuno_Facha, Jul 5, 2015.

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

    Nuno_Facha

    How can i spawn and mount a player on a Horse in Java?
    I tried this but the player is not able to control the horse as if he mounted manualy ingame:
    Code:
            if (e.getPlayer().getName().equals("Esquilo_Azul")) {
                Horse h = (Horse) e.getPlayer().getLocation().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.HORSE);
                h.setCustomName("§cCavalinho do Diego");
                h.setCustomNameVisible(true);
                h.setTamed(true);
                h.getInventory().setSaddle(new ItemStack(Material.SADDLE));
                h.setOwner(e.getPlayer());
                h.setPassenger(e.getPlayer());
            }
     
  2. Offline

    Zombie_Striker

    @Nuno_Facha
    What is the current result of your code? Does the horse spawn with the saddle?
     
  3. Offline

    Nuno_Facha

    Code:
    Code:
    ~           Horse h = (Horse) e.getPlayer().getLocation().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.HORSE);
                h.setCustomName("§cCavalinho do Diego");
                h.setCustomNameVisible(true);
                h.setTamed(true);
                h.getInventory().setSaddle(new ItemStack(Material.SADDLE));
                h.setOwner(e.getPlayer());
                h.setPassenger(e.getPlayer());
                e.getPlayer().sendMessage("Chegou seu cavalinho!");
            }
    The player spawns but it it is not controlable like if it was right clicked
     
  4. Offline

    Zombie_Striker

    @Nuno_Facha
    Here are some basic tests you should do :
    1. When some command is sent (command "/test123"), the player will receive messages about the entity they are riding (casting that entity to a horse). Make this command and print out if A) it is tamed, B) registers that it has a saddle on, C) is owned and, D) has a passenger.
    2. Remove first the lines that are "unnecessary" (custom names, messages) and see if that fixes anything
    3. Re-Work your code. Move lines around. Maybe the saddle show be put on before the owner is set/ the player may have to be on the horse before owner/tamed is set.
     
Thread Status:
Not open for further replies.

Share This Page