BiomesOPlenty/common/biomesoplenty/entities/EntityBird.java

113 lines
3.4 KiB
Java
Raw Normal View History

2013-11-08 03:16:32 +00:00
package biomesoplenty.entities;
import biomesoplenty.api.Items;
2013-11-08 10:09:13 +00:00
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2013-11-08 03:16:32 +00:00
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class EntityBird extends EntityFlyingMob
{
public int courseChangeCooldown;
public double waypointX;
public double waypointY;
public double waypointZ;
public EntityBird(World world)
{
super(world);
this.setSize(1.0F, 1.0F);
}
@Override
protected void updateEntityActionState()
{
double d0 = this.waypointX - this.posX;
double d1 = this.waypointY - this.posY;
double d2 = this.waypointZ - this.posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
if (d3 < 1.0D || d3 > 3600.0D)
{
2013-11-08 05:50:23 +00:00
this.waypointX = this.posX + (double)((this.rand.nextFloat() * 8.0F - 4.0F) * 6.0F);
this.waypointY = this.posY + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 6.0F);
this.waypointZ = this.posZ + (double)((this.rand.nextFloat() * 8.0F - 4.0F) * 6.0F);
2013-11-08 03:16:32 +00:00
}
if (this.courseChangeCooldown-- <= 0)
{
this.courseChangeCooldown += this.rand.nextInt(2) + 2;
d3 = (double)MathHelper.sqrt_double(d3);
if (this.isCourseTraversable(this.waypointX, this.waypointY, this.waypointZ, d3))
{
this.motionX += d0 / d3 * 0.1D;
this.motionY += d1 / d3 * 0.1D;
this.motionZ += d2 / d3 * 0.1D;
}
else
{
this.waypointX = this.posX;
this.waypointY = this.posY;
this.waypointZ = this.posZ;
}
}
this.renderYawOffset = this.rotationYaw = -((float)Math.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI;
}
private boolean isCourseTraversable(double par1, double par3, double par5, double par7)
{
double d4 = (this.waypointX - this.posX) / par7;
double d5 = (this.waypointY - this.posY) / par7;
double d6 = (this.waypointZ - this.posZ) / par7;
AxisAlignedBB axisalignedbb = this.boundingBox.copy();
for (int i = 1; (double)i < par7; ++i)
{
axisalignedbb.offset(d4, d5, d6);
2013-11-08 10:09:13 +00:00
if (!this.worldObj.getCollidingBoundingBoxes(this, axisalignedbb).isEmpty()
|| this.isInWater() ?
this.worldObj.getBlockMaterial(MathHelper.floor_double(this.waypointX), MathHelper.floor_double(this.waypointY), MathHelper.floor_double(this.waypointZ)) == Material.water
: this.worldObj.isAnyLiquid(axisalignedbb))
2013-11-08 03:16:32 +00:00
{
return false;
}
}
return true;
}
@Override
protected void dropFewItems(boolean par1, int par2)
{
int var3 = rand.nextInt(3) + rand.nextInt(1 + par2);
for (int var4 = 0; var4 < var3; ++var4)
{
this.entityDropItem(new ItemStack(Item.feather, 1, 1), 0.0F);
}
}
2013-11-08 03:16:32 +00:00
@Override
protected String getLivingSound()
{
2013-11-08 09:11:51 +00:00
return "biomesoplenty:mob.bird.say";
2013-11-08 03:16:32 +00:00
}
@Override
protected String getHurtSound()
{
2013-11-08 09:11:51 +00:00
return "biomesoplenty:mob.bird.hurt";
2013-11-08 03:16:32 +00:00
}
@Override
protected String getDeathSound()
{
2013-11-08 09:11:51 +00:00
return "biomesoplenty:mob.bird.hurt";
2013-11-08 03:16:32 +00:00
}
}