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

77 lines
1.8 KiB
Java
Raw Normal View History

2014-07-31 23:45:40 +00:00
package WayofTime.alchemicalWizardry.common.tileEntity;
import net.minecraft.nbt.NBTTagCompound;
2015-07-29 12:23:01 +00:00
import net.minecraft.server.gui.IUpdatePlayerListBox;
2014-07-31 23:45:40 +00:00
import net.minecraft.tileentity.TileEntity;
2015-07-29 12:23:01 +00:00
import net.minecraft.util.BlockPos;
2014-07-31 23:45:40 +00:00
import net.minecraft.world.World;
2015-07-29 12:23:01 +00:00
import WayofTime.alchemicalWizardry.ModBlocks;
2014-07-31 23:45:40 +00:00
2015-07-29 12:23:01 +00:00
public class TESpectralBlock extends TileEntity implements IUpdatePlayerListBox
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
2015-07-29 12:23:01 +00:00
public void update()
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
{
2015-07-29 12:23:01 +00:00
worldObj.setBlockToAir(pos);
2014-07-31 23:45:40 +00:00
}
2014-10-13 20:33:20 +00:00
}
2015-07-29 12:23:01 +00:00
public static boolean createSpectralBlockAtLocation(World world, BlockPos pos, int duration)
2014-07-31 23:45:40 +00:00
{
2015-07-29 12:23:01 +00:00
if (!world.isAirBlock(pos))
2014-10-13 20:33:20 +00:00
{
return false;
}
2015-07-29 12:23:01 +00:00
world.setBlockState(pos, ModBlocks.spectralBlock.getDefaultState());
TileEntity tile = world.getTileEntity(pos);
2014-10-13 20:33:20 +00:00
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
}
}