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 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 ;)

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.