Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.62 KB | None | 0 0
  1. import net.minecraft.server.v1_8_R3.*;
  2. import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
  3. import com.google.common.collect.Lists;
  4. import org.bukkit.craftbukkit.v1_8_R3.entity.CraftVillager;
  5.  
  6. import java.lang.reflect.Field;
  7. import java.util.List;
  8. import java.util.Random;
  9.  
  10. /**
  11. * Created by Tom on 15/08/2014.
  12. */
  13. public class RidableVillager extends EntityVillager {
  14.  
  15. private String[] villagernames = {"Jagger", "Kelsey", "Kelton", "Haylie", "Harlow", "Howard", "Wulffric", "Winfred", "Ashley", "Bailey", "Beckett", "Alfredo", "Alfred", "Adair", "Edgar", "ED", "Eadwig", "Edgaras", "Buckley", "Stanley", "Nuffley", "Mary", "Jeffry", "Rosaly", "Elliot", "Harry", "Sam", "Rosaline", "Tom", "Ivan", "Kevin", "Adam"};
  16.  
  17.  
  18. @SuppressWarnings("rawtypes")
  19. public RidableVillager(org.bukkit.World world) {
  20. super(((CraftWorld) world).getHandle());
  21.  
  22. List goalB = (List) getPrivateField("b", PathfinderGoalSelector.class, goalSelector);
  23. goalB.clear();
  24. List goalC = (List) getPrivateField("c", PathfinderGoalSelector.class, goalSelector);
  25. goalC.clear();
  26. List targetB = (List) getPrivateField("b", PathfinderGoalSelector.class, targetSelector);
  27. targetB.clear();
  28. List targetC = (List) getPrivateField("c", PathfinderGoalSelector.class, targetSelector);
  29. targetC.clear();
  30.  
  31. this.a(0.6F, 1.8F);
  32. ((Navigation)getNavigation()).b(true);
  33. ((Navigation)getNavigation()).a(true);
  34. this.goalSelector.a(0, new PathfinderGoalFloat(this));
  35. // this.goalSelector.a(1, new PathfinderGoalAvoidTarget(this, new EntityZom(this), 8.0F, 0.6D, 0.6D));
  36. this.goalSelector.a(1, new PathfinderGoalTradeWithPlayer(this));
  37. this.goalSelector.a(1, new PathfinderGoalLookAtTradingPlayer(this));
  38. this.goalSelector.a(2, new PathfinderGoalMoveIndoors(this));
  39. this.goalSelector.a(3, new PathfinderGoalRestrictOpenDoor(this));
  40. this.goalSelector.a(4, new PathfinderGoalOpenDoor(this, true));
  41. this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 0.6D));
  42. this.goalSelector.a(6, new PathfinderGoalMakeLove(this));
  43. this.goalSelector.a(8, new PathfinderGoalPlay(this, 0.32D));
  44. this.goalSelector.a(9, new PathfinderGoalInteract(this, EntityHuman.class, 3.0F, 1.0F));
  45. this.goalSelector.a(9, new PathfinderGoalInteract(this, EntityVillager.class, 5.0F, 0.02F));
  46. this.goalSelector.a(9, new PathfinderGoalRandomStroll(this, 0.6D));
  47. this.goalSelector.a(10, new PathfinderGoalLookAtPlayer(this, EntityInsentient.class, 8.0F));
  48. this.setCustomName(villagernames[new Random().nextInt(villagernames.length)]);
  49. this.setCustomNameVisible(true);
  50. }
  51.  
  52. public static Object getPrivateField(String fieldName, Class clazz, Object object) {
  53. Field field;
  54. Object o = null;
  55.  
  56. try {
  57. field = clazz.getDeclaredField(fieldName);
  58.  
  59. field.setAccessible(true);
  60.  
  61. o = field.get(object);
  62. } catch (NoSuchFieldException e) {
  63. e.printStackTrace();
  64. } catch (IllegalAccessException e) {
  65. e.printStackTrace();
  66. }
  67.  
  68. return o;
  69. }
  70.  
  71.  
  72. /* public void e(float f, float f1)
  73. {
  74. if (f > 1.0F) {
  75. makeSound("mob.horse.land", 0.4F, 1.0F);
  76. }
  77. int i = MathHelper.f((f * 0.5F - 3.0F) * f1);
  78. if (i > 0)
  79. {
  80. damageEntity(DamageSource.FALL, i);
  81. if (this.passenger != null) {
  82. this.passenger.damageEntity(DamageSource.FALL, i);
  83. }
  84. Block block = this.world.getType(new BlockPosition(this.locX, this.locY - 0.2D - this.lastYaw, this.locZ)).getBlock();
  85. if ((block.getMaterial() != Material.AIR) && (!R()))
  86. {
  87. StepSound stepsound = block.stepSound;
  88.  
  89. this.world.makeSound(this, stepsound.getStepSound(), stepsound.getVolume1() * 0.5F, stepsound.getVolume2() * 0.75F);
  90. }
  91. }
  92. } */
  93.  
  94. @Override
  95. public void g(float f, float f1) {
  96.  
  97.  
  98. if (this.passenger != null && this.passenger instanceof EntityLiving) {
  99. this.lastYaw = this.yaw = this.passenger.yaw;
  100. this.pitch = this.passenger.pitch * 0.5F;
  101. setYawPitch(this.yaw, this.pitch);
  102. this.aI = this.aG = this.yaw;
  103. f = ((EntityLiving) this.passenger).aZ* 0.5F;
  104. f1 = ((EntityLiving) this.passenger).ba;
  105. if (f1 <= 0.0F) {
  106. f1 *= 0.25F;
  107. }
  108.  
  109.  
  110. if (!this.world.isClientSide) {
  111. this.k((float) this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue());
  112. this.S = 1.0F;
  113. if (f1 <= 0.0F) {
  114. f1 *= 0.25F; // Make backwards slower
  115. }
  116. f *= 0.75F; // Also make sideways slower
  117.  
  118. float speed = 0.12F; // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
  119. this.k(speed); // Apply the speed
  120. super.g(f, f1);
  121. }
  122.  
  123. if (this.onGround) {
  124.  
  125. this.j(false);
  126. }
  127.  
  128. this.ay = this.az;
  129. double d0 = this.locX - this.lastX;
  130. double d1 = this.locZ - this.lastZ;
  131. float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
  132.  
  133. if (f4 > 1.0F) {
  134. f4 = 1.0F;
  135. }
  136.  
  137. this.az += (f4 - this.az) * 0.4F;
  138. this.aA+= this.az;
  139. } else {
  140. this.S = 0.5F;
  141. this.aK = 0.02F;
  142. // this.S = 1.0F;
  143.  
  144. if (f1 <= 0.0F) {
  145. f1 *= 0.25F; // Make backwards slower
  146. }
  147. f *= 0.75F; // Also make sideways slower
  148.  
  149. float speed = 0.12F; // 0.2 is the default entity speed. I made it slightly faster so that riding is better than walking
  150. this.k(speed); // Apply the speed
  151. super.g(f, f1);
  152. this.S = 1.0F;
  153. }
  154. }
  155.  
  156.  
  157.  
  158. /* @Override
  159. public void g(float f, float f1)
  160. {
  161. if ((this.passenger != null) && ((this.passenger instanceof EntityLiving)) && (cE()))
  162. {
  163. this.lastYaw = (this.yaw = this.passenger.yaw);
  164. this.pitch = (this.passenger.pitch * 0.5F);
  165. setYawPitch(this.yaw, this.pitch);
  166. this.aI = (this.aG = this.yaw);
  167. f = ((EntityLiving)this.passenger).aX * 0.5F;
  168. f1 = ((EntityLiving)this.passenger).aY;
  169. if (f1 <= 0.0F)
  170. {
  171. f1 *= 0.25F;
  172. this.bL = 0;
  173. }
  174. if ((this.onGround) && (this.bp == 0.0F) && (cx()) && (!this.bE))
  175. {
  176. f = 0.0F;
  177. f1 = 0.0F;
  178. }
  179. if ((this.bp > 0.0F) && (!ct()) && (this.onGround))
  180. {
  181. this.motY = (getJumpStrength() * this.bp);
  182. if (hasEffect(MobEffectList.JUMP)) {
  183. this.motY += (getEffect(MobEffectList.JUMP).getAmplifier() + 1) * 0.1F;
  184. }
  185. m(true);
  186. this.ai = true;
  187. if (f1 > 0.0F)
  188. {
  189. float f2 = MathHelper.sin(this.yaw * 3.141593F / 180.0F);
  190. float f3 = MathHelper.cos(this.yaw * 3.141593F / 180.0F);
  191.  
  192. this.motX += -0.4F * f2 * this.bp;
  193. this.motZ += 0.4F * f3 * this.bp;
  194. makeSound("mob.horse.jump", 0.4F, 1.0F);
  195. }
  196. this.bp = 0.0F;
  197. }
  198. this.S = 1.0F;
  199. this.aK = (bH() * 0.1F);
  200. if (!this.world.isStatic)
  201. {
  202. j((float)getAttributeInstance(GenericAttributes.d).getValue());
  203. super.g(f, f1);
  204. }
  205. if (this.onGround)
  206. {
  207. this.bp = 0.0F;
  208. m(false);
  209. }
  210. this.ay = this.az;
  211. double d0 = this.locX - this.lastX;
  212. double d1 = this.locZ - this.lastZ;
  213. float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
  214. if (f4 > 1.0F) {
  215. f4 = 1.0F;
  216. }
  217. this.az += (f4 - this.az) * 0.4F;
  218. this.aA += this.az;
  219. }
  220. else
  221. {
  222. this.S = 0.5F;
  223. this.aK = 0.02F;
  224. super.g(f, f1);
  225. }
  226. }
  227. */
  228.  
  229.  
  230. @Override
  231. public EntityAgeable createChild(EntityAgeable entityAgeable) {
  232. return this.b(entityAgeable);
  233. }
  234.  
  235.  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement