Create

Create

86M Downloads

Backtank custom mod data isn't being preserved when it's placed in block form

CsiPA0723 opened this issue ยท 2 comments

commented

Describe the Bug

When placing down any backtank with Cold Sweat's insulating lining sewed into it, and then picking it up, the lining disappears from the backtank.

Issue from Cold Sweat's Github: Momo-Softworks/Cold-Sweat#174

Reproduction Steps

  1. Install both Create and Cold Sweat
  2. Grab a backtank and sew some insulation into it
  3. Place it down and pick it up
  4. Insulation gone

Expected Result

To keep insulation data

Operating System

  • Windows 11

Mod Version

  • 0.5.1f

Minecraft Version

  • 1.20.1

Forge Version

  • 47.2.20
commented

It's a bit more broad than just custom mod data. Any nbt data that is not the name, air level or enchantments isn't passed to the block entity. So this will also effect vanilla mechanics such as lore strings, attribute modifiers or the adventure mode CanDestroy and CanPlaceOn flags.
Relevant code:

withBlockEntityDo(worldIn, pos, be -> {
be.setCapacityEnchantLevel(EnchantmentHelper.getItemEnchantmentLevel(AllEnchantments.CAPACITY.get(), stack));
be.setAirLevel(stack.getOrCreateTag()
.getInt("Air"));
if (stack.isEnchanted())
be.setEnchantmentTag(stack.getEnchantmentTags());
if (stack.hasCustomHoverName())
be.setCustomName(stack.getHoverName());
});

Then in the read and write functions (for loading from/saving to disk) of BacktankBlockEntity the loot tables (for breaking by hand), and the getCloneItemStack function (for right click equipping) of the BanktankBlock, only this data is available (and thus used) when retrieving the item from the placed block.

commented

We had a similar problem with Apotheosis affixes getting removed from our tanks/jetpacks when it was placed in the world for recharge. We solved it by adding a command block to recharge it by resetting the Air tag value directly on the tank. Doing it while on a player turned out to be really problematic, so we created a charging station chest (we used a shulker box, but any vanilla storage will do). The command block looks in the chest selects the top left item, and then sets the air in the tank to 3000 (this is the value of a netherite tank with Capacity VII on it).

The command we used in the command block: /data modify block 367 96 -331 Items[0].tag merge value {Air:3000}
We used this command to get the max value for our tanks: /data get block 367 96 -331 Items[0].tag.Air

This method isnt perfect. For one, it will put an NBT tag for air on ANYTHING in that slot when the button is pressed. Secondly, it has no way to know if its a plain unenchanted copper backtank, or a fully enchanted/gemmed/affixed/etc netherite jetpack. As such, the copper tank's capacity is bigger than it should be.

Not a solution, but a usable workaround until this code is updated.