BiomesOPlenty/common/biomesoplenty/entities/EntityWasp.java
2013-10-30 05:23:04 -04:00

154 lines
4.7 KiB
Java

package biomesoplenty.entities;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
public class EntityWasp extends EntityFlyingMob
{
public int courseChangeCooldown;
public double waypointX;
public double waypointY;
public double waypointZ;
private Entity targetedEntity;
/** Cooldown time between target loss and new target aquirement. */
private int aggroCooldown;
public EntityWasp(World world)
{
super(world);
this.setSize(1.0F, 1.0F);
}
@Override
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(2.5D);
}
@Override
protected void updateEntityActionState()
{
if (!this.worldObj.isRemote && this.worldObj.difficultySetting == 0)
{
this.setDead();
}
this.despawnEntity();
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)
{
this.waypointX = this.posX + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 4.0F);
this.waypointY = this.posY + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 4.0F);
this.waypointZ = this.posZ + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 4.0F);
}
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;
}
}
if (this.targetedEntity != null && this.targetedEntity.isDead)
{
this.targetedEntity = null;
}
if (this.targetedEntity == null || this.aggroCooldown-- <= 0)
{
this.targetedEntity = this.worldObj.getClosestVulnerablePlayerToEntity(this, 100.0D);
if (this.targetedEntity != null)
{
this.aggroCooldown = 20;
}
}
double d4 = 64.0D;
if (this.targetedEntity != null && this.targetedEntity.getDistanceSqToEntity(this) < d4 * d4)
{
double d5 = this.targetedEntity.posX - this.posX;
double d6 = this.targetedEntity.boundingBox.minY + (double)(this.targetedEntity.height) - (this.posY);
double d7 = this.targetedEntity.posZ - this.posZ;
this.renderYawOffset = this.rotationYaw = -((float)Math.atan2(d5, d7)) * 180.0F / (float)Math.PI;
if (this.canEntityBeSeen(this.targetedEntity))
{
this.waypointX = targetedEntity.posX;
this.waypointY = targetedEntity.posY;
this.waypointZ = targetedEntity.posZ;
float f1 = this.targetedEntity.getDistanceToEntity(this);
this.attackEntity(this.targetedEntity, f1);
}
}
else
{
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);
if (!this.worldObj.getCollidingBoundingBoxes(this, axisalignedbb).isEmpty())
{
return false;
}
}
return true;
}
@Override
protected String getLivingSound()
{
return "biomesoplenty:mob.wasp.say";
}
@Override
protected String getHurtSound()
{
return "biomesoplenty:mob.wasp.hurt";
}
@Override
protected String getDeathSound()
{
return "biomesoplenty:mob.wasp.hurt";
}
}