
Inserting items into barrels fails after world reload with Astral Sorcery installed
tommyTT opened this issue ยท 7 comments
Bug
As we discussed in my other bug report, I had trouble with the barrels "sometimes" not accepting items. I now was able to reliably reproduce it, It's a problem with the serialization of the Barrel TileEntity that shows up if e.g. Astral Sorcery (tested with version 1.12.2-1.9.1) is present and attaches forge capabilities. This is very similar to #243 that is already fixed.
Steps to reproduce
- Put down a barrel and insert more than 2 Stacks of items (>127 items), e.g. stone.
- Log out of the world and log back in.
- Try inserting more stone in the barrel.
The barrel won't accept the additional items. You can even take out some items from the barrel and you're not able to put them back again. You can only insert items into the barrel once it is empty.
Versions
Minecraft: 1.12.2
Forge: 1.12.2-14.23.4.2703
Charset: Latest dev version from git.asie.pl (Revision: e902895)
Astral Sorcery: 1.12.2-1.9.1 (added through libs folder in dev environment)
Diagnosis
When trying to insert the items, the current item stack representing the barrel content is compared to the item stack that should be inserted into the barrel. This includes a compatibility check for the attached forge capabilities. In this case the check fails because the two item stacks have different capabilities after a world reload. The item stack representing the content of the barrel has the Astral Sorcery AmuletHolderCapability, the item stack from the player inventory doesn't have that capability.
The problem occurs during deserialization when the new ItemStack is constructed from the serialized NBT data. The serialization of the Barrel TileEntity wrote the entire item stack including the item count to the NBT tag. This causes a similar problem to #243 because on deserialization from the NBT tag the item stack can temporarily have a negative item count (byte overflow). The constructor for the ItemStack calls the forge event to attach all capabilities, so when the Astral Sorcery one is asked it checks the item stack and because of the negative count the isEmpty method returns true. In that case the Astral Sorcery capability is attached (which is a bit questionable in my opinion and I will report it to the AS devs) and the item stacks that you can retrieve in the world (without the AS capability) no longer matches.
Wow. That is impressive. You've won Bug Hunter of the month, possibly of the year.
@tommyTT Could you try with the latest Git version on git.asie.pl? (It should also fix existing barrels, by the way. There's a provision in the code for that.)
Happy to help, this gives me a better understanding of the inner workings of Minecraft.
I will try it as soon as I can see the commit on git.asie.pl. The Astral Sorcery side is also fixed already.
Thanks for the quick help!
@tommyTT Sorry, I forgot about having previously committed on another machine (for the map compass tweak). It's there now.
I'm still impressed by just how intricate that bug was.