Industrial Foregoing

Industrial Foregoing

95M Downloads

null nbt tag is being applied to items in black hole unit

DoomSquirter opened this issue ยท 1 comments

commented

see other issue on farscapes github:
Beyond-Reality/Beyond-Realty-Farscapes#38

over a week ago, I had verified that the BHU that contained wood from my farm had the null nbt removed and that all new wood coming in (and existing) would not have the extra (NBT: (0) tags) added to it.

I have > 400k of spruce wood in this bhu and it has not emptied in the last week.

I noticed yesterday that now it does have the null nbt tag on it, meaning, all spruce being exported from that BHU will not stack with any normal spruce that has no nbt tags.

I feel fairly confident the issue's occurring to the BHU itself. It does seem that anything that gets put into a BHU is subject to the null nbt tag.

commented

That's caused by basically, well, this entire method: https://github.com/Buuz135/Industrial-Foregoing/blob/master/src/main/java/com/buuz135/industrial/tile/misc/BlackHoleUnitTile.java#L150
@Buuz135 you don't need to check compound.hasKey unless you need another fallback that isn't the default. All NBTTagCompound get methods are nonnull and have a fallback.
IE, this compound.hasKey(NBT_META) ? compound.getInteger(NBT_META) : 0 can just be compound.getInteger(NBT_META) with the same effect.

Either way, on to the reason there's the blank itemstack tag:
In readFromNbt, you check
if (compound.hasKey(NBT_ITEM_NBT)) stack.setTagCompound(compound.getCompoundTag(NBT_ITEM_NBT));
But, this is always true, since you do tagCompound.setTag(NBT_ITEM_NBT, stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound());
in writeToNbt.

This may be best to continue doing in writeToNbt, but this line should change in readFromNbt
if (compound.hasKey(NBT_ITEM_NBT)) stack.setTagCompound(compound.getCompoundTag(NBT_ITEM_NBT));
should become
NBTTagCompound nbttag = compound.getCompoundTag(NBT_ITEM_NBT);
if(!nbttag.hasNoTags()) stack.setTagCompound(nbttag);