/moCreatures/server/.metadata/.plugins/org.eclipse.core.resources/.history/8c/b07facde0a8000101cbdd28cb20c0c30
https://code.google.com/p/minecraft-smp-mocreatures/ · #! · 449 lines · 416 code · 33 blank · 0 comment · 0 complexity · 748d4d081df21300830d3e0865b35f9d MD5 · raw file
- package net.minecraft.src;
- // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
- // Jad home page: http://www.kpdus.com/jad.html
- // Decompiler options: packimports(3) braces deadcode
-
- import java.util.List;
-
- import net.minecraft.src.AxisAlignedBB;
- import net.minecraft.src.Block;
- import net.minecraft.src.Entity;
- import net.minecraft.src.EntityAnimal;
- import net.minecraft.src.EntityItem;
- import net.minecraft.src.EntityLiving;
- import net.minecraft.src.Item;
- import net.minecraft.src.Material;
- import net.minecraft.src.MathHelper;
- import net.minecraft.src.NBTTagCompound;
- import net.minecraft.src.World;
- import net.minecraft.src.mod_MoCreatures;
-
- public class EntityBird extends EntityAnimal
- {
- private boolean hasReproduced;
- public int typeInt;
- public boolean typeChosen;
- private boolean fleeing;
- public float wingB;
- public float wingC;
- public float wingD;
- public float wingE;
- public float wingH;
- public boolean tamed;
- public static int counterEntity;
-
- public EntityBird(World world)
- {
- super(world);
- texture = "/mob/birdblue.png";
- setSize(0.5F, 0.3F);
- health = 2;
- isCollidedVertically = true;
- wingB = 0.0F;
- wingC = 0.0F;
- wingH = 1.0F;
- fleeing = false;
- tamed = false;
- typeInt = 0;
- typeChosen = false;
- hasReproduced = false;
- }
-
- protected void fall(float f)
- {
- }
-
- public int getMaxSpawnedInChunk()
- {
- return 6;
- }
-
- public void onLivingUpdate()
- {
- super.onLivingUpdate();
- wingE = wingB;
- wingD = wingC;
- wingC = (float)(wingC + (onGround ? -1 : 4) * 0.3D);
- if(wingC < 0.0F)
- wingC = 0.0F;
- if(wingC > 1.0F)
- wingC = 1.0F;
- if(!onGround && wingH < 1.0F)
- wingH = 1.0F;
- wingH = (float)(wingH * 0.9D);
- if(!onGround && motionY < 0.0D)
- motionY *= 0.8D;
- wingB += wingH * 2.0F;
- EntityLiving entityliving = getClosestEntityLiving(this, 4.0D);
- if(entityliving != null && !tamed && canEntityBeSeen(entityliving))
- fleeing = true;
- if(rand.nextInt(300) == 0)
- fleeing = true;
- if(fleeing)
- {
- if(flyToNextTree())
- fleeing = false;
- int ai[] = returnNearestMaterialCoord(this, Material.leaves, Double.valueOf(16.0D));
- if(ai[0] == -1)
- {
- for(int i = 0; i < 2; i++)
- wingFlap();
-
- fleeing = false;
- }
- if(rand.nextInt(50) == 0)
- fleeing = false;
- }
- if(!fleeing)
- {
- EntityItem entityitem = getClosestSeeds(this, 12.0D);
- if(entityitem != null)
- {
- flyToNextEntity(entityitem);
- EntityItem entityitem1 = getClosestSeeds(this, 1.0D);
- if(rand.nextInt(50) == 0 && entityitem1 != null)
- {
- entityitem1.setEntityDead();
- tamed = true;
- }
- }
- }
- }
-
- protected void updatePlayerActionState()
- {
- if(onGround && rand.nextInt(10) == 0 && (motionX > 0.05D || motionZ > 0.05D || motionX < -0.05D || motionZ < -0.05D))
- motionY = 0.25D;
- if(!fleeing)
- super.updatePlayerActionState();
- }
-
- public void setEntityDead()
- {
- if(!tamed || health <= 0)
- {
- counterEntity--;
- super.setEntityDead();
- }
- }
-
- @SuppressWarnings("unchecked")
- private EntityItem getClosestSeeds(Entity entity, double d)
- {
- double d1 = -1.0D;
- EntityItem entityitem = null;
- List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
- for(int i = 0; i < list.size(); i++)
- {
- Entity entity1 = list.get(i);
- if(!(entity1 instanceof EntityItem))
- continue;
- EntityItem entityitem1 = (EntityItem)entity1;
- if(entityitem1.item.itemID != Item.seeds.shiftedIndex)
- continue;
- double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
- if((d < 0.0D || d2 < d * d) && (d1 == -1.0D || d2 < d1))
- {
- d1 = d2;
- entityitem = entityitem1;
- }
- }
-
- return entityitem;
- }
-
- @SuppressWarnings("unchecked")
- private EntityLiving getClosestEntityLiving(Entity entity, double d)
- {
- double d1 = -1.0D;
- EntityLiving entityliving = null;
- List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
- for(int i = 0; i < list.size(); i++)
- {
- Entity entity1 = list.get(i);
- if(!(entity1 instanceof EntityLiving) || (entity1 instanceof EntityBird))
- continue;
- double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
- if((d < 0.0D || d2 < d * d) && (d1 == -1.0D || d2 < d1) && ((EntityLiving)entity1).canEntityBeSeen(entity))
- {
- d1 = d2;
- entityliving = (EntityLiving)entity1;
- }
- }
-
- return entityliving;
- }
-
- private boolean flyToNextEntity(Entity entity)
- {
- if(entity != null)
- {
- int i = MathHelper.floor_double(entity.posX);
- int j = MathHelper.floor_double(entity.posY);
- int k = MathHelper.floor_double(entity.posZ);
- faceTreeTop(i, j, k, 30.0F);
- if(MathHelper.floor_double(posY) < j)
- {
- motionY += 0.15D;
- }
- if(posX < entity.posX)
- {
- double d = entity.posX - posX;
- if(d > 0.5D)
- motionX += 0.05D;
- } else
- {
- double d1 = posX - entity.posX;
- if(d1 > 0.5D)
- motionX -= 0.05D;
- }
- if(posZ < entity.posZ)
- {
- double d2 = entity.posZ - posZ;
- if(d2 > 0.5D)
- motionZ += 0.05D;
- } else
- {
- double d3 = posZ - entity.posZ;
- if(d3 > 0.5D)
- motionZ -= 0.05D;
- }
- return true;
- }
- return false;
- }
-
- private void wingFlap()
- {
- motionY += 0.05D;
- if(rand.nextInt(30) == 0)
- motionX += 0.2D;
- if(rand.nextInt(30) == 0)
- motionX -= 0.2D;
- if(rand.nextInt(30) == 0)
- motionZ += 0.2D;
- if(rand.nextInt(30) == 0)
- motionZ -= 0.2D;
- }
-
- private boolean flyToNextTree()
- {
- int ai[] = returnNearestMaterialCoord(this, Material.leaves, Double.valueOf(20.0D));
- int ai1[] = findTreeTop(ai[0], ai[1], ai[2]);
- if(ai1[1] != 0)
- {
- int i = ai1[0];
- int j = ai1[1];
- int k = ai1[2];
- faceTreeTop(i, j, k, 30.0F);
- if(j - MathHelper.floor_double(posY) > 2)
- motionY += 0.15D;
- int l = 0;
- int i1 = 0;
- if(posX < i)
- {
- l = i - MathHelper.floor_double(posX);
- motionX += 0.05D;
- } else
- {
- l = MathHelper.floor_double(posX) - i;
- motionX -= 0.05D;
- }
- if(posZ < k)
- {
- i1 = k - MathHelper.floor_double(posZ);
- motionZ += 0.05D;
- } else
- {
- i1 = MathHelper.floor_double(posX) - k;
- motionZ -= 0.05D;
- }
- double d = l + i1;
- if(d < 3.0D)
- return true;
- }
- return false;
- }
-
- public void setType(int i)
- {
- typeInt = i;
- typeChosen = false;
- chooseType();
- }
-
- public void chooseType()
- {
- if(typeInt == 0)
- {
- int i = rand.nextInt(100);
- if(i <= 15)
- typeInt = 1;
- else if(i <= 30)
- typeInt = 2;
- else if(i <= 45)
- typeInt = 3;
- else if(i <= 60)
- typeInt = 4;
- else if(i <= 75)
- typeInt = 5;
- else if(i <= 90)
- typeInt = 6;
- else
- typeInt = 2;
- }
- if(!typeChosen)
- texture = new StringBuilder("/mob/").append(getLivingSound()).append(".png").toString();
- typeChosen = true;
- }
-
- public void faceTreeTop(int i, int j, int k, float f)
- {
- double d = i - posX;
- double d1 = k - posZ;
- double d2 = j - posY;
- double d3 = MathHelper.sqrt_double(d * d + d1 * d1);
- float f1 = (float)((Math.atan2(d1, d) * 180.0D) / Math.PI) - 90.0F;
- float f2 = (float)((Math.atan2(d2, d3) * 180.0D) / Math.PI);
- rotationPitch = -updateRotation(rotationPitch, f2, f);
- rotationYaw = updateRotation(rotationYaw, f1, f);
- }
-
- private float updateRotation(float f, float f1, float f2)
- {
- float f3 = f1;
- for(f3 = f1 - f; f3 < -180.0F; f3 += 360.0F);
- while (f3 >= 180.0F)
- f3 -= 360.0F;
- if(f3 > f2)
- f3 = f2;
- if(f3 < -f2)
- f3 = -f2;
- return f + f3;
- }
-
- private int[] findTreeTop(int i, int j, int k)
- {
- int l = i - 5;
- int i1 = k - 5;
- int j1 = i + 5;
- int k1 = j + 7;
- int l1 = k + 5;
- for(int i2 = l; i2 < j1; i2++)
- {
- for(int j2 = i1; j2 < l1; j2++)
- {
- int k2 = worldObj.getBlockId(i2, j, j2);
- if(k2 == 0 || Block.blocksList[k2].blockMaterial != Material.wood)
- continue;
- int l2 = j;
- while (l2 < k1)
- {
- int i3 = worldObj.getBlockId(i2, l2, j2);
- if(i3 == 0)
- return (new int[] { i2, l2 + 2, j2 });
- l2++;
- }
- }
-
- }
-
- return (new int[] { 0, 0, 0 });
- }
-
- public int[] returnNearestMaterialCoord(Entity entity, Material material, Double double1)
- {
- AxisAlignedBB axisalignedbb = entity.boundingBox.expand(double1.doubleValue(), double1.doubleValue(), double1.doubleValue());
- int i = MathHelper.floor_double(axisalignedbb.minX);
- int j = MathHelper.floor_double(axisalignedbb.maxX + 1.0D);
- int k = MathHelper.floor_double(axisalignedbb.minY);
- int l = MathHelper.floor_double(axisalignedbb.maxY + 1.0D);
- int i1 = MathHelper.floor_double(axisalignedbb.minZ);
- int j1 = MathHelper.floor_double(axisalignedbb.maxZ + 1.0D);
- for(int k1 = i; k1 < j; k1++)
- {
- for(int l1 = k; l1 < l; l1++)
- {
- for(int i2 = i1; i2 < j1; i2++)
- {
- int j2 = worldObj.getBlockId(k1, l1, i2);
- if(j2 != 0 && Block.blocksList[j2].blockMaterial == material)
- return (new int[] { k1, l1, i2 });
- }
- }
- }
-
- return (new int[] { -1, 0, 0 });
- }
-
- protected int getDropItemId()
- {
- if(rand.nextInt(2) == 0)
- return Item.feather.shiftedIndex;
- return Item.seeds.shiftedIndex;
- }
-
- public void writeEntityToNBT(NBTTagCompound nbttagcompound)
- {
- super.writeEntityToNBT(nbttagcompound);
- nbttagcompound.setInteger("TypeInt", typeInt);
- nbttagcompound.setBoolean("HasReproduced", hasReproduced);
- nbttagcompound.setBoolean("Tamed", tamed);
- nbttagcompound.setInteger("CounterEntity", counterEntity);
- }
-
- public void readEntityFromNBT(NBTTagCompound nbttagcompound)
- {
- super.readEntityFromNBT(nbttagcompound);
- hasReproduced = nbttagcompound.getBoolean("HasReproduced");
- tamed = nbttagcompound.getBoolean("Tamed");
- typeInt = nbttagcompound.getInteger("TypeInt");
- counterEntity = nbttagcompound.getInteger("CounterEntity");
- }
-
- protected String getLivingSound()
- {
- switch (typeInt)
- {
- case 1:
- return "birdwhite";
- case 2:
- return "birdblack";
- case 3:
- return "birdgreen";
- case 4:
- return "birdblue";
- case 5:
- return "birdyellow";
- default:
- case 6:
- return "birdred";
- }
- }
-
- protected String getHurtSound()
- {
- return "birdhurt";
- }
-
- protected String getDeathSound()
- {
- return "birddying";
- }
-
- public boolean getCanSpawnHere()
- {
- int i = MathHelper.floor_double(posX);
- int j = MathHelper.floor_double(boundingBox.minY);
- int k = MathHelper.floor_double(posZ);
- worldObj.getBlockId(i, j - 1, k);
- if(super.getCanSpawnHere())
- {
- if(counterEntity >= mod_MoCreatures.maxBirds)
- return false;
- counterEntity++;
- return true;
- }
- return false;
- }
- }