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

@ -40,9 +40,9 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.deserialize(tagCompound);
this.isActive = tagCompound.getBoolean("isActive"); this.isActive = tagCompound.getBoolean("isActive");
this.activeCounter = tagCompound.getInteger("activeCounter"); this.activeCounter = tagCompound.getInteger("activeCounter");
this.key = tagCompound.getString("key"); this.key = tagCompound.getString("key");
@ -57,9 +57,9 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound); super.serialize(tagCompound);
tagCompound.setBoolean("isActive", isActive); tagCompound.setBoolean("isActive", isActive);
tagCompound.setInteger("activeCounter", activeCounter); tagCompound.setInteger("activeCounter", activeCounter);
tagCompound.setString("key", "".equals(key) ? "empty" : key); tagCompound.setString("key", "".equals(key) ? "empty" : key);
@ -153,19 +153,4 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
return false; return false;
} }
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new SPacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readFromNBT(packet.getNbtCompound());
}
} }

View file

@ -85,9 +85,9 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
isSlave = tag.getBoolean("isSlave"); isSlave = tag.getBoolean("isSlave");
direction = EnumFacing.getFront(tag.getInteger(Constants.NBT.DIRECTION)); direction = EnumFacing.getFront(tag.getInteger(Constants.NBT.DIRECTION));
@ -105,9 +105,9 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
tag.setBoolean("isSlave", isSlave); tag.setBoolean("isSlave", isSlave);
tag.setInteger(Constants.NBT.DIRECTION, direction.getIndex()); tag.setInteger(Constants.NBT.DIRECTION, direction.getIndex());

View file

@ -23,9 +23,9 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickable,
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.deserialize(tagCompound);
NBTTagCompound altarTag = tagCompound.getCompoundTag("bloodAltar"); NBTTagCompound altarTag = tagCompound.getCompoundTag("bloodAltar");
@ -33,9 +33,9 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickable,
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound); super.serialize(tagCompound);
NBTTagCompound altarTag = new NBTTagCompound(); NBTTagCompound altarTag = new NBTTagCompound();
this.bloodAltar.writeToNBT(altarTag); this.bloodAltar.writeToNBT(altarTag);

View file

@ -1,15 +1,11 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.tile.base.TileBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.*;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileBloodTank extends TileEntity implements IFluidHandler public class TileBloodTank extends TileBase implements IFluidHandler
{ {
public static int capacity; public static int capacity;
public FluidTank tank; public FluidTank tank;
@ -57,7 +53,7 @@ public class TileBloodTank extends TileEntity implements IFluidHandler
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound.getCompoundTag("tank")); tank.readFromNBT(tagCompound.getCompoundTag("tank"));
@ -65,40 +61,11 @@ public class TileBloodTank extends TileEntity implements IFluidHandler
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound);
if (tank.getFluidAmount() != 0) if (tank.getFluidAmount() != 0)
tagCompound.setTag("tank", tank.writeToNBT(new NBTTagCompound())); tagCompound.setTag("tank", tank.writeToNBT(new NBTTagCompound()));
tagCompound.setInteger("capacity", capacity); tagCompound.setInteger("capacity", capacity);
return tagCompound; return tagCompound;
} }
@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);
}
} }

View file

@ -112,9 +112,9 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
willMap.clear(); willMap.clear();
@ -129,9 +129,9 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
for (Entry<EnumDemonWillType, Double> entry : willMap.entrySet()) for (Entry<EnumDemonWillType, Double> entry : willMap.entrySet())
{ {

View file

@ -1,28 +1,20 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.tile.base.TileTicking;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; 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.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.soul.DemonWillHolder; import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.block.BlockDemonCrystal; import WayofTime.bloodmagic.block.BlockDemonCrystal;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileDemonCrystal extends TileEntity implements ITickable public class TileDemonCrystal extends TileTicking
{ {
public DemonWillHolder holder = new DemonWillHolder(); public DemonWillHolder holder = new DemonWillHolder();
public final int maxWill = 100; public final int maxWill = 100;
@ -47,7 +39,7 @@ public class TileDemonCrystal extends TileEntity implements ITickable
} }
@Override @Override
public void update() public void onUpdate()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
{ {
@ -179,7 +171,7 @@ public class TileDemonCrystal extends TileEntity implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.readFromNBT(tag);
@ -190,49 +182,12 @@ public class TileDemonCrystal extends TileEntity implements ITickable
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag);
holder.writeToNBT(tag, "Will"); holder.writeToNBT(tag, "Will");
tag.setInteger("crystalCount", crystalCount); tag.setInteger("crystalCount", crystalCount);
tag.setInteger("placement", placement.getIndex()); tag.setInteger("placement", placement.getIndex());
tag.setDouble("progress", progressToNextCrystal); tag.setDouble("progress", progressToNextCrystal);
return tag; return tag;
} }
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
return oldState.getBlock() != newState.getBlock();
}
@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());
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
readFromNBT(tag);
}
} }

View file

@ -5,19 +5,14 @@ import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWillConduit; import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.registry.ModBlocks; import WayofTime.bloodmagic.registry.ModBlocks;
import net.minecraft.block.state.IBlockState; import WayofTime.bloodmagic.tile.base.TileBase;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileDemonCrystallizer extends TileEntity implements ITickable, IDemonWillConduit public class TileDemonCrystallizer extends TileTicking implements IDemonWillConduit
{ {
//The whole purpose of this block is to grow a crystal initially. The acceleration and crystal growing is up to the crystal itself afterwards. //The whole purpose of this block is to grow a crystal initially. The acceleration and crystal growing is up to the crystal itself afterwards.
public DemonWillHolder holder = new DemonWillHolder(); public DemonWillHolder holder = new DemonWillHolder();
@ -34,7 +29,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
} }
@Override @Override
public void update() public void onUpdate()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
{ {
@ -93,7 +88,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.readFromNBT(tag);
@ -102,7 +97,7 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.writeToNBT(tag);
@ -175,38 +170,4 @@ public class TileDemonCrystallizer extends TileEntity implements ITickable, IDem
{ {
return holder.getWill(type); return holder.getWill(type);
} }
@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();
}
} }

View file

@ -4,19 +4,12 @@ import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType; import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWillConduit; import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import net.minecraft.block.state.IBlockState; import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileDemonPylon extends TileEntity implements ITickable, IDemonWillConduit public class TileDemonPylon extends TileTicking implements IDemonWillConduit
{ {
public DemonWillHolder holder = new DemonWillHolder(); public DemonWillHolder holder = new DemonWillHolder();
public final int maxWill = 100; public final int maxWill = 100;
@ -28,7 +21,7 @@ public class TileDemonPylon extends TileEntity implements ITickable, IDemonWillC
} }
@Override @Override
public void update() public void onUpdate()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
{ {
@ -54,7 +47,7 @@ public class TileDemonPylon extends TileEntity implements ITickable, IDemonWillC
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.readFromNBT(tag);
@ -62,10 +55,8 @@ public class TileDemonPylon extends TileEntity implements ITickable, IDemonWillC
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag);
holder.writeToNBT(tag, "Will"); holder.writeToNBT(tag, "Will");
return tag; return tag;
} }
@ -134,38 +125,4 @@ public class TileDemonPylon extends TileEntity implements ITickable, IDemonWillC
{ {
return holder.getWill(type); return holder.getWill(type);
} }
@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();
}
} }

View file

@ -1,18 +1,12 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.ritual.RitualPortal; import WayofTime.bloodmagic.ritual.RitualPortal;
import WayofTime.bloodmagic.tile.base.TileBase;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TileDimensionalPortal extends TileEntity public class TileDimensionalPortal extends TileBase
{ {
public String portalID = ""; public String portalID = "";
public int masterStoneX; public int masterStoneX;
@ -24,7 +18,7 @@ public class TileDimensionalPortal extends TileEntity
; ;
} }
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
@ -35,10 +29,8 @@ public class TileDimensionalPortal extends TileEntity
masterStoneZ = tagCompound.getInteger("masterStoneZ"); masterStoneZ = tagCompound.getInteger("masterStoneZ");
} }
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound);
tagCompound.setString(RitualPortal.PORTAL_ID_TAG, Strings.isNullOrEmpty(portalID) ? "" : portalID); tagCompound.setString(RitualPortal.PORTAL_ID_TAG, Strings.isNullOrEmpty(portalID) ? "" : portalID);
tagCompound.setInteger("masterStoneX", masterStoneX); tagCompound.setInteger("masterStoneX", masterStoneX);
@ -58,38 +50,4 @@ public class TileDimensionalPortal extends TileEntity
this.masterStoneY = blockPos.getY(); this.masterStoneY = blockPos.getY();
this.masterStoneZ = blockPos.getZ(); this.masterStoneZ = blockPos.getZ();
} }
@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();
}
} }

View file

@ -5,49 +5,16 @@ import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual; import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper; import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import WayofTime.bloodmagic.tile.base.TileBase;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@NoArgsConstructor @NoArgsConstructor
public class TileImperfectRitualStone extends TileEntity implements IImperfectRitualStone public class TileImperfectRitualStone extends TileBase implements IImperfectRitualStone
{ {
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new SPacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
}
@Override
@SideOnly(Side.CLIENT)
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readFromNBT(packet.getNbtCompound());
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
readFromNBT(tag);
}
// IImperfectRitualStone // IImperfectRitualStone
@Override @Override

View file

@ -74,17 +74,17 @@ public class TileIncenseAltar extends TileInventory implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
tranquility = tag.getDouble("tranquility"); tranquility = tag.getDouble("tranquility");
incenseAddition = tag.getDouble("incenseAddition"); incenseAddition = tag.getDouble("incenseAddition");
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
tag.setDouble("tranquility", tranquility); tag.setDouble("tranquility", tranquility);
tag.setDouble("incenseAddition", incenseAddition); tag.setDouble("incenseAddition", incenseAddition);
return tag; return tag;

View file

@ -1,6 +1,6 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import net.minecraft.block.state.IBlockState; import WayofTime.bloodmagic.tile.base.TileBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
@ -8,24 +8,17 @@ import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper; import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
public class TileInventory extends TileEntity implements IInventory public class TileInventory extends TileBase implements IInventory
{ {
protected int[] syncedSlots = new int[0]; protected int[] syncedSlots = new int[0];
protected ItemStack[] inventory; protected ItemStack[] inventory;
@ -53,7 +46,7 @@ public class TileInventory extends TileEntity implements IInventory
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
NBTTagList tags = tagCompound.getTagList("Items", 10); NBTTagList tags = tagCompound.getTagList("Items", 10);
@ -75,7 +68,7 @@ public class TileInventory extends TileEntity implements IInventory
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
NBTTagList tags = new NBTTagList(); NBTTagList tags = new NBTTagList();
@ -95,40 +88,6 @@ public class TileInventory extends TileEntity implements IInventory
return tagCompound; return tagCompound;
} }
@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();
}
public void dropItems() public void dropItems()
{ {
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this); InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);

View file

@ -3,17 +3,14 @@ package WayofTime.bloodmagic.tile;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import WayofTime.bloodmagic.tile.base.TileTicking;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -35,12 +32,10 @@ import WayofTime.bloodmagic.registry.ModItems;
import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.ChatUtil;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor
public class TileMasterRitualStone extends TileEntity implements IMasterRitualStone, ITickable public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone
{ {
private String owner; private String owner;
private boolean active; private boolean active;
@ -54,7 +49,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
private List<EnumDemonWillType> currentActiveWillConfig = new ArrayList<EnumDemonWillType>(); private List<EnumDemonWillType> currentActiveWillConfig = new ArrayList<EnumDemonWillType>();
@Override @Override
public void update() public void onUpdate()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
return; return;
@ -86,9 +81,8 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag);
owner = tag.getString(Constants.NBT.OWNER_UUID); owner = tag.getString(Constants.NBT.OWNER_UUID);
currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL)); currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL));
if (currentRitual != null) if (currentRitual != null)
@ -114,9 +108,8 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag);
String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual()); String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual());
tag.setString(Constants.NBT.OWNER_UUID, Strings.isNullOrEmpty(getOwner()) ? "" : getOwner()); tag.setString(Constants.NBT.OWNER_UUID, Strings.isNullOrEmpty(getOwner()) ? "" : getOwner());
tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId); tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
@ -188,12 +181,12 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
this.owner = crystalOwner; this.owner = crystalOwner;
this.currentRitual = ritual; this.currentRitual = ritual;
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3); notifyUpdate();
return true; return true;
} }
} }
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3); notifyUpdate();
return true; return true;
} }
} }
@ -242,7 +235,7 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
this.active = false; this.active = false;
this.activeTime = 0; this.activeTime = 0;
} }
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3); notifyUpdate();
} }
} }
@ -300,34 +293,6 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
return super.getPos(); return super.getPos();
} }
@Override
public SPacketUpdateTileEntity getUpdatePacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
writeToNBT(nbttagcompound);
return new SPacketUpdateTileEntity(pos, this.getBlockMetadata(), nbttagcompound);
}
@Override
@SideOnly(Side.CLIENT)
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
{
super.onDataPacket(net, packet);
readFromNBT(packet.getNbtCompound());
}
@Override
public NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
readFromNBT(tag);
}
@Override @Override
public World getWorldObj() public World getWorldObj()
{ {

View file

@ -282,9 +282,9 @@ public class TileMimic extends TileInventory implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak"); dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
tileTag = tag.getCompoundTag("tileTag"); tileTag = tag.getCompoundTag("tileTag");
@ -296,9 +296,9 @@ public class TileMimic extends TileInventory implements ITickable
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak); tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
tag.setTag("tileTag", tileTag); tag.setTag("tileTag", tileTag);

View file

@ -1,21 +1,12 @@
package WayofTime.bloodmagic.tile; package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.base.TileTicking;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound; 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 @NoArgsConstructor
public class TilePhantomBlock extends TileEntity implements ITickable public class TilePhantomBlock extends TileTicking
{ {
private int ticksRemaining = 10; private int ticksRemaining = 10;
@ -25,22 +16,20 @@ public class TilePhantomBlock extends TileEntity implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound);
this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING); this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound);
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining); tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
return tagCompound; return tagCompound;
} }
@Override @Override
public void update() public void onUpdate()
{ {
ticksRemaining--; ticksRemaining--;
@ -50,38 +39,4 @@ public class TilePhantomBlock extends TileEntity implements ITickable
worldObj.removeTileEntity(getPos()); 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();
}
} }

View file

@ -33,17 +33,17 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
burnTime = tag.getInteger(Constants.NBT.SOUL_FORGE_BURN); burnTime = tag.getInteger(Constants.NBT.SOUL_FORGE_BURN);
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
tag.setInteger(Constants.NBT.SOUL_FORGE_BURN, burnTime); tag.setInteger(Constants.NBT.SOUL_FORGE_BURN, burnTime);
return tag; return tag;

View file

@ -2,6 +2,8 @@ package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.registry.ModBlocks; import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.tile.base.TileBase;
import WayofTime.bloodmagic.tile.base.TileTicking;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -17,7 +19,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
public class TileSpectralBlock extends TileEntity implements ITickable public class TileSpectralBlock extends TileTicking
{ {
private int ticksRemaining; private int ticksRemaining;
private String containedBlockName; private String containedBlockName;
@ -28,18 +30,16 @@ public class TileSpectralBlock extends TileEntity implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound);
ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING); ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
containedBlockName = tagCompound.getString(Constants.NBT.CONTAINED_BLOCK_NAME); containedBlockName = tagCompound.getString(Constants.NBT.CONTAINED_BLOCK_NAME);
containedBlockMeta = tagCompound.getInteger(Constants.NBT.CONTAINED_BLOCK_META); containedBlockMeta = tagCompound.getInteger(Constants.NBT.CONTAINED_BLOCK_META);
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound);
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining); tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
tagCompound.setString(Constants.NBT.CONTAINED_BLOCK_NAME, Strings.isNullOrEmpty(containedBlockName) ? "" : containedBlockName); tagCompound.setString(Constants.NBT.CONTAINED_BLOCK_NAME, Strings.isNullOrEmpty(containedBlockName) ? "" : containedBlockName);
tagCompound.setInteger(Constants.NBT.CONTAINED_BLOCK_META, containedBlockMeta); tagCompound.setInteger(Constants.NBT.CONTAINED_BLOCK_META, containedBlockMeta);
@ -47,35 +47,7 @@ public class TileSpectralBlock extends TileEntity implements ITickable
} }
@Override @Override
public SPacketUpdateTileEntity getUpdatePacket() public void onUpdate()
{
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 void update()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
{ {

View file

@ -35,16 +35,16 @@ public class TileTeleposer extends TileInventory implements ITickable
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void deserialize(NBTTagCompound tagCompound)
{ {
super.readFromNBT(tagCompound); super.deserialize(tagCompound);
previousInput = tagCompound.getInteger(Constants.NBT.PREVIOUS_INPUT); previousInput = tagCompound.getInteger(Constants.NBT.PREVIOUS_INPUT);
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) public NBTTagCompound serialize(NBTTagCompound tagCompound)
{ {
super.writeToNBT(tagCompound); super.serialize(tagCompound);
tagCompound.setInteger(Constants.NBT.PREVIOUS_INPUT, previousInput); tagCompound.setInteger(Constants.NBT.PREVIOUS_INPUT, previousInput);
return tagCompound; return tagCompound;
} }

View file

@ -0,0 +1,124 @@
package WayofTime.bloodmagic.tile.base;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Base tile class.
*
* Handles data syncing and core data writing/reading.
*/
public class TileBase extends TileEntity
{
@Override
public final void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
deserializeBase(compound);
deserialize(compound);
}
@Override
public final NBTTagCompound writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
serializeBase(compound);
return serialize(compound);
}
/**
* Called by {@link #readFromNBT(NBTTagCompound)}
*
* Internal data (such as coordinates) are handled for you. Just read the data you need.
*
* @param tagCompound - The tag compound to read from
*/
public void deserialize(NBTTagCompound tagCompound)
{
}
/**
* Package private method for reading base data from the tag compound.
*
* @see TileTicking
*
* @param tagCompound - The tag compound to read from
*/
void deserializeBase(NBTTagCompound tagCompound)
{
}
/**
* Called by {@link #writeToNBT(NBTTagCompound)}
*
* Internal data (such as coordinates) are handled for you. Just read the data you need.
*
* @param tagCompound - The tag compound to write to.
* @return the modified tag compound
*/
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
return tagCompound;
}
/**
* Package private method for writing base data to the tag compound.
*
* @see TileTicking
*
* @param tagCompound - The tag compound to write to.
* @return the modified tag compound
*/
NBTTagCompound serializeBase(NBTTagCompound tagCompound)
{
return tagCompound;
}
public void notifyUpdate() {
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
}
// Data syncing
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
return oldState.getBlock() != newState.getBlock();
}
@Override
public final SPacketUpdateTileEntity getUpdatePacket()
{
return new SPacketUpdateTileEntity(getPos(), -999, writeToNBT(new NBTTagCompound()));
}
@Override
@SideOnly(Side.CLIENT)
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
{
super.onDataPacket(net, pkt);
readFromNBT(pkt.getNbtCompound());
}
@Override
public final NBTTagCompound getUpdateTag()
{
return writeToNBT(new NBTTagCompound());
}
@Override
public final void handleUpdateTag(NBTTagCompound tag)
{
readFromNBT(tag);
}
}

View file

@ -0,0 +1,63 @@
package WayofTime.bloodmagic.tile.base;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ITickable;
/**
* Base class for tiles that tick. Allows disabling the ticking programmatically.
*/
// TODO - Move implementations that depend on existed ticks to new methods from here.
public abstract class TileTicking extends TileBase implements ITickable
{
private int ticksExisted;
private boolean shouldTick = true;
@Override
public final void update()
{
if (shouldTick()) {
ticksExisted++;
onUpdate();
}
}
@Override
void deserializeBase(NBTTagCompound tagCompound)
{
this.ticksExisted = tagCompound.getInteger("ticksExisted");
this.shouldTick = tagCompound.getBoolean("shouldTick");
}
@Override
NBTTagCompound serializeBase(NBTTagCompound tagCompound)
{
tagCompound.setInteger("ticksExisted", getTicksExisted());
tagCompound.setBoolean("shouldTick", shouldTick());
return tagCompound;
}
/**
* Called every tick that {@link #shouldTick()} is true.
*/
public abstract void onUpdate();
public int getTicksExisted()
{
return ticksExisted;
}
public void resetLifetime()
{
ticksExisted = 0;
}
public boolean shouldTick()
{
return shouldTick;
}
public void setShouldTick(boolean shouldTick)
{
this.shouldTick = shouldTick;
}
}

View file

@ -47,9 +47,9 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
currentActiveSlot = tag.getInteger("currentSlot"); currentActiveSlot = tag.getInteger("currentSlot");
priorities = tag.getIntArray(Constants.NBT.ROUTING_PRIORITY); priorities = tag.getIntArray(Constants.NBT.ROUTING_PRIORITY);
if (priorities.length != 6) if (priorities.length != 6)
@ -83,9 +83,9 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
tag.setInteger("currentSlot", currentActiveSlot); tag.setInteger("currentSlot", currentActiveSlot);
tag.setIntArray(Constants.NBT.ROUTING_PRIORITY, priorities); tag.setIntArray(Constants.NBT.ROUTING_PRIORITY, priorities);
tag.setBoolean("updated", true); tag.setBoolean("updated", true);

View file

@ -155,10 +155,9 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
} }
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.serialize(tag);
NBTTagList tags = new NBTTagList(); NBTTagList tags = new NBTTagList();
for (BlockPos pos : generalNodeList) for (BlockPos pos : generalNodeList)
{ {
@ -195,9 +194,9 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
NBTTagList tags = tag.getTagList(Constants.NBT.ROUTING_MASTER_GENERAL, 10); NBTTagList tags = tag.getTagList(Constants.NBT.ROUTING_MASTER_GENERAL, 10);
for (int i = 0; i < tags.tagCount(); i++) for (int i = 0; i < tags.tagCount(); i++)

View file

@ -41,9 +41,9 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
private List<BlockPos> connectionList = new LinkedList<BlockPos>(); private List<BlockPos> connectionList = new LinkedList<BlockPos>();
@Override @Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) public NBTTagCompound serialize(NBTTagCompound tag)
{ {
super.writeToNBT(tag); super.deserialize(tag);
NBTTagCompound masterTag = new NBTTagCompound(); NBTTagCompound masterTag = new NBTTagCompound();
masterTag.setInteger(Constants.NBT.X_COORD, masterPos.getX()); masterTag.setInteger(Constants.NBT.X_COORD, masterPos.getX());
masterTag.setInteger(Constants.NBT.Y_COORD, masterPos.getY()); masterTag.setInteger(Constants.NBT.Y_COORD, masterPos.getY());
@ -64,9 +64,9 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void deserialize(NBTTagCompound tag)
{ {
super.readFromNBT(tag); super.deserialize(tag);
connectionList.clear(); connectionList.clear();
NBTTagCompound masterTag = tag.getCompoundTag(Constants.NBT.ROUTING_MASTER); NBTTagCompound masterTag = tag.getCompoundTag(Constants.NBT.ROUTING_MASTER);
masterPos = new BlockPos(masterTag.getInteger(Constants.NBT.X_COORD), masterTag.getInteger(Constants.NBT.Y_COORD), masterTag.getInteger(Constants.NBT.Z_COORD)); masterPos = new BlockPos(masterTag.getInteger(Constants.NBT.X_COORD), masterTag.getInteger(Constants.NBT.Y_COORD), masterTag.getInteger(Constants.NBT.Z_COORD));