-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ItemStack changes not synced if LocalPlayer #407
Comments
That check exists only on NeoForge because it otherwise caused syncing issues in the curio inventory for the local player once Curios migrated over to their new data attachment system. Can you provide more specific reproduction steps in regards to the data you're writing and reading on the client? Also, does this occur in a single-player instance or while connected on a dedicated server? I'm having a hard time reproducing this on my end, as any changes I've attempted are read and synced appropriately, but I suspect this may just be due to the exact nature of the data we're respectively attempting to sync. |
Sorry about the lack of details. I reported it late at night my time so I might have rushed and missed some details. I'm going to do a test today on a clean workspace that I can share with you. But to answer your questions, it was on singleplayer. I haven't tested on a dedicated server. |
Alright, here is a test mod showcasing the issue. This is running on 1.20.6 with NeoForge. I've added some comments on demonstrating the problem. If you have any questions, let me know. |
Thanks, that should be enough information for now. I am able to reproduce this issue now, at least on 1.20.6. I'll need to re-test some of this on 1.20.4, which is showing some strangely divergent behavior. It looks like this check might be unnecessary on 1.20.6, which would solve the problem entirely if I could just remove it, but still causes syncing issues if removed on 1.20.4. I'll do some more digging and testing to figure out what's going on exactly and what the ideal solution is for each version. |
Before I start this off, I reversed your bug fix by adding a non-suspending breakpoint with the condition I did some digging into the issue. I am going to guess that the sync issue you were fixing is related to putting the item into the curio slot and it disappearing. To make things short, Here is how to test this:
ItemStack doesn't have a hashCode() implementation, so it is just using the JVM hash. Provided they are the same, we can safely assume the client/server are retrieving the same object in memory. If you look at the stacktrace of Above on line 416 is where the item is retrieved, and this is where it starts going into NeoForge's code. Moving into To push forward further, the Now here is what I discovered... The And here is the simple fix for the problem. In the handling of and of course, remove the LocalPlayer check. It's time for me to go to bed. |
Hmm, very interesting findings. It does thoroughly explain what's going on, which you are correct to assume that the original bug that appeared was related to putting the item into the curio slot and it disappearing. I had originally assumed there was syncing happening in the data attachment and that it was caused by a race condition in the inventory data when applied on the It also explains why this doesn't appear to happen in 1.20.6 (without just the I'm glad to see that it's a very simple fix though, I'll try to have an update out tonight at some point. Thank you very much for the thorough investigation, I really appreciate it. |
I forgot to mention what finally happens. Since The Glad I could help, just trying to get my mods updated :') |
So basically make sure you copy objects on the receiving end if you're developing prior to 1.20.6. This is not exclusive to ItemStacks. You can use |
Minecraft Version
1.20.4
What happened?
I am currently updating my mod to 1.20.4, and I've run into a problem. I am trying to update some data to the client using
ICurio#writeSyncData
andICurio#readSyncData
. TheItemStack
passed into theICurio#readSyncData
call, presumably theItemStack
that I should be updating with my custom data, is completely ignored. I've looked into your code and it seem in the handling ofSPacketSyncStack
that if the target entity is a LocalPlayer, it will never update the item in thestacksHandler
.This behaviour is only present in the NeoForge version of the mod. The check for LocalPlayer does not exist in the Forge version.
NeoForge handling: (The code in question)
https://github.com/TheIllusiveC4/Curios/blob/1.20.4/neoforge/src/main/java/top/theillusivec4/curios/common/network/client/CuriosClientPayloadHandler.java#L296-L302
Forge handling: (No localplayer check)
https://github.com/TheIllusiveC4/Curios/blob/1.20.4/forge/src/main/java/top/theillusivec4/curios/common/network/server/sync/SPacketSyncStack.java#L89-L93
How do you trigger this bug?
ICurio#writeSyncData
andICurio#readSyncData
ItemStack
passed inICurio#readSyncData
with the custom dataItemStack
in the curios slot with the local player (Minecraft.getMinecraft().player
)ItemStack
will not have the custom dataLoader
NeoForge
Loader Version
20.4.190
Mod Version
7.4.0+1.20.4
Relevant Log Outputs
No response
The text was updated successfully, but these errors were encountered: