Solved Specify horse type spawned using EntityType.HORSE

Discussion in 'Plugin Development' started by jflory7, Jul 17, 2013.

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

    jflory7

    Hello Bukkit forums,

    I have been messing around with the new 1.6.2 features, and I wanted to code two commands that spawn a skeleton or zombie horse depending on the command. I've got all of the code down to where I can spawn a horse successfully, but I do not know how to specify the horse type to a skeleton or zombie horse. Is there a known way to do this yet? My code is as follows:
    Code:java
    1. p.getWorld().spawnEntity(location, EntityType.HORSE);


    Thanks!
     
  2. Offline

    ZeusAllMighty11

    You need to define the horse in a variable

    Code:
    Horse h = (Horse) p.getWorld().spawnEntity(location, EntityType.HORSE);
    h.blahblah()
    
     
  3. Offline

    autoit4you

    You cant do that with spawnEntity, but with spawn
     
  4. Offline

    jflory7

    TheGreenGamerHD
    This my full code now:
    Code:java
    1. public class Skeleton implements CommandExecutor
    2. {
    3. Main plugin;
    4. public Skeleton(Main plugin)
    5. {
    6. this.plugin = plugin;
    7. }
    8.  
    9. @Override
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    11. {
    12. // Make the letter 'p' a variable for the command sender (or the player).
    13. Player p = (Player) sender;
    14.  
    15. // If the player typed /twitter, then do the following...
    16. if (cmd.getName().equalsIgnoreCase("skeletonhorse"))
    17. {
    18. Location location = p.getLocation();
    19. Horse horse = (Horse) p.getWorld().spawnEntity(location, EntityType.HORSE);
    20. horse.4;
    21. p.sendMessage(ChatColor.GOLD + "Skeleton horse has been spawned.");
    22. Bukkit.broadcastMessage(ChatColor.GOLD + "A new mob has appeared at " + location);
    23.  
    24. // If this has happened, the function will return true.
    25. return true;
    26. }
    27. // If this hasn't happened, a value of false will be returned.
    28. return false;
    29. }
    30. }


    This is what console spat out at me when I ran the plugin:
    Code:
    17.07 02:57:05 [Server] INFO ... 15 more
    17.07 02:57:05 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    17.07 02:57:05 [Server] INFO at com.crystalcraftmc.darkhorse.Zombie.onCommand(Zombie.java:32)
    17.07 02:57:05 [Server] INFO Type mismatch: cannot convert from double to Horse
    17.07 02:57:05 [Server] INFO Syntax error on token "horse", AssignmentOperator expected after this token
    17.07 02:57:05 [Server] INFO Caused by: java.lang.Error: Unresolved compilation problems:
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:839)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:882)
    17.07 02:57:05 [Server] INFO at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:964)
    17.07 02:57:05 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
    17.07 02:57:05 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
    17.07 02:57:05 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    17.07 02:57:05 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'zombiehorse' in plugin DarkHorse v0.1b
    autoit4you
    How does one use that?

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

    autoit4you

    Code:
    Horse horse = (Horse) EntityType.HORSE.getEntityClass();
    horse.setVariant(Variant.SKELETON_HORSE);
    p.getWorld().spawn(loc, horse);
     
  6. Offline

    jflory7

    autoit4you
    Eclipse is throwing errors when I type that and I'm not sure why. Note that p = player. Here is the code I have:
    Code:java
    1. Location location = p.getLocation();
    2. Horse horse = (Horse) p.getWorld().spawn(location, EntityType.HORSE.getEntityClass());
    3. horse.setVariant(Variant.SKELETON_HORSE);
    4. p.getWorld().spawn(location, horse);


    It throws the error on the last line for "spawn(location, horse)".
    Code:
    The method spawn(Location, Class<T>) in the type World is not applicable for the arguments (Location, Horse)
     
  7. Offline

    molenzwiebel

    Code:java
    1.  
    2. Horse horse = (Horse) p.getWorld().spawnEntity(location, EntityType.HORSE);
    3. horse.setVariant(Variant.SKELETON_HORSE);
    4.  
     
  8. Offline

    Pawnguy7

    Normally I just do like so: (spawning mobs, that is)

    Code:java
    1.  
    2. Horse horse = (Horse) location.getWorld().spawnEntity(location, EntityType.HORSE);
    3. horse.setVariant(Variant.SKELETON_HORSE);
    4.  
     
  9. Offline

    molenzwiebel

    Beat ya :)
     
    Pawnguy7 likes this.
  10. Offline

    autoit4you

    try p.getWorld().spawn(loc, horse.class);
     
  11. Offline

    Pawnguy7

    molenzwiebel haha, so you did. I hadn't heard of a spawn method before this, though, so I will look into that.
     
  12. Offline

    jflory7

    molenzwiebel Pawnguy7
    I cut off the .getEntityClass now, thanks!

    autoit4you
    I tried doing that, and then it wanted me to create a horse.class file. The variable seems to be working, it's just the "spawn" part that is throwing this error:
    Code:
    The method spawn(Location, Class<T>) in the type World is not applicable for the arguments (Location, Horse)
     
  13. Offline

    molenzwiebel

    Do NOT use @autoit4you's code. It is completely wrong. Ours will work fine. Try it
     
  14. Offline

    jflory7

    molenzwiebel
    Ahh, okay, it works now! Thank you much for the help!
     
Thread Status:
Not open for further replies.

Share This Page