Posted October 10, 201410 yr I got a TileEntity that has also a Container and a Gui. That said, it has only one slot and i write the contents to NBT and also read it. When i put the itemstack inside all works perfectly. But when i log out and relog in, the server seems to be working fine (things are happening) but the client is not recognising the item inside unless i open the gui. Then all the animations that depend on that item can trigger after that. Anything i missed? Packets? Sever or client only things? "!world.isRemote"? EDIT: this is the TileEntityCode. I'll explain a bit. public class TileEntityBatReceptacle extends TileEntityMachine implements IInventory { public ItemStack item; public float BatRotation = 0.0F; public Block[] bottomBlocks = new Block[9]; public boolean[] bottomBlocksValid = new boolean[9]; public boolean charge; public TileEntityBatReceptacle() { EnergyAmount = 0; charge = true; } @Override public void writeToNBT(NBTTagCompound compound) { NBTTagList items = new NBTTagList(); for (int i = 0; i < getSizeInventory(); i++) { ItemStack stack = getStackInSlot(i); if (stack != null) { NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte) i); stack.writeToNBT(item); items.appendTag(item); } } compound.setTag("Items", items); compound.setFloat("rotaion", BatRotation); compound.setBoolean("charge", charge); super.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList items = compound.getTagList("Items", 10); for (int i = 0; i < items.tagCount(); i++) { NBTTagCompound item = items.getCompoundTagAt(i); int slot = item.getByte("Slot"); if (slot >= 0 && slot < getSizeInventory()) { setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } BatRotation = compound.getFloat("rotation"); charge = compound.getBoolean("charge"); } public void updateEntity() { for (int i = 0; i < bottomBlocksValid.length; i++) { bottomBlocksValid[i] = false; } charge = true; /** * SE ENCARGA DE OBTENER EL NIVEL DE ENERGÍA DE LA BATERÍA E IGUALARLO * AL DEL RECEPTÁCULO. */ ItemStack battery = getStackInSlot(0); if (battery != null) { if (battery.getItem() == AncientCraft.ItemCorruptBattery) { NBTTagCompound compound = battery.getTagCompound(); EnergyAmount = compound.getInteger("EnergyAmount"); } else { EnergyAmount = 0; } } else { EnergyAmount = 0; } /** * SE ENCARGA DE INCREMENTAR LA CARGA DE LA BATERÍA CUANDO HAY UN * ALIONITEORE DEBAJO Y EL CONSTRUCTO NECESARIO */ for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { bottomBlocks[i * 3 + j] = worldObj.getBlock(xCoord - 1 + i, yCoord - 1, zCoord - 1 + j); if (bottomBlocks[i * 3 + j] == AncientCraft.AlionOreShell && i * 3 + j != 4) { bottomBlocksValid[i * 3 + j] = true; } else if (bottomBlocks[i * 3 + j] == AncientCraft.AlioniteOre && i * 3 + j == 4) { bottomBlocksValid[i * 3 + j] = true; } } } for (int i = 0; i < 9; i++) { if (bottomBlocksValid[i] == false) { charge = false; } } if (charge == true) { if (battery != null) { if (battery.getItem() == AncientCraft.ItemCorruptBattery) { NBTTagCompound compound = battery.getTagCompound(); if (compound != null) { if (EnergyAmount < Reference.MAX_BATTERY_LEVEL) { compound.setInteger("EnergyAmount", EnergyAmount + 1); } } } } } /** * rotación de la bartía en el renderizado. */ if (!worldObj.isRemote) { } else { BatRotation += 0.05F; } } public float getBatRotation() { return BatRotation; } /** * Funciones que gestionan los objetos. */ @Override public int getSizeInventory() { return 1; } @Override public ItemStack getStackInSlot(int i) { return item; } @Override public ItemStack decrStackSize(int i, int count) { ItemStack itemstack = getStackInSlot(i); if (itemstack != null) { if (count >= itemstack.stackSize) { setInventorySlotContents(i, null); } else { itemstack = itemstack.splitStack(count); } } markDirty(); return itemstack; } @Override public ItemStack getStackInSlotOnClosing(int i) { ItemStack item = getStackInSlot(i); setInventorySlotContents(i, null); markDirty(); return item; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { item = itemstack; if (itemstack != null) { if (item.stackSize > getInventoryStackLimit()) { item.stackSize = getInventoryStackLimit(); } } markDirty(); } @Override public String getInventoryName() { return null; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 1; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return player.getDistanceSq(xCoord, yCoord, zCoord) <= 64; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int slotn, ItemStack itemStack) { return true; } }
October 10, 201410 yr People recommended S35PacketUpdateTileEntity. Look at TileEntityFlowerPot@getDescriptionPacket for example.
October 10, 201410 yr Author People recommended S35PacketUpdateTileEntity. Look at TileEntityFlowerPot@getDescriptionPacket for example. Okay! thanks! gonna explore that.
October 10, 201410 yr Author SOLVED Thank you very much. This is what i added to the TileEntity: public Packet getDescriptionPacket() { NBTTagCompound nbttagcompound = new NBTTagCompound(); this.writeToNBT(nbttagcompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 5, nbttagcompound); } public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); }
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.