Jump to content

[1.12.2] [UNSOLVED] TileEntity out of sync, cannot figure out the reason.


Recommended Posts

Posted (edited)

Good afternoon, modders.

 

I am in the process of creating a simple furnace-like block. This means I currently have the following classes, copied directly from the vanilla furnace: 

 

I am stuck. After a bit of debugging, I found out that the container holds the correct values, but somehow they are not correctly synchronized to the tileentity in WorldClient. The GUI displays different values from those held by the container. The thing that weirds me out the most is the fact that my code is copied directly from vanilla code, except for a few tweaks here and there.

 

The GUI opens without any problems and the inventory seems to be persistent, as far as NBT values being handled.

The weird things start happening when I try smelting ONE single 'Dust' item with my furnace: at first, fuelRemaining and fuelInitial are displayed on the GUI as whatever burn time the fuel item holds (it uses vanilla fuel), so let's say 1600 for a single coal item, and this value starts decreasing by 1 each tick. fuelInitial should NOT be decreasing at all, it should stay at 1600 until other fuel items are used. 

In the meantime, both smeltingProgress and smeltingDuration go from zero to 200 (again, smeltingDuration should be a fixed number!), and when they hit 200 their values are matched to those held by fuelRemaining and fuelInitial at the time. 

 

I find myself with a GUI displaying only one correct value, which is fuelRemaining, while the other three fields are the exact same.

I really cannot figure out why for the love of God this is happening.

 

Thanks for your precious time, I will now further investigate the possible issues of my code.

Cheers!

Edited by -fr0st-
Posted (edited)

Good morning.

I have taken your advice, and am currently upgrading my setup. One question quickly arose in my head, though: without implementing the IInventory interface, I no longer have access to getField() and setField().

 

How am I going to access my tileentity's data on the client? Should I simply create my own version of getField() and setField() that simply returns/sets the value of my fields?

For instance, take a look at this snippet of code from the tileentity class:

@SideOnly(Side.CLIENT)
public static boolean isSmelting(ITileInventory tile) {
	return ((TileAlloySmelter) tile).getField(0) > 0;
}

 

Furthermore, all my container methods are now broken for the same exact reason - IContainerLister#sendAllWindowProperties needs an IInventory argument; Container#updateProgressBar and Container#detectAndSendChanges both need getField() or setField().

 

How do I make my container properly compatible with the new system? 

Thanks for your time!

Edited by -fr0st-
Posted
6 minutes ago, -fr0st- said:

IContainerLister#sendAllWindowProperties

Just don't use it. This is for initial sync when the window is opened but you will sync all your data on the first tick anyway.

 

6 minutes ago, -fr0st- said:

Container#updateProgressBar and Container#detectAndSendChanges both need getField() or setField().

Just get and set your variables directly. get/setField are wrappers for variable access anyway. For example instead of getField(0) you would use tile.progress and instead of setField(0, value) you would use tile.progress = value. I have an example in one of my projects here.

Posted (edited)

I have finished porting my code. The behaviour reported in the original post has not ceased, wrong values are still displayed in the GUI.

 

EDIT: I have put a breakpoint in the GUI class and in the tileentity class, here are the variables at the same exact tick: GUI and TileEntity. As you can see, the tileentityes have two different ids, so there are two instances for each block, one on WorldServer with correct values, and one on WorldClient with wrong values. Is this how minecraft handles tileentities? Genuinely curious.

Edited by -fr0st-
Posted

Greetings, modders.

I have decided to completely rewrite my whole system from scratch, removing unneeded code such as ITileInventory.

At the moment I am on mobile, but as soon as I get home I will finish rewriting everything and - in case my issue persists - I will update the OP accordingly.

Thanks for your patience!

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.