BloodMagic/src/main/java/WayofTime/bloodmagic/tile/TilePhantomBlock.java
Nick 9950b32d53 Fix Sigil of the Phantom Bridge
I'm tentatively considering this fixed. I'd rather not do it this way, but it seems to work...
2016-01-11 13:36:07 -08:00

69 lines
1.9 KiB
Java

package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.Constants;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ITickable;
import net.minecraft.world.World;
public class TilePhantomBlock extends TileEntity implements ITickable
{
private int ticksRemaining;
public TilePhantomBlock(int ticksRemaining)
{
this.ticksRemaining = ticksRemaining;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
}
@Override
public void update()
{
ticksRemaining--;
if (ticksRemaining <= 0)
{
worldObj.removeTileEntity(getPos());
worldObj.setBlockToAir(getPos());
}
}
@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)
{
return oldState.getBlock() != newState.getBlock();
}
}