Jump to content

TileEntity with gui inventory change doesn't trigger writeToNBT automatically?


Recommended Posts

Posted

I implemented a block with tileentity which has a gui and inventory using capabilities and `IItemHandler`. After some struggling everything seems to work fine except I notice that when I put something into the only slot of that block (or TE), then exit and reconnect, that something is very likely to disappear. Here are the code of that tileentity and container. This happens when I don't override `detectAndSendChanges`

  Reveal hidden contents
  Reveal hidden contents

Using some print statements I can confirm that `ItemStackHandler` in tileentity is correctly updated as soon as new items are put in (or taken out), however when exit there's no call to writeToNBT. Only after I trigger something in the client and send a packet to server, writeToNBT get called, and the changes to inventory persist. Currently the only way I found is to override `detectAndSendChanges` as show in the code. However I'm not sure is this the correct way to do this. Doesn't this should be handled automatically because from all the tutorials I read, they all basically does the same thing as mine here, and none of them mentions the necessity to override detectAndSendChanges to make the inventory behave "correctly" in common sense.

I want to ask if its I'm missing something obviously or is this override expected?

Posted

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 2/13/2018 at 6:08 PM, Draco18s said:
Expand  

After adding  override for `getUpdatePacket` and `onDataPacket` then remove `detectAndSendChanges`, its inventory still doesn't persist. The problem seems to be the inventory doesn't even stored (no writeToNBT called) on server side, not a server to client syncing problem. `getUpdatePacket` doesn't been called when I make changes to the inventory. I read it elsewhere that getUpdatePacket is called by `notifyBlockUpdate`, do I need to call it somewhere manually?

Posted
  On 2/14/2018 at 3:39 PM, diesieben07 said:

I guess I was blind when I wrote that.

 

Is your tile entity registered properly? Show your block class.

Expand  

Sorry for the late reply, here you go:

 

BlockREAnalyzer:

  Reveal hidden contents

 

and this is the registering part:

 

BlockRE:

  Reveal hidden contents

tileentity is registered in GeneralProxy, ClientProxy and ServerProxy are just inherited from it and calling super methods in 3 stages respectively.

 

  Reveal hidden contents

 

I also setup a git repo here

Posted (edited)
  On 2/15/2018 at 9:34 AM, diesieben07 said:
  • Problematic code, issue 10.
  • Code style, issue 1.
  • I can't see the issue right now, however your Git repository is incomplete, so I cannot actually debug your mod.
Expand  

I have made some changes, but I'm not sure what's missing in the git repository. I tried clone it to new folder and gradle build works just fine.

 

EDIT: Is it the missing of gradlew.bat? ok I added that.

Edited by Frefreak
Posted
  On 2/16/2018 at 9:32 AM, diesieben07 said:

I can't reproduce it at all. It works just fine.

Expand  

Have you remove that `detectAndSendChanges` in ContainerREAnalyzer.java? That issue only arise without it. And I was asking if it is really necessary or if I did something wrong elsewhere since all the tutorials I read didn't mention I also need `detectAndSendChanges`in order to make the changes detected.

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.