Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.*;
  4.  
  5. public class HumanBehaviourAI extends EntityMobs {
  6.  
  7. public HumanBehaviourAI(World world) {
  8. super(world);
  9. randomSoundDelay = 0;
  10. texture = "/mob/char.png";
  11. moveSpeed = 0.5F;
  12. attackStrength = 4;
  13. setSize(1.0F, 1.0F);
  14. equippedItem = rand.nextInt(equippedItems.length);
  15. armorLevel = rand.nextInt(armorMap.size());
  16. health = 40;
  17. height = 1.8F;
  18. }
  19.  
  20. public void onLivingUpdate() {
  21. attackStrength = 4 + equippedItem;
  22. if(swingArm)
  23. {
  24. swingTick++;
  25. if(swingTick == 8)
  26. {
  27. swingTick = 0;
  28. swingArm = false;
  29. }
  30. } else
  31. {
  32. swingTick = 0;
  33. }
  34. swingProgress = (float)swingTick / 8F;
  35. super.onLivingUpdate();
  36. }
  37.  
  38. public void onUpdate()
  39. {
  40. moveSpeed = playerToAttack == null ? 0.5F : 0.95F;
  41. if(randomSoundDelay > 0 && --randomSoundDelay == 0)
  42. {
  43. worldObj.playSoundAtEntity(this, "mob.humanangry", getSoundVolume() * 2.0F, 1.0F);
  44. }
  45. super.onUpdate();
  46. }
  47.  
  48.  
  49. protected Entity findPlayerToAttack() {
  50. if(worldObj.difficultySetting > 2) {
  51. float f = getEntityBrightness(1.0F);
  52. if(f < 0.0F) {
  53. EntityPlayer entityplayer = worldObj.getClosestPlayerToEntity(this, attackRange);
  54. if(entityplayer != null) {
  55. return entityplayer;
  56. }
  57. }
  58. }
  59. if(rand.nextInt(5) == 0) {
  60. EntityLiving entityliving = getClosestTarget(this, 8D);
  61. if (entityliving != null) shareAngry(entityliving);
  62. return entityliving;
  63. }
  64. return null;
  65. }
  66. public int getMaxSpawnedInChunk() {
  67. return 3;
  68. }
  69. public EntityLiving getClosestTarget(Entity entity, double d) {
  70. double d1 = -1D;
  71. EntityLiving entityliving = null;
  72. List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d,d,d));
  73. for(int i = 0; i < list.size(); i++) {
  74. Entity thisEntity = (Entity)list.get(i);
  75. if(!(thisEntity instanceof EntityLiving) ||
  76.  
  77. //Ignore unless provoked
  78. thisEntity == entity ||
  79. thisEntity == entity.ridingEntity ||
  80. thisEntity == entity.riddenByEntity ||
  81. thisEntity instanceof EntityAnimals ||
  82. thisEntity instanceof EntitySquid ||
  83. thisEntity instanceof EntityPlayer)
  84. {
  85. continue;
  86. }
  87. double d2 = thisEntity.getDistanceSq(entity.posX, entity.posY, entity.posZ);
  88. if((d < 0.0D || d2 < d * d) && (d1 == -1D || d2 < d1) && ((EntityLiving)thisEntity).canEntityBeSeen(entity)) {
  89. d1 = d2;
  90. entityliving = (EntityLiving)thisEntity;
  91. }
  92. }
  93. return entityliving;
  94. }
  95.  
  96. public boolean interact(EntityPlayer entityplayer) {
  97. return false;
  98. }
  99.  
  100.  
  101. public boolean attackEntityFrom(Entity entity, int i, EntityLiving thisent) {
  102. if ((i -= armorLevel) < 1) i = 1;
  103. swingArm = true;
  104. return super.attackEntityFrom(entity, i);
  105. }
  106. protected float getSoundVolume()
  107. {
  108. return 0.4F;
  109. }
  110.  
  111.  
  112. @SuppressWarnings("rawtypes")
  113. public void shareAngry(Entity entity) {
  114. List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
  115. for(int j = 0; j < list.size(); j++) {
  116. Entity thisEntity = (Entity)list.get(j);
  117. if(thisEntity instanceof HumanBehaviourAI) {
  118. HumanBehaviourAI entityhuman = (HumanBehaviourAI)thisEntity;
  119. entityhuman.becomeAngryAt(entity);
  120. }
  121. }
  122. }
  123.  
  124. public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  125. {
  126. super.writeEntityToNBT(nbttagcompound);
  127. }
  128.  
  129. public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  130. {
  131. super.readEntityFromNBT(nbttagcompound);
  132. }
  133.  
  134. private void becomeAngryAt(Entity entity) {
  135. if (playerToAttack == null || !playerToAttack.isEntityAlive()) {
  136. playerToAttack = entity;
  137. randomSoundDelay = rand.nextInt(40);
  138. }
  139. }
  140.  
  141. protected float getBlockPathWeight(int i, int j, int k) {
  142. return 15F;
  143. }
  144.  
  145. public ItemStack getHeldItem() {
  146. return equippedItems[equippedItem];
  147. }
  148.  
  149. protected int getDropItemId() {
  150. return droppedItems[rand.nextInt(droppedItems.length)];
  151. }
  152.  
  153. public ItemStack armorItemInSlot(int i) {
  154. ItemStack[] currentArmor = armorMap.get(Integer.valueOf(armorLevel));
  155. return currentArmor[i];
  156. }
  157.  
  158. private final double attackRange = 16D;
  159. protected int randomSoundDelay;
  160. private int equippedItem;
  161. private int armorLevel;
  162. private static final ItemStack[] equippedItems;
  163. private static final Map<Integer, ItemStack[]> armorMap = new HashMap<Integer, ItemStack[]>();
  164. private static final int[] droppedItems;
  165. public String humanName = null;
  166. public boolean swingArm = false;
  167. public int swingTick = 0;
  168.  
  169. static {
  170. equippedItems = new ItemStack[] {
  171. new ItemStack(Block.torchWood, 1),
  172. new ItemStack(Item.pickaxeStone, 1),
  173. new ItemStack(Item.hoeDiamond, 1),
  174. new ItemStack(Item.axeSteel, 1),
  175. new ItemStack(Item.swordSteel, 1),
  176. };
  177. droppedItems = new int[] {
  178. Item.appleRed.shiftedIndex,
  179. Item.ingotGold.shiftedIndex,
  180. Item.ingotIron.shiftedIndex
  181. };
  182. armorMap.put(Integer.valueOf(0), new ItemStack[] {
  183. null, null, null, null
  184. });
  185. armorMap.put(Integer.valueOf(1), new ItemStack[] {
  186. new ItemStack(Item.helmetLeather, 1),
  187. new ItemStack(Item.plateLeather),
  188. new ItemStack(Item.legsLeather, 1),
  189. new ItemStack(Item.bootsLeather, 1)
  190. });
  191. armorMap.put(Integer.valueOf(2), new ItemStack[] {
  192. new ItemStack(Item.helmetChain, 1),
  193. new ItemStack(Item.plateChain),
  194. new ItemStack(Item.legsChain, 1),
  195. new ItemStack(Item.bootsChain, 1)
  196. });
  197. armorMap.put(Integer.valueOf(3), new ItemStack[] {
  198. new ItemStack(Item.helmetGold, 1),
  199. new ItemStack(Item.plateGold),
  200. new ItemStack(Item.legsGold, 1),
  201. new ItemStack(Item.bootsGold, 1)
  202. });
  203. armorMap.put(Integer.valueOf(4), new ItemStack[] {
  204. new ItemStack(Item.helmetSteel, 1),
  205. new ItemStack(Item.plateSteel),
  206. new ItemStack(Item.legsSteel, 1),
  207. new ItemStack(Item.bootsSteel, 1)
  208. });
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement