Add IItemHandler support to (most) blocks, fixed machines rotating (thanks @Ricket)

This commit is contained in:
aidancbrady committed 2017-03-29 13:51:00 -04:00
1 parent 0e9f380bd7
commit c12f1c1e6f
5 files changed
+107 -44

No files matched your search

@@ -184,7 +184,11 @@ public abstract class TileEntityBasicBlock extends TileEntity implements ITileNe
{
super.readFromNBT(nbtTags);
facing = EnumFacing.getFront(nbtTags.getInteger("facing"));
if(nbtTags.hasKey("facing"))
{
facing = EnumFacing.getFront(nbtTags.getInteger("facing"));
}
redstone = nbtTags.getBoolean("redstone");
for(ITileComponent component : components)
@@ -198,7 +202,11 @@ public abstract class TileEntityBasicBlock extends TileEntity implements ITileNe
{
super.writeToNBT(nbtTags);
nbtTags.setInteger("facing", facing == null ? -1 : facing.ordinal());
if(facing != null)
{
nbtTags.setInteger("facing", facing.ordinal());
}
nbtTags.setBoolean("redstone", redstone);
for(ITileComponent component : components)
@@ -299,4 +307,22 @@ public abstract class TileEntityBasicBlock extends TileEntity implements ITileNe
return null;
}
@Override
public NBTTagCompound getUpdateTag()
{
// Forge writes only x/y/z/id info to a new NBT Tag Compound. This is fine, we have a custom network system
// to send other data so we don't use this one (yet).
return super.getUpdateTag();
}
@Override
public void handleUpdateTag(NBTTagCompound tag)
{
// The super implementation of handleUpdateTag is to call this readFromNBT. But, the given TagCompound
// only has x/y/z/id data, so our readFromNBT will set a bunch of default values which are wrong.
// So simply call the super's readFromNBT, to let Forge do whatever it wants, but don't treat this like
// a full NBT object, don't pass it to our custom read methods.
super.readFromNBT(tag);
}
}