So I have a tile entity of a container block, and on the client side at least, it seems to think everything is 0, false, etc.
1.) For instance, I have the debug code
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == ModBlocks.MY_BLOCK) { // you'd think this would always be true
return state.getValue(MyBlock.ACTIVATED);
}
MyMod.LOGGER.info(pos.getX() + " " + pos.getY() + " " + pos.getZ() + " " + state.getBlock().getUnlocalizedName()); // debug
return false;
which not only always prints something to the logger, but the thing that it prints is actually
0 0 0 tile:bedrock
(or sometimes tile:air, depending on what is at 0,0,0)
The value of pos is not being changed/overwritten anywhere in my code.
2.) As well, the tile entity resets to default whenever the world is reloaded, forgetting all of the items inside it. While I am setting NBT as follows:
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
if (compound.hasKey("ITEMS")) {
itemStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("ITEMS"));
}
if (compound.hasKey("previousRedstoneState")) {
previousRedstoneState = compound.getBoolean("previousRedstoneState");
}
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
compound.setTag("ITEMS", itemStackHandler.serializeNBT());
compound.setBoolean("previousRedstoneState", previousRedstoneState);
return compound;
}
my GUI for the block does not display the correct previousRedstoneState. It does get the items right, but only until world exit.
3.) I have tried sending packets using the MinecraftByExample method, in case the GUI was a server/client issue:
@Nullable
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(getPos(), getBlockMetadata(), getUpdateTag());
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
handleUpdateTag(pkt.getNbtCompound());
}
@Override
public NBTTagCompound getUpdateTag() {
NBTTagCompound nbtTagCompound = new NBTTagCompound();
writeToNBT(new NBTTagCompound());
return nbtTagCompound;
}
@Override
public void handleUpdateTag(NBTTagCompound tag) {
this.readFromNBT(tag);
}
This updates the GUI text that corresponds to the NBT, but not to the blockstate. As well, if I store a byte array in the NBT that is being created from analyzing the inventory of a neighbouring block, that part of the NBT does not update correctly.
I can supply additional context as necessary.
How can I medicate my poor block?