Jump to content

Inventory duping - please help me understand


drceph

Recommended Posts

Hey guys,

 

I'm new to modding with forge and I have a duping bug that I want to try and get an understanding of why it happens and how these sort of things are combatted.

 

Below is a code fragment from the updateEntity() method of my TileEntity sub-class:

 

if (this.inventory[0] != null && this.inventory[0].getItem().equals(Item.coal)) {
		if (timer == 0) {
			--this.inventory[0].stackSize;
			if (this.inventory[0].stackSize == 0) {
				this.inventory[0] = null;
				onInventoryChanged();
			}
			timer = 5;
		} else {
			timer--;
		}

 

This tile entity is attached to a BlockContainer with a single inventory slot. When coal is in the slot it will decrease the coal stack by one every 5 ticks (this is fuel for an IC crossover mod, and coal is a placeholder).

 

What I find is that if I click the stack of coal as it is decreasing it will (often) pick up the stack but a phantom stack will stay in the container slot and continue to decrease. If I put my picked up stack in my inventory and try to pick up the phantom stack, it disappears.

 

My theory is that this is due to the lazy syncing between the server and client (in 1.4.2 so even SSP is client/server, if I understand it correctly). I'm guessing that on a particular tick that if I take the stack that it stops decreasing it on client side, but for some reason the server side has decreased it. This creates a discrepancy between the two and the server-side state overrides the client-side state.

 

I see the solution being a situation where some sort of syncing message is sent to the server telling it that the stack is going to be modified and to trust the client-state. I'm sure there is a solution that exists and I hear terms such as Proxies and Packets being thrown around and while I'm sure they are components of the solution, I'm not sure exactly how to approach it. I know I have some CommonProxy and ClientProxy classes set up for the GUI aspects, but these I took from a tutorial and don't yet grok them 100%.

 

Any insights, tips and assistance that improve my understanding would be greatly appreciated - even if it is simply a pointer towards to correct classes and/or documentation.

 

Cheers,

C.

 

EDIT: The onInventoryChanged() call in there was my feeble attempt at hoping there was some sort of built-in method for notification/synchronisation - please let me know if I'm wrong ;)

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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