Clean up TE implementations

Offload some work to base classes that provide some helpers

TODO: Implementations for Inventories (using caps) and ticking tiles with inventories.
This commit is contained in:
Nicholas Ignoffo 2016-09-07 17:46:06 -07:00
parent 4d331aa758
commit 798bad5583
23 changed files with 280 additions and 493 deletions

View file

@ -1,21 +1,12 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.base.TileTicking;
import lombok.NoArgsConstructor;
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.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@NoArgsConstructor
public class TilePhantomBlock extends TileEntity implements ITickable
public class TilePhantomBlock extends TileTicking
{
private int ticksRemaining = 10;
@ -25,22 +16,20 @@ public class TilePhantomBlock extends TileEntity implements ITickable
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
public void deserialize(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound)
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
return tagCompound;
}
@Override
public void update()
public void onUpdate()
{
ticksRemaining--;
@ -50,38 +39,4 @@ public class TilePhantomBlock extends TileEntity implements ITickable
worldObj.removeTileEntity(getPos());
}
}
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return new SPacketUpdateTileEntity(getPos(), -999, nbt);
}
@Override
@SideOnly(Side.CLIENT)
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
{
super.onDataPacket(net, pkt);
readFromNBT(pkt.getNbtCompound());
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
readFromNBT(tag);
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
return oldState.getBlock() != newState.getBlock();
}
}