BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TESpectralBlock.java

81 lines
1.8 KiB
Java
Raw Normal View History

2014-07-31 23:45:40 +00:00
package WayofTime.alchemicalWizardry.common.tileEntity;
2014-10-13 20:33:20 +00:00
import WayofTime.alchemicalWizardry.ModBlocks;
2014-07-31 23:45:40 +00:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class TESpectralBlock extends TileEntity
2014-10-13 20:33:20 +00:00
{
2014-07-31 23:45:40 +00:00
private int ticksRemaining;
public TESpectralBlock()
{
ticksRemaining = 0;
}
@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
ticksRemaining = par1NBTTagCompound.getInteger("ticksRemaining");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
2014-10-13 20:33:20 +00:00
par1NBTTagCompound.setInteger("ticksRemaining", ticksRemaining);
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
2014-07-31 23:45:40 +00:00
@Override
public void updateEntity()
{
super.updateEntity();
2014-10-13 20:33:20 +00:00
if (worldObj.isRemote)
2014-07-31 23:45:40 +00:00
{
2014-10-13 20:33:20 +00:00
return;
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
2014-07-31 23:45:40 +00:00
this.ticksRemaining--;
2014-10-13 20:33:20 +00:00
if (this.ticksRemaining <= 0)
2014-07-31 23:45:40 +00:00
{
2014-10-13 20:33:20 +00:00
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
}
2014-07-31 23:45:40 +00:00
public static boolean createSpectralBlockAtLocation(World world, int x, int y, int z, int duration)
{
2014-10-13 20:33:20 +00:00
if (!world.isAirBlock(x, y, z))
{
return false;
}
world.setBlock(x, y, z, ModBlocks.spectralBlock);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TESpectralBlock)
{
((TESpectralBlock) tile).setDuration(duration);
return true;
}
return false;
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
2014-07-31 23:45:40 +00:00
public void setDuration(int dur)
{
2014-10-13 20:33:20 +00:00
this.ticksRemaining = dur;
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
2014-07-31 23:45:40 +00:00
public void resetDuration(int dur)
{
2014-10-13 20:33:20 +00:00
if (this.ticksRemaining < dur)
{
this.ticksRemaining = dur;
}
2014-07-31 23:45:40 +00:00
}
}