Advertisement
Guest User

Untitled

a guest
Jan 28th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. package me.xgal.mlg.cosmetics.mounts;
  2.  
  3. import java.lang.reflect.Field;
  4.  
  5. import net.minecraft.server.v1_8_R3.EntityHuman;
  6. import net.minecraft.server.v1_8_R3.EntityIronGolem;
  7. import net.minecraft.server.v1_8_R3.EntityLiving;
  8. import net.minecraft.server.v1_8_R3.MathHelper;
  9. import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
  10. import net.minecraft.server.v1_8_R3.World;
  11.  
  12. import org.bukkit.Location;
  13. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  14. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
  15. import org.bukkit.craftbukkit.v1_8_R3.util.UnsafeList;
  16. import org.bukkit.entity.IronGolem;
  17. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
  18.  
  19. public class IronGolemMount extends EntityIronGolem {
  20.  
  21. public IronGolemMount(World world) {
  22. super(world);
  23.  
  24. try {
  25. Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
  26. bField.setAccessible(true);
  27. Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
  28. cField.setAccessible(true);
  29.  
  30. bField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
  31. bField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
  32. cField.set(goalSelector, new UnsafeList<PathfinderGoalSelector>());
  33. cField.set(targetSelector, new UnsafeList<PathfinderGoalSelector>());
  34. } catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. @Override
  40. public void g(float sideMot, float forMot) {
  41. if (this.passenger != null && this.passenger instanceof EntityHuman) {
  42. this.lastYaw = this.yaw = this.passenger.yaw;
  43. this.pitch = this.passenger.pitch * 0.5F;
  44. this.setYawPitch(this.yaw, this.pitch);
  45. this.aI = this.aG = this.yaw;
  46. sideMot = ((EntityLiving) this.passenger).aZ * 0.3F;
  47. forMot = ((EntityLiving) this.passenger).ba;
  48. if (forMot <= 0.0F) {
  49. forMot *= 5.25F;
  50. }
  51.  
  52. Field jump = null;
  53. try {
  54. jump = EntityLiving.class.getDeclaredField("aY");
  55. } catch (NoSuchFieldException e1) {
  56. e1.printStackTrace();
  57. } catch (SecurityException e1) {
  58. e1.printStackTrace();
  59. }
  60. jump.setAccessible(true);
  61.  
  62. if (jump != null && this.onGround) {
  63. try {
  64. if (jump.getBoolean(this.passenger)) {
  65. double jumpHeight = 0.5D;
  66. this.motY = jumpHeight;
  67. }
  68. } catch (IllegalAccessException e) {
  69. e.printStackTrace();
  70. }
  71. }
  72.  
  73. this.S = 1.0F;
  74. this.aK = (float) (this.bh * 0.1F);
  75. if (!this.world.isClientSide) {
  76. this.j((int) 0.35F);
  77. super.g(sideMot, forMot);
  78. }
  79.  
  80. this.ay = this.az;// Some extra things
  81. double d0 = this.locX - this.lastX;
  82. double d1 = this.locZ - this.lastZ;
  83. float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
  84. if (f4 > 1.0F) {
  85. f4 = 1.0F;
  86. }
  87.  
  88. this.az += (f4 - this.az) * 0.4F;
  89. this.aA += this.az;
  90. } else {
  91. this.S = 0.5F;
  92. this.aK = 0.02F;
  93. super.g(sideMot, forMot);
  94. }
  95. }
  96.  
  97. public static IronGolem spawn(Location loc) {
  98. World mcWorld = (World) ((CraftWorld) loc.getWorld()).getHandle();
  99. final IronGolemMount customEnt = new IronGolemMount(mcWorld);
  100. customEnt.setLocation(loc.getX(), loc.getY(), loc.getZ(), (float) -179.1, (float) 1.7);
  101. ((CraftLivingEntity) customEnt.getBukkitEntity()).setRemoveWhenFarAway(false);
  102. mcWorld.addEntity(customEnt, SpawnReason.CUSTOM);
  103. return (IronGolem) customEnt.getBukkitEntity();
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement