DimDoors/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java

326 lines
8.5 KiB
Java
Raw Normal View History

package StevenDimDoors.mod_pocketDim.ticking;
2013-05-28 00:58:20 +02:00
import java.util.List;
2013-05-27 02:01:44 +02:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityFlying;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
2013-05-28 02:08:42 +02:00
import net.minecraft.nbt.NBTTagCompound;
2013-05-27 14:10:07 +02:00
import net.minecraft.util.AxisAlignedBB;
2013-05-28 02:08:42 +02:00
import net.minecraft.util.DamageSource;
2013-05-27 02:01:44 +02:00
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import StevenDimDoors.mod_pocketDim.util.Point4D;
2013-06-02 03:43:56 +02:00
import StevenDimDoors.mod_pocketDim.world.LimboProvider;
import StevenDimDoors.mod_pocketDim.world.PocketProvider;
2013-05-28 00:58:20 +02:00
public class MobMonolith extends EntityFlying implements IMob
{
2013-05-27 14:10:07 +02:00
float soundTime = 0;
int aggro = 0;
byte textureState = 0;
2013-05-30 03:05:59 +02:00
float scaleFactor = 0;
2013-06-11 03:25:31 +02:00
int aggroMax;
2013-05-27 14:10:07 +02:00
int destX=0;
int destY=0;
int destZ=0;
public MobMonolith(World par1World)
{
super(par1World);
2013-05-31 08:17:05 +02:00
this.texture="/mods/DimDoors/textures/mobs/Monolith0.png";
2013-06-11 19:21:39 +02:00
this.setSize(3F, 9.0F);
2013-05-28 00:58:20 +02:00
this.noClip=true;
2013-06-11 19:21:39 +02:00
this.scaleFactor= (float) ((rand.nextDouble()/2)+1);
2013-06-11 03:25:31 +02:00
this.aggroMax=rand.nextInt(245)+200;
if (properties == null)
properties = DDProperties.instance();
}
private static DDProperties properties = null;
2013-05-30 03:05:59 +02:00
@Override
public boolean canDespawn()
{
return false;
}
@Override
public int getMaxHealth()
{
// TODO Auto-generated method stub
return 20;
}
2013-05-28 02:08:42 +02:00
public boolean canBePushed()
{
return false;
}
2013-05-30 03:05:59 +02:00
public float getRenderSizeModifier()
{
return this.scaleFactor;
}
public void setEntityPosition(Entity entity, double x, double y, double z)
{
entity.lastTickPosX = entity.prevPosX = entity.posX = x;
entity.lastTickPosY = entity.prevPosY = entity.posY = y + (double)entity.yOffset;
entity.lastTickPosZ = entity.prevPosZ = entity.posZ = z;
entity.setPosition(x, y, z);
}
protected void entityInit()
{
super.entityInit();
this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
}
2013-05-28 00:58:20 +02:00
2013-05-27 02:01:44 +02:00
@Override
public void onEntityUpdate()
{
if (!(this.worldObj.provider instanceof LimboProvider || this.worldObj.provider instanceof PocketProvider))
2013-06-16 09:40:46 +02:00
{
this.setDead();
}
byte b0 = this.dataWatcher.getWatchableObjectByte(16);
this.texture="/mods/DimDoors/textures/mobs/Monolith"+b0+".png";
2013-05-27 14:10:07 +02:00
super.onEntityUpdate();
if (this.isEntityAlive() && this.isEntityInsideOpaqueBlock())
{
2013-06-15 09:09:46 +02:00
this.setDead();
}
2013-06-14 21:21:38 +02:00
EntityPlayer entityPlayer = this.worldObj.getClosestPlayerToEntity(this, 30);
2013-05-27 14:10:07 +02:00
if (entityPlayer != null)
2013-05-27 02:01:44 +02:00
{
if(this.soundTime<=0)
{
2013-06-15 09:09:46 +02:00
this.playSound("mods.DimDoors.sfx.monk", 1F, 1F);
this.soundTime=100;
}
2013-05-27 14:10:07 +02:00
this.faceEntity(entityPlayer, 1, 1);
if (shouldAttackPlayer(entityPlayer))
2013-05-27 02:01:44 +02:00
{
if (aggro<470)
2013-05-27 14:10:07 +02:00
{
if (rand.nextInt(11)>this.textureState||this.aggro>=300||rand.nextInt(13)>this.textureState&&this.aggroMax>this.aggro)
2013-05-28 00:58:20 +02:00
{
aggro++;
}
if (this.worldObj.provider instanceof PocketProvider||this.worldObj.getClosestPlayerToEntity(this, 5)!=null)
2013-05-28 00:58:20 +02:00
{
2013-05-29 07:22:50 +02:00
aggro++;
aggro++;
if (rand.nextBoolean())
2013-05-28 00:58:20 +02:00
{
2013-05-28 04:45:21 +02:00
aggro++;
2013-05-28 00:58:20 +02:00
}
2013-05-28 05:30:40 +02:00
}
if (aggro>430&&this.soundTime<100)
2013-05-28 05:30:40 +02:00
{
2013-06-15 05:16:27 +02:00
this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ,"mods.DimDoors.sfx.tearing",2F, 1F);
2013-06-14 21:21:38 +02:00
this.soundTime=100;
2013-05-28 00:58:20 +02:00
}
if (aggro>445&&this.soundTime<200)
2013-05-27 14:10:07 +02:00
{
2013-06-15 05:16:27 +02:00
this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ,"mods.DimDoors.sfx.tearing",5F, 1F);
2013-06-14 21:21:38 +02:00
this.soundTime=200;
2013-05-27 14:10:07 +02:00
}
}
else if (!this.worldObj.isRemote && !entityPlayer.capabilities.isCreativeMode)
2013-05-27 14:10:07 +02:00
{
Point4D destination = new Point4D(
(int) this.posX + MathHelper.getRandomIntegerInRange(rand, -250, 250),
(int) this.posY + 500,
(int) this.posZ + MathHelper.getRandomIntegerInRange(rand, -250, 250),
properties.LimboDimensionID);
DDTeleporter.teleportEntity(entityPlayer, destination);
this.aggro = 0;
2013-05-28 05:30:40 +02:00
2013-05-31 08:17:05 +02:00
entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1);
2013-05-27 14:10:07 +02:00
}
if (!(this.worldObj.provider instanceof LimboProvider || this.worldObj.getClosestPlayerToEntity(this, 5) != null) || this.aggro > 300)
2013-05-29 07:22:50 +02:00
{
for (int i = 0; i < -1+this.textureState/2; ++i)
{
entityPlayer.worldObj.spawnParticle("portal", entityPlayer.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, entityPlayer.posY + this.rand.nextDouble() * (double)entityPlayer.height - 0.75D, entityPlayer.posZ + (this.rand.nextDouble() - 0.5D) * (double)entityPlayer.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D);
}
2013-05-29 07:22:50 +02:00
}
2013-05-27 02:01:44 +02:00
}
2013-05-28 04:45:21 +02:00
else
{
if(aggro>0)
{
if(rand.nextInt(10)==0)
{
aggro--;
}
2013-05-28 04:45:21 +02:00
}
}
2013-05-27 02:01:44 +02:00
}
2013-05-28 00:58:20 +02:00
else
2013-05-27 14:10:07 +02:00
{
2013-05-28 00:58:20 +02:00
if(aggro>0)
{
aggro--;
2013-05-28 04:45:21 +02:00
if(rand.nextBoolean())
{
aggro--;
}
2013-05-28 00:58:20 +02:00
}
2013-05-27 14:10:07 +02:00
}
if (soundTime>=0)
2013-05-27 14:10:07 +02:00
{
soundTime--;
}
2013-05-28 00:58:20 +02:00
this.textureState= (byte) (this.aggro/25);
if (!this.worldObj.isRemote)
{
this.dataWatcher.updateObject(16, Byte.valueOf(this.textureState));
}
}
private boolean shouldAttackPlayer(EntityPlayer par1EntityPlayer)
{
return par1EntityPlayer.canEntityBeSeen(this);
}
private boolean isCourseTraversable(double par1, double par3, double par5, double par7)
{
double d4 = (par1 - this.posX) / par7;
double d5 = (par3 - this.posY) / par7;
double d6 = (par5 - 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;
}
public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
{
if(!(par1DamageSource==DamageSource.inWall))
{
this.aggro=400;
}
return false;
}
public void faceEntity(Entity par1Entity, float par2, float par3)
{
double d0 = par1Entity.posX - this.posX;
double d1 = par1Entity.posZ - this.posZ;
double d2;
if (par1Entity instanceof EntityLiving)
{
EntityLiving entityliving = (EntityLiving)par1Entity;
d2 = entityliving.posY + (double)entityliving.getEyeHeight() - (this.posY + (double)this.getEyeHeight());
}
else
{
d2 = (par1Entity.boundingBox.minY + par1Entity.boundingBox.maxY) - (this.posY + (double)this.getEyeHeight());
}
double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d1 * d1);
float f2 = (float)(Math.atan2(d1, d0) * 180.0D / Math.PI) - 90.0F;
float f3 = (float)(-(Math.atan2(d2, d3) * 180.0D / Math.PI));
this.rotationPitch = f3;
this.rotationYaw = f2;
this.rotationYaw = f2;
this.rotationYawHead=f2;
this.renderYawOffset=this.rotationYaw;
}
private float updateRotation(float par1, float par2, float par3)
{
float f3 = MathHelper.wrapAngleTo180_float(par2 - par1);
if (f3 > par3)
{
f3 = par3;
}
if (f3 < -par3)
{
f3 = -par3;
}
return par1 + f3;
}
public float getRotationYawHead()
{
return 0.0F;
}
public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeEntityToNBT(par1NBTTagCompound);
par1NBTTagCompound.setFloat("soundTime", this.soundTime);
par1NBTTagCompound.setInteger("aggro", this.aggro);
par1NBTTagCompound.setInteger("aggroMax", this.aggroMax);
par1NBTTagCompound.setByte("textureState", this.textureState);
par1NBTTagCompound.setFloat("scaleFactor", this.scaleFactor);
2013-06-24 06:34:21 +02:00
}
2013-06-24 06:34:21 +02:00
@Override
public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readEntityFromNBT(par1NBTTagCompound);
this.soundTime = par1NBTTagCompound.getFloat("soundTime");
this.aggro = par1NBTTagCompound.getInteger("aggro");
this.aggroMax = par1NBTTagCompound.getInteger("aggroMax");
this.textureState = par1NBTTagCompound.getByte("textureState");
this.scaleFactor = par1NBTTagCompound.getFloat("scaleFactor");
2013-05-27 02:01:44 +02:00
}
public boolean getCanSpawnHere()
{
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox( this.posX-15, posY-4, this.posZ-15, this.posX+15, this.posY+15, this.posZ+15));
2013-05-28 02:08:42 +02:00
if(this.worldObj.provider.dimensionId==DDProperties.instance().LimboDimensionID)
{
if(list.size()>0)
{
return false;
}
2013-05-30 03:05:59 +02:00
}
else if(this.worldObj.provider instanceof PocketProvider)
{
if(list.size()>5||this.worldObj.canBlockSeeTheSky((int)this.posX, (int)this.posY, (int)this.posZ))
{
return false;
}
}
return this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox);
}
}