Advertisement
Guest User

PetZombie

a guest
Jul 14th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. package me.ErezCS.Hub.pets.types;
  2.  
  3. import java.lang.reflect.Field;
  4.  
  5. import org.bukkit.Bukkit;
  6.  
  7. import net.minecraft.server.v1_7_R3.EntityHuman;
  8. import net.minecraft.server.v1_7_R3.EntityLiving;
  9. import net.minecraft.server.v1_7_R3.EntityZombie;
  10. import net.minecraft.server.v1_7_R3.World;
  11.  
  12. public class PetZombie extends EntityZombie {
  13.  
  14. public PetZombie(World world) {
  15. super(world);
  16. // TODO Auto-generated constructor stub
  17. }
  18.  
  19. @Override
  20. public void e(float sideMot, float forMot) {
  21. if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
  22. super.e(sideMot, forMot);
  23. this.W = 0.5F; // Make sure the entity can walk over half slabs, instead of jumping
  24. return;
  25. }
  26.  
  27. this.lastYaw = this.yaw = this.passenger.yaw;
  28. this.pitch = this.passenger.pitch * 0.5F;
  29.  
  30. // Set the entity's pitch, yaw, head rotation etc.
  31. this.b(this.yaw, this.pitch); //[url]https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/Entity.java#L163-L166[/url]
  32. this.aO = this.aM = this.yaw;
  33.  
  34. this.W = 1.0F; // The custom entity will now automatically climb up 1 high blocks
  35.  
  36. sideMot = ((EntityLiving) this.passenger).bd * 0.5F;
  37. forMot = ((EntityLiving) this.passenger).be;
  38.  
  39. if (forMot <= 0.0F) {
  40. forMot *= 0.25F; // Make backwards slower
  41. }
  42. sideMot *= 0.75F; // Also make sideways slower
  43.  
  44. float speed = 0.2F; // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
  45. this.i(speed); // Apply the speed
  46. super.e(sideMot, forMot); // Apply the motion to the entity
  47.  
  48.  
  49. Field jump = null;
  50. try {
  51. jump = EntityLiving.class.getDeclaredField("bc");
  52. } catch (NoSuchFieldException e1) {
  53. // TODO Auto-generated catch block
  54. e1.printStackTrace();
  55. } catch (SecurityException e1) {
  56. // TODO Auto-generated catch block
  57. e1.printStackTrace();
  58. }
  59. jump.setAccessible(true);
  60.  
  61. if (jump != null && this.onGround) { // Wouldn't want it jumping while on the ground would we?
  62. try {
  63. if (jump.getBoolean(this.passenger)) {
  64. double jumpHeight = 0.5D;
  65. this.motY = jumpHeight; // Used all the time in NMS for entity jumping
  66. }
  67. } catch (IllegalAccessException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. }
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement