Entity Speed???

Discussion in 'Plugin Development' started by jdawgerj515, Jul 10, 2013.

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

    jdawgerj515

    So I was looking at the changes of Build 2811 in the docs and saw that they had added an API for horses.

    What I didn't see in the API was a way to get and set the Horse speed. Since horses have different speeds. I was wondering if this was already implemented and if so how do you do it. I am guessing using Vectors would be bad in this situation since that can be choppy (tick-wise) from what I have seen.

    And I trying not to use PotionEffects, before someone recommends that.

    Bump

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

    jdawgerj515

  3. Offline

    jdawgerj515

    BorisTheTerrible
    I'll try that out, I find it strange they didn't add something like Horse speed to the API for horses, if they did it would be similar to getMaxSpeed for MineCarts would it not?
     
  4. jdawgerj515 Minecart is a different type of entity then a horse. But the documentation for bukkit currently doesn't show anything about horses that I can find so they may or may not have a way to change a horses speed.
     
  5. Offline

    Chinwe

  6. i was about to say that. Just wait for the API for the attributes comes out so you won't have to do NMS stuff, things will be much easier then!

    altought it will not work for minecarts. For minecarts, i would look into changing the booster track stuff. But i don't think you can get the cart to move faster at some point, but it will techinically never stop.
     
  7. Here is what you need and more

    Though it should be noted that the code is accessing native minecraft code and due craftbukkit changing package name to intentionally break every plugin that does so. you will have to update the packages and you might also have to update cHorse.getHandle().b(compound); When a new version of minecraft is out

    This code only contains getters, but you can just replace everywhere it says getXXXXXX(valueName) with set(valueName, newValue)

    Code:java
    1. public void printHorseInfo(Player player) {
    2. Entity vehicle = player.getVehicle();
    3. if(vehicle instanceof Horse){
    4. Horse horse = (Horse)vehicle;
    5. CraftHorse cHorse = (CraftHorse)horse;
    6. String horseName = horse.getCustomName();
    7. if(horseName == null){
    8. horseName = "not named";
    9. }
    10.  
    11. //NMS CODE, MIGHT BREAK EASYLY!!!!!!!!!!!!!!!!!!!!!
    12. NBTTagCompound compound = new NBTTagCompound();
    13. cHorse.getHandle().b(compound);
    14. //////////////////////////////////////////////////
    15.  
    16. int typeId = compound.getInt("Type");
    17. String typeName = null;
    18. switch(typeId){
    19. case 0:
    20. typeName = "Horse";
    21. break;
    22. case 1:
    23. typeName = "Donkey";
    24. break;
    25. case 2:
    26. typeName = "Mule";
    27. break;
    28. case 3:
    29. typeName = "Zombie";
    30. break;
    31. case 4:
    32. typeName = "Skeleton";
    33. break;
    34. }
    35.  
    36. String ownerName = compound.getString("OwnerName");
    37. if(ownerName == null){
    38. ownerName ="No owner";
    39. }
    40.  
    41. int temper = compound.getInt("Temper");
    42. boolean hasReproduced = compound.getBoolean("HasReproduced");
    43. boolean hasChest = compound.getBoolean("HasReproduced");
    44.  
    45. double jumpStrength = -1;
    46. double speed = -1;
    47.  
    48. NBTTagList list = compound.getList("Attributes");
    49. for(int i = 0; i < list.size() ; i++){
    50. NBTBase base = list.get(i);
    51. //id 10 means it is a NBTTagCompound
    52. if(base.getTypeId() == 10){
    53. NBTTagCompound attrCompound = (NBTTagCompound)base;
    54. //For same reason attrCompound.getName() always returns an empty string
    55. //so toString is used.
    56. if(base.toString().contains("horse.jumpStrength")){
    57. jumpStrength = attrCompound.getDouble("Base");
    58. } else if(base.toString().contains("generic.movementSpeed")){
    59. speed = attrCompound.getDouble("Base");
    60. }
    61. }
    62. }
    63. player.sendMessage(ChatColor.GREEN+"Horse Stats for \""+horseName+"\"");
    64. player.sendMessage(ChatColor.GREEN+"Type: "+ChatColor.BLUE+typeName);
    65. player.sendMessage(ChatColor.GREEN+"Tamed by: "+ChatColor.BLUE+ownerName);
    66. player.sendMessage(ChatColor.GREEN+"Age: "+ChatColor.BLUE+horse.getAge());
    67. player.sendMessage(ChatColor.GREEN+"Fully grown: "+ChatColor.BLUE+horse.isAdult());
    68. player.sendMessage(ChatColor.GREEN+"Max health: "+ChatColor.BLUE+format(horse.getMaxHealth()));
    69. player.sendMessage(ChatColor.GREEN+"Speed: "+ChatColor.BLUE+format(speed));
    70. player.sendMessage(ChatColor.GREEN+"Jump strength: "+ChatColor.BLUE+format(jumpStrength));
    71. player.sendMessage(ChatColor.GREEN+"Temper: "+ChatColor.BLUE+temper);
    72. player.sendMessage(ChatColor.GREEN+"Has chest: "+ChatColor.BLUE+hasChest);
    73. player.sendMessage(ChatColor.GREEN+"Has reproduced: "+ChatColor.BLUE+hasReproduced + " (Unused at the moment)");
    74. } else {
    75. player.sendMessage(ChatColor.RED + "You are not riding a horse, you are riding a "+vehicle);
    76. }
    77. }
    78.  
    79. public static String format(double number) {
    80. BigDecimal bd = new BigDecimal(number);
    81. bd = bd.setScale(2,BigDecimal.ROUND_DOWN);
    82. return bd.toPlainString();
    83. }


    EDIT*
    Found a more extensible API for modifiyng horses https://forums.bukkit.org/threads/util-horsemodifier-spawn-and-modify-horses.157358/
     
  8. Offline

    jdawgerj515

    mollekake
    I will do what you said and just wait for the Attribute API to come out. I wish they would just add it to the Horse API as well for relevancy.
     
  9. Offline

    Izbay

    I'm also (along with all of my plugin users) eagerly awaiting a way to get/set horse speed. I've seen no word on attributes yet.
     
  10. Offline

    jdawgerj515

    I'm guessing this isn't coming out till around 1.7

    I can wait : /
     
Thread Status:
Not open for further replies.

Share This Page