Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.util.*;
- public class HumanBehaviourAI extends EntityMobs {
- public HumanBehaviourAI(World world) {
- super(world);
- randomSoundDelay = 0;
- texture = "/mob/char.png";
- moveSpeed = 0.5F;
- attackStrength = 4;
- setSize(1.0F, 1.0F);
- equippedItem = rand.nextInt(equippedItems.length);
- armorLevel = rand.nextInt(armorMap.size());
- health = 40;
- height = 1.8F;
- }
- public void onLivingUpdate() {
- attackStrength = 4 + equippedItem;
- if(swingArm)
- {
- swingTick++;
- if(swingTick == 8)
- {
- swingTick = 0;
- swingArm = false;
- }
- } else
- {
- swingTick = 0;
- }
- swingProgress = (float)swingTick / 8F;
- super.onLivingUpdate();
- }
- public void onUpdate()
- {
- moveSpeed = playerToAttack == null ? 0.5F : 0.95F;
- if(randomSoundDelay > 0 && --randomSoundDelay == 0)
- {
- worldObj.playSoundAtEntity(this, "mob.humanangry", getSoundVolume() * 2.0F, 1.0F);
- }
- super.onUpdate();
- }
- protected Entity findPlayerToAttack() {
- if(worldObj.difficultySetting > 2) {
- float f = getEntityBrightness(1.0F);
- if(f < 0.0F) {
- EntityPlayer entityplayer = worldObj.getClosestPlayerToEntity(this, attackRange);
- if(entityplayer != null) {
- return entityplayer;
- }
- }
- }
- if(rand.nextInt(5) == 0) {
- EntityLiving entityliving = getClosestTarget(this, 8D);
- if (entityliving != null) shareAngry(entityliving);
- return entityliving;
- }
- return null;
- }
- public int getMaxSpawnedInChunk() {
- return 3;
- }
- public EntityLiving getClosestTarget(Entity entity, double d) {
- double d1 = -1D;
- EntityLiving entityliving = null;
- List list = worldObj.getEntitiesWithinAABBExcludingEntity(entity, entity.boundingBox.expand(d,d,d));
- for(int i = 0; i < list.size(); i++) {
- Entity thisEntity = (Entity)list.get(i);
- if(!(thisEntity instanceof EntityLiving) ||
- //Ignore unless provoked
- thisEntity == entity ||
- thisEntity == entity.ridingEntity ||
- thisEntity == entity.riddenByEntity ||
- thisEntity instanceof EntityAnimals ||
- thisEntity instanceof EntitySquid ||
- thisEntity instanceof EntityPlayer)
- {
- continue;
- }
- double d2 = thisEntity.getDistanceSq(entity.posX, entity.posY, entity.posZ);
- if((d < 0.0D || d2 < d * d) && (d1 == -1D || d2 < d1) && ((EntityLiving)thisEntity).canEntityBeSeen(entity)) {
- d1 = d2;
- entityliving = (EntityLiving)thisEntity;
- }
- }
- return entityliving;
- }
- public boolean interact(EntityPlayer entityplayer) {
- return false;
- }
- public boolean attackEntityFrom(Entity entity, int i, EntityLiving thisent) {
- if ((i -= armorLevel) < 1) i = 1;
- swingArm = true;
- return super.attackEntityFrom(entity, i);
- }
- protected float getSoundVolume()
- {
- return 0.4F;
- }
- @SuppressWarnings("rawtypes")
- public void shareAngry(Entity entity) {
- List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
- for(int j = 0; j < list.size(); j++) {
- Entity thisEntity = (Entity)list.get(j);
- if(thisEntity instanceof HumanBehaviourAI) {
- HumanBehaviourAI entityhuman = (HumanBehaviourAI)thisEntity;
- entityhuman.becomeAngryAt(entity);
- }
- }
- }
- public void writeEntityToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeEntityToNBT(nbttagcompound);
- }
- public void readEntityFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readEntityFromNBT(nbttagcompound);
- }
- private void becomeAngryAt(Entity entity) {
- if (playerToAttack == null || !playerToAttack.isEntityAlive()) {
- playerToAttack = entity;
- randomSoundDelay = rand.nextInt(40);
- }
- }
- protected float getBlockPathWeight(int i, int j, int k) {
- return 15F;
- }
- public ItemStack getHeldItem() {
- return equippedItems[equippedItem];
- }
- protected int getDropItemId() {
- return droppedItems[rand.nextInt(droppedItems.length)];
- }
- public ItemStack armorItemInSlot(int i) {
- ItemStack[] currentArmor = armorMap.get(Integer.valueOf(armorLevel));
- return currentArmor[i];
- }
- private final double attackRange = 16D;
- protected int randomSoundDelay;
- private int equippedItem;
- private int armorLevel;
- private static final ItemStack[] equippedItems;
- private static final Map<Integer, ItemStack[]> armorMap = new HashMap<Integer, ItemStack[]>();
- private static final int[] droppedItems;
- public String humanName = null;
- public boolean swingArm = false;
- public int swingTick = 0;
- static {
- equippedItems = new ItemStack[] {
- new ItemStack(Block.torchWood, 1),
- new ItemStack(Item.pickaxeStone, 1),
- new ItemStack(Item.hoeDiamond, 1),
- new ItemStack(Item.axeSteel, 1),
- new ItemStack(Item.swordSteel, 1),
- };
- droppedItems = new int[] {
- Item.appleRed.shiftedIndex,
- Item.ingotGold.shiftedIndex,
- Item.ingotIron.shiftedIndex
- };
- armorMap.put(Integer.valueOf(0), new ItemStack[] {
- null, null, null, null
- });
- armorMap.put(Integer.valueOf(1), new ItemStack[] {
- new ItemStack(Item.helmetLeather, 1),
- new ItemStack(Item.plateLeather),
- new ItemStack(Item.legsLeather, 1),
- new ItemStack(Item.bootsLeather, 1)
- });
- armorMap.put(Integer.valueOf(2), new ItemStack[] {
- new ItemStack(Item.helmetChain, 1),
- new ItemStack(Item.plateChain),
- new ItemStack(Item.legsChain, 1),
- new ItemStack(Item.bootsChain, 1)
- });
- armorMap.put(Integer.valueOf(3), new ItemStack[] {
- new ItemStack(Item.helmetGold, 1),
- new ItemStack(Item.plateGold),
- new ItemStack(Item.legsGold, 1),
- new ItemStack(Item.bootsGold, 1)
- });
- armorMap.put(Integer.valueOf(4), new ItemStack[] {
- new ItemStack(Item.helmetSteel, 1),
- new ItemStack(Item.plateSteel),
- new ItemStack(Item.legsSteel, 1),
- new ItemStack(Item.bootsSteel, 1)
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement