Ride NMS giants in 1.11

Discussion in 'Plugin Development' started by RithikVaderX3, May 26, 2017.

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

    RithikVaderX3

    I am making a plugin to ride a custom giant and control it. I can register and spawn the giant, but I cannot ride it.
    Here's the code I use to spawn and ride the giant:
    Code:java
    1.  
    2. [SIZE=16px]Location playerLocation = player.getLocation();[/SIZE]
    3. World mcWorld = (World) ((CraftWorld) playerLocation.getWorld()).getHandle();
    4. RegEntity Entities = new RegEntity();
    5. CustomEntityGiant myGiant = new CustomEntityGiant(mcWorld);
    6. int myGiantId = Entities.createNewEntity("MyGiant", 53, EntityType.GIANT, EntityGiantZombie.class, CustomEntityGiant.class);
    7. Entities.registerEntity(myGiantId);
    8. myGiant.spawn(playerLocation);
    9. CraftPlayer playerconv = ((CraftPlayer)player).getHandle().getBukkitEntity();
    10. Entity playerEntity = playerconv.getHandle();
    11. myGiant.passengers.set(0, playerEntity);
    12. PacketPlayOutMount packet = new PacketPlayOutMount(((CraftPlayer)player).getHandle());
    13. ((CraftPlayer)player).getHandle().playerConnection.sendPacket(packet);
    14. [SIZE=16px][/SIZE]

    Here is my CustomEntityGiant class:
    Code:java
    1.  
    2. public class CustomEntityGiant extends EntityGiantZombie
    3. {
    4. public CustomEntityGiant(World world)
    5. {
    6. super(world);
    7. }
    8. protected void initAttributes()
    9. {
    10. super.initAttributes();
    11. this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(10.0D);
    12. this.getAttributeInstance(GenericAttributes.maxHealth).setValue(500.0D);
    13. this.setCustomName(ChatColor.GOLD + "Test Giant");
    14. this.setCustomNameVisible(true);
    15. this.setInvisible(false);
    16.  
    17. }
    18. @Override
    19. public void g(float sideMot, float forMot)
    20. {
    21. {
    22. EntityLiving passenger = (EntityLiving) this.passengers.get(0);
    23. this.yaw = passenger.yaw;
    24. this.lastYaw = this.yaw;
    25. this.pitch = (passenger.pitch * 0.5F);
    26. setYawPitch(this.yaw, this.pitch);
    27. this.aN = this.yaw;
    28. this.aP = this.aN;
    29.  
    30. Float speedMultiplier = 3F; //Here you can set the speed
    31. sideMot = passenger.be * speedMultiplier;
    32. forMot = passenger.bf * speedMultiplier;
    33. if(forMot <= 0.0F)
    34. {
    35. forMot *= 0.25F;// Make backwards slower
    36. }
    37. Field jump = null; //Jumping
    38. try
    39. {
    40. jump = EntityLiving.class.getDeclaredField("bd");
    41. }
    42. {
    43. e1.printStackTrace();
    44. }
    45. catch (SecurityException e1)
    46. {
    47. e1.printStackTrace();
    48. }
    49. jump.setAccessible(true);
    50.  
    51. if (jump != null && this.onGround)
    52. { // Wouldn't want it jumping while on the ground would we?
    53. try
    54. {
    55. if (jump.getBoolean(passenger))
    56. {
    57. double jumpHeight = 0.5D; //Here you can set the jumpHeight
    58. this.motY = jumpHeight; // Used all the time in NMS for entity jumping
    59. }
    60. }
    61. {
    62. e.printStackTrace();
    63. }
    64. }
    65. super.g(sideMot, forMot);
    66. }
    67. }
    68. protected Item getLoot()
    69. {
    70. return Items.ROTTEN_FLESH;
    71. }
    72. public Monster spawn(Location location)
    73. {
    74. World mcWorld = (World) ((CraftWorld) location.getWorld()).getHandle();
    75. final CustomEntityGiant spawnedGiant = new CustomEntityGiant(mcWorld);
    76. spawnedGiant.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    77. ((CraftLivingEntity) spawnedGiant.getBukkitEntity()).setRemoveWhenFarAway(true);
    78. mcWorld.addEntity(spawnedGiant, SpawnReason.CUSTOM);
    79. return ((Monster)spawnedGiant.getBukkitEntity());
    80. }
    81. }
    82.  

    I tested it with try and catch blocks and got java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 exception while trying to access the list passengers for the giant.
    Can you not ride a giant or did I do something wrong?
     
    Last edited: May 27, 2017
  2. Offline

    timtower Administrator Administrator Moderator

    @RithikVaderX3 Check if there are passengers before you get them.
     
  3. Offline

    RithikVaderX3

    Well, the problem is the size of the list passengers is 0. I get the indexOutOfBounds exception. I will try adding an element to the list
     
  4. Offline

    timtower Administrator Administrator Moderator

    @RithikVaderX3 You should not add an element, you should check IF there is one.
     
  5. Offline

    RithikVaderX3

    Okay, so I checked the list and the size of the list is 0, myGiant.isVehicle() returns false and player.startRiding(myGiant) doesn't work either. Did I register the giant properly to make it rideable or did I mess something up?

    Is it even possible to ride a Giant in Bukkit 1.11.2?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: May 26, 2017
  6. Offline

    Zombie_Striker

    @RithikVaderX3
    Although you can make all entities ridable, because of obfuscation, the method name may have changed. That means you need to figure out what the new name for the method is. I would recommend, if you are using an IDE, pressing CRTL+SPACE to see all the methods and their constructors. What you are looking for is a method that requires two floats. Once you find it, move all the code from G into that method.
     
    RithikVaderX3 likes this.
  7. Offline

    RithikVaderX3

    Alright, I tried the method 'e'. It gave me the same error.
    I tried removing the myGiant.passengers.set(0, playerEntity); line from main and tried with the 'g' method. It spammed the console with the outOfBounds exception this time. Something really weird is going on.
    @Zombie_Striker

    EDIT: I just decompiled EntityHorse.class and I didn't find ANY code similar to the g or e methods that would be used in 1.8 or 1.7. So the code has probably changed significantly somewhere else and I don't think overriding a method would work. Any solutions?
     
    Last edited: May 27, 2017
  8. Offline

    MrGriefer_

    If your using 1.11 override method:
    PHP:
    @Override
    public void g(float sideMotfloat forMot
    Then, check to see if the passenger is a human. After that paste the code from EntityHorse!
     
  9. Offline

    RithikVaderX3

    I guess there's no solution yet. I will just make the plugin for 1.8 RO-1
     
  10. Offline

    MrGriefer_

    If your question is how to make the player ride the Giant, then, use:
    PHP:
    ((CraftLivingEntitycustomEntity.getBukkitEntity)).setPassenger(player);
     
  11. Offline

    RithikVaderX3

    @MrGriefer_ That works maybe like 1 in 10 times, but I still can't use wasd to move the entity.
     
Thread Status:
Not open for further replies.

Share This Page