2015-12-27 19:38:12 -05:00
|
|
|
package WayofTime.bloodmagic.tile;
|
|
|
|
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-01-11 13:36:07 -08:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-11 13:36:07 -08:00
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-11 13:36:07 -08:00
|
|
|
import net.minecraft.util.BlockPos;
|
2015-12-27 19:38:12 -05:00
|
|
|
import net.minecraft.util.ITickable;
|
2016-01-11 13:36:07 -08:00
|
|
|
import net.minecraft.world.World;
|
2015-12-27 19:38:12 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class TilePhantomBlock extends TileEntity implements ITickable
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
private int ticksRemaining;
|
|
|
|
|
2016-01-11 13:36:07 -08:00
|
|
|
public TilePhantomBlock(int ticksRemaining)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-01-11 13:36:07 -08:00
|
|
|
this.ticksRemaining = ticksRemaining;
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void readFromNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
super.readFromNBT(tagCompound);
|
2016-01-11 13:36:07 -08:00
|
|
|
this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void writeToNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public void update()
|
|
|
|
{
|
2015-12-27 19:38:12 -05:00
|
|
|
ticksRemaining--;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (ticksRemaining <= 0)
|
|
|
|
{
|
2016-01-11 13:36:07 -08:00
|
|
|
worldObj.removeTileEntity(getPos());
|
|
|
|
worldObj.setBlockToAir(getPos());
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:36:07 -08:00
|
|
|
@Override
|
|
|
|
public Packet getDescriptionPacket()
|
|
|
|
{
|
|
|
|
NBTTagCompound nbt = new NBTTagCompound();
|
|
|
|
writeToNBT(nbt);
|
|
|
|
return new S35PacketUpdateTileEntity(getPos(), -999, nbt);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
|
|
|
|
{
|
|
|
|
super.onDataPacket(net, pkt);
|
|
|
|
readFromNBT(pkt.getNbtCompound());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-01-11 13:36:07 -08:00
|
|
|
return oldState.getBlock() != newState.getBlock();
|
2015-12-27 19:38:12 -05:00
|
|
|
}
|
|
|
|
}
|