Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.