Posted September 7, 201510 yr hey, I need to sync TE on client and server side because changes only occur on server side. I use getDescriptionPacket() and onDataPacket(). The problem is that TE implements ISidedInventory and I cannot sync the stacks from ItemStack[] if the stack is null, but that is necessary. If I clear the inventory on server side the client doesn't care. @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); NBTTagList invList = tag.getTagList("Inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < invList.tagCount(); i++) { NBTTagCompound stackTag = invList.getCompoundTagAt(i); int slot = stackTag.getByte("Slot"); if (slot >= 0 && slot < inv.length) inv[slot] = ItemStack.loadItemStackFromNBT(stackTag); } active = tag.getBoolean("active"); processing = tag.getBoolean("processing"); cooldown = tag.getInteger("cooldown"); name = tag.getString("name"); NBTTagCompound st = (NBTTagCompound) tag.getTag("stack"); stack = ItemStack.loadItemStackFromNBT(st); } @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); NBTTagList invList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { if (inv[i] != null) { NBTTagCompound stackTag = new NBTTagCompound(); stackTag.setByte("Slot", (byte) i); inv[i].writeToNBT(stackTag); invList.appendTag(stackTag); } } tag.setBoolean("active", active); tag.setBoolean("processing", processing); tag.setInteger("cooldown", cooldown); if (name != null && !name.equals("")) tag.setString("name", name); NBTTagCompound st = new NBTTagCompound(); if (stack != null) stack.writeToNBT(st); tag.setTag("stack", st); tag.setTag("Inventory", invList); } @Override public Packet getDescriptionPacket() { NBTTagCompound syncData = new NBTTagCompound(); this.writeToNBT(syncData); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, syncData); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readFromNBT(pkt.func_148857_g()); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); }
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.