2012-11-05 20:29:04 +01:00
|
|
|
package mekanism.common;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
|
|
|
public class EntityObsidianTNT extends Entity
|
|
|
|
{
|
|
|
|
/** How long the fuse is */
|
|
|
|
public int fuse;
|
2013-03-11 18:49:01 +01:00
|
|
|
|
|
|
|
/** Whether or not the TNT has exploded */
|
2012-08-15 22:41:41 +02:00
|
|
|
private boolean hasExploded = false;
|
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
public EntityObsidianTNT(World world)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-03-11 18:49:01 +01:00
|
|
|
super(world);
|
2012-08-15 22:41:41 +02:00
|
|
|
fuse = 0;
|
|
|
|
preventEntitySpawning = true;
|
|
|
|
setSize(0.98F, 0.98F);
|
|
|
|
yOffset = height / 2.0F;
|
|
|
|
}
|
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
public EntityObsidianTNT(World world, double x, double y, double z)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-03-11 18:49:01 +01:00
|
|
|
this(world);
|
|
|
|
setPosition(x, y, z);
|
|
|
|
float randPi = (float)(Math.random()*Math.PI*2);
|
|
|
|
motionX = -(Math.sin(randPi))*0.02F;
|
2013-02-22 04:03:54 +01:00
|
|
|
motionY = 0.2;
|
2013-03-11 18:49:01 +01:00
|
|
|
motionZ = -(Math.cos(randPi))*0.02F;
|
2012-11-05 20:29:04 +01:00
|
|
|
fuse = Mekanism.ObsidianTNTDelay;
|
2013-03-11 18:49:01 +01:00
|
|
|
prevPosX = x;
|
|
|
|
prevPosY = y;
|
|
|
|
prevPosZ = z;
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
protected void entityInit() {}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
protected boolean canTriggerWalking()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public boolean canBeCollidedWith()
|
|
|
|
{
|
|
|
|
return !isDead;
|
|
|
|
}
|
2012-11-06 16:44:14 +01:00
|
|
|
|
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
prevPosX = posX;
|
|
|
|
prevPosY = posY;
|
|
|
|
prevPosZ = posZ;
|
2013-02-22 04:03:54 +01:00
|
|
|
motionY -= 0.04;
|
2012-08-15 22:41:41 +02:00
|
|
|
moveEntity(motionX, motionY, motionZ);
|
2013-02-22 04:03:54 +01:00
|
|
|
motionX *= 0.98;
|
|
|
|
motionY *= 0.98;
|
|
|
|
motionZ *= 0.98;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
if(onGround)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-02-22 04:03:54 +01:00
|
|
|
motionX *= 0.7;
|
|
|
|
motionZ *= 0.7;
|
|
|
|
motionY *= -0.5;
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
2013-03-11 18:49:01 +01:00
|
|
|
if(fuse-- <= 0)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2013-03-11 18:49:01 +01:00
|
|
|
if(!worldObj.isRemote)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
|
|
|
setDead();
|
|
|
|
explode();
|
|
|
|
}
|
2013-03-11 18:49:01 +01:00
|
|
|
else {
|
2012-08-15 22:41:41 +02:00
|
|
|
if(hasExploded)
|
|
|
|
{
|
|
|
|
setDead();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
worldObj.spawnParticle("lava", posX, posY + 0.5D, posZ, 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-11 18:49:01 +01:00
|
|
|
else {
|
2012-08-15 22:41:41 +02:00
|
|
|
worldObj.spawnParticle("lava", posX, posY + 0.5D, posZ, 0.0D, 0.0D, 0.0D);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void explode()
|
|
|
|
{
|
2012-11-05 20:29:04 +01:00
|
|
|
worldObj.createExplosion((Entity)null, posX, posY, posZ, Mekanism.ObsidianTNTBlastRadius, true);
|
2012-08-15 22:41:41 +02:00
|
|
|
hasExploded = true;
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
|
|
|
|
{
|
|
|
|
par1NBTTagCompound.setByte("Fuse", (byte)fuse);
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
|
|
|
|
{
|
|
|
|
fuse = par1NBTTagCompound.getByte("Fuse");
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2012-08-15 22:41:41 +02:00
|
|
|
public float getShadowSize()
|
|
|
|
{
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
}
|