Jump to content

[1.12] Creative inventory bidirectional ItemStack handling breaking my ItemHandler capability


Recommended Posts

Posted

So I was doing some reading trying to figure out why my item with an itemhandler capability was losing all of its items when it changed slots in creative on the server- and someone on the MMD discord mentioned that the client handles inventory in creative.

I found this:
http://www.minecraftforge.net/forum/topic/27248-player-inventory-synchronization/

Quote

1. If you remove ItemStack from player.inventory on both sides, no matter what - both will loose the stack (and yeah, that's 100%).

2. If only on client - obviously you'll be out of sync and if you would swap that slot with other item, second one would appear (server will synchro you)

 

3. BUT now - what you are doing is setting only on server. Funny thing here is gamemode.

When in survival you client will go out of sync like in point 2. (and will most likely update with upcoming packet), but if you are in creative there is something like creative inventory - that's where magic happens, you see, when in creative server allows CLIENT to actually SEND ItemStacks - processes are not Server -> Client, but "reciprocal" (whetever this word means - doublt-sided/Bi-directional). You can edit anything you want, therefore if you would remove itemStack on server-side, but not on client, if you try to use removed-on-server item in this nulled slot, item will dissappear (server resynchronizes client when item is used) BUT if you would move this server-nulled item to other slot, then it's treated like one generated by creative inventory - and send from Client to Server. Server normally saves it to your server-side inventory.

So apparently I'm doing something wrong with my cap provider/deserialization or something that is causing the client to not get the right items in the right spot.

What I mean by "changing slots" is I will take the bag, move it from slot 1 on my hotbar to slot 2 and all the items will have disappeared. (It's a GUI, and definitely not desync, relogging fixes nothing).

Otherwise works fine in survival on server and on the client (although I have noticed it a few times in creative on the client - possibly the effective server thread is responsible)

 

Capability Provider:

https://github.com/BuiltBrokenModding/SBM-DeadMansSatchel/blob/master/src/main/java/com/builtbroken/deadmanssatchel/item/SatchelCapabilityProvider.java

Item:

https://github.com/BuiltBrokenModding/SBM-DeadMansSatchel/blob/master/src/main/java/com/builtbroken/deadmanssatchel/item/ItemDeadMansSatchel.java

Container:

https://github.com/BuiltBrokenModding/SBM-DeadMansSatchel/blob/master/src/main/java/com/builtbroken/deadmanssatchel/item/ContainerSatchel.java

Not sure if I should be using the NBT argument from initCapabilities somehow. Is there a way to force handling on the server for my container - even in creative?

 

Posted
2 minutes ago, diesieben07 said:

I cannot find you registering your capability anywhere.

I need to "register" my capability? How? Isn't already registered as an itemhandler capability, like builtin?

Posted
1 minute ago, diesieben07 said:

Yeah, I'm an idiot. Of course not.

 

Your isEmpty check in hasCapability could be a problem. Why do you have that there?

Doesn't really matter - same bug happens with or without it. Had it originally, removed it, re-added, nothing.

Posted
1 minute ago, diesieben07 said:

Okay. And this bug occurs only when in creative?

Yep.

Posted

Dunno if you ever found a *real* fix - but my fix was disabling it in creative (the item has no use in creative, it's a bag that returns even after you die)

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.