GabrielOlvH / Industrial-Revolution

An Industrial mod made for Fabric.
Apache License 2.0
196 stars 58 forks source link

fix items not saved #374

Closed DrummerMC closed 2 years ago

GabrielOlvH commented 2 years ago

Thank for the PR, but I had already fixed it on my dev env but I just forgot to push it 😅

DrummerMC commented 2 years ago

@GabrielOlvH I looked into your change and I'm not shure if your code works correctly. https://github.com/GabrielOlvH/Industrial-Revolution/commit/9867e98bb095796e0a1f9e126da71a624c99885b#diff-219ff525b9e6ab2ee826e1dfb12e9fb0147952ed18a038fe577c49096f01c182R24 You call syncable.markForUpdate() with calls makeDirty on the next tick. If the inventory is modified from outside of your machine (item insert or extract by a neighbor machine for example) then no next tick may be exists if the cunk get unloaded.

GabrielOlvH commented 2 years ago

This is a very specific edge case which I believe is highly unlikely to happen as it has never happened in the past. The reason I don't call markDirty directly is because Minecraft's logic is pretty bad and would cause performance issues. Calling markDirty() needs to perform a #getChunk and also update every neighbor block because of comparators. This would not scale well in a large modded worlds with lots of things happening at once