Empty tag compounds polluting items in player inventory
littlej541 opened this issue ยท 1 comments
Describe the bug
This bug is similar to #786 in problem and solution. That PR is waiting on an update to UMC otherwise I'd probably make a PR for this as well. The rail blueprint item causes items in the player's inventory to be contaminated with empty tag compounds that break stacking with other items of the same type. The items in question are the blocks selected for the rail bed and rail fill. It happens to every stack of that item type in the player's inventory. This only happens outside of creative mode because rails don't consume items when placed in creative and so don't go through the sequence required. The exact that causes this issue arises through this sequence:
- ItemTrackBlueprint::OnBlockClicked calls RailInfo::build
- RailInfo::build calls RailInfo::checkMaterials
- RailInfo::checkMaterials calls ItemGauge::has on ItemStacks of the rail bed and rail fill material
- ItemGauge::has calls ItemStack::getTagCompound on the ItemStacks from above
getTagCompound() is the root cause of the issue. When getTagCompound() is called, if the tag compound for the item is null, as it is for many items, it creates an empty tag compound for it. This may be desired elsewhere but it causes a problem in this situation.
How to reproduce
Steps to reproduce the unwanted behavior:
- Be outside of creative mode
- Get a track blueprint
- Set rail fill and/or bed to something other than air
- Build the track
- Get new blocks of the same type use for the rail fill/bed
- These new blocks will not stack with the old unless another track section is built with the same blocks as fill/bed, causing them to be given empty tag compounds as well
Expected behavior
Items without tag compounds should not acquire them randomly, and should remain null to preserve stacking capabilities.
System Information
- IR-Version: 1.7.3_1.12.2
- Forge-Version: 1.12.2-14.23.4.2705, 1.12.2-14.23.5.2854
Additional context
The easy fix would be to store the result to be returned in ItemGauge::has, clear the tag compound set after calling ItemStack::getTagCompound with ItemStack::clearTagCompound if it was supposed to be null, then return the stored result.
I am pretty sure d7ca08a inadvertently fixed this. Closing as it will be in the next release.
Thanks for the super detailed report!