fix backtank nbt not saving

ForgeCaps don't save yet either though
This commit is contained in:
VoidLeech 2024-07-05 00:16:28 +02:00
parent 75d337ba8c
commit f20dbd5cae
No known key found for this signature in database
7 changed files with 51 additions and 7 deletions

View file

@ -3329,7 +3329,7 @@ c2b075008849e152f20e8da946e89c9722325df6 data/create/loot_tables/blocks/content_
69b4b25d7d271458177fbbaeba2c797daccc38a2 data/create/loot_tables/blocks/contraption_controls.json 69b4b25d7d271458177fbbaeba2c797daccc38a2 data/create/loot_tables/blocks/contraption_controls.json
28856dc862efc6bcc421d035d26386740458f868 data/create/loot_tables/blocks/controller_rail.json 28856dc862efc6bcc421d035d26386740458f868 data/create/loot_tables/blocks/controller_rail.json
2c2785e39e1891dff2c50cba93e814b56d935154 data/create/loot_tables/blocks/controls.json 2c2785e39e1891dff2c50cba93e814b56d935154 data/create/loot_tables/blocks/controls.json
3abf04f6132955275ad490668cd28f481afb4ec2 data/create/loot_tables/blocks/copper_backtank.json 830949a5dc64982392db2c1f651d2a9d0ff659a8 data/create/loot_tables/blocks/copper_backtank.json
6697e619d5c6dcb81aad4f5c88ba319d13665b35 data/create/loot_tables/blocks/copper_bars.json 6697e619d5c6dcb81aad4f5c88ba319d13665b35 data/create/loot_tables/blocks/copper_bars.json
8010db6b2427536c74312c85425b3ba83abc363c data/create/loot_tables/blocks/copper_casing.json 8010db6b2427536c74312c85425b3ba83abc363c data/create/loot_tables/blocks/copper_casing.json
ea5fb942c8dfb792daac538e09d286ac120aa199 data/create/loot_tables/blocks/copper_door.json ea5fb942c8dfb792daac538e09d286ac120aa199 data/create/loot_tables/blocks/copper_door.json
@ -3590,7 +3590,7 @@ afdff197c9d1a6940e988c00435135f9705fd0e5 data/create/loot_tables/blocks/metal_gi
b83a90fbe83906b171fc0de6bdc2d9aa3a8c542e data/create/loot_tables/blocks/millstone.json b83a90fbe83906b171fc0de6bdc2d9aa3a8c542e data/create/loot_tables/blocks/millstone.json
5c1df8443043b3fe3b665dba348e2ff188bcbe31 data/create/loot_tables/blocks/minecart_anchor.json 5c1df8443043b3fe3b665dba348e2ff188bcbe31 data/create/loot_tables/blocks/minecart_anchor.json
1e73d28fdd2e54910074aeadbe5617425a8ae656 data/create/loot_tables/blocks/mysterious_cuckoo_clock.json 1e73d28fdd2e54910074aeadbe5617425a8ae656 data/create/loot_tables/blocks/mysterious_cuckoo_clock.json
a5fa8fdc10efe534e5c7d8bdb687f226b39f63ef data/create/loot_tables/blocks/netherite_backtank.json 9be92bab82bc1e83533f1d4679b09bd0513b07eb data/create/loot_tables/blocks/netherite_backtank.json
2e21a06c0d671e543bffecb0b67d97b51fa83ddc data/create/loot_tables/blocks/nixie_tube.json 2e21a06c0d671e543bffecb0b67d97b51fa83ddc data/create/loot_tables/blocks/nixie_tube.json
f6b4095a518a01081f3663d7268d67063bdb44ee data/create/loot_tables/blocks/nozzle.json f6b4095a518a01081f3663d7268d67063bdb44ee data/create/loot_tables/blocks/nozzle.json
d378be8f13fc7ed625813eae3a50b68e8706a297 data/create/loot_tables/blocks/oak_window.json d378be8f13fc7ed625813eae3a50b68e8706a297 data/create/loot_tables/blocks/oak_window.json
@ -5012,7 +5012,7 @@ e6aa8895186358e9d069f5a99909132be49f3bf1 data/create/recipes/diorite_from_stone_
a90268d38f976327ff5e1b87ff1d72ca2d1ebad6 data/create/recipes/dripstone_block_from_stone_types_dripstone_stonecutting.json a90268d38f976327ff5e1b87ff1d72ca2d1ebad6 data/create/recipes/dripstone_block_from_stone_types_dripstone_stonecutting.json
27d9bf05a610447e90314e658dbbcd191f378fc9 data/create/recipes/dripstone_pillar_from_stone_types_dripstone_stonecutting.json 27d9bf05a610447e90314e658dbbcd191f378fc9 data/create/recipes/dripstone_pillar_from_stone_types_dripstone_stonecutting.json
d81ceba2946286d374801e698a4ca2116395cbad data/create/recipes/emptying/builders_tea.json d81ceba2946286d374801e698a4ca2116395cbad data/create/recipes/emptying/builders_tea.json
318ab703224ff1d6f7200675e1e0a4c138b28456 data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json d62f4682fe6cc61df5a1c0231a2004a4ee78a329 data/create/recipes/emptying/compat/alexsmobs/lava_bottle.json
c26d003e921720308c05ad7b9f3cb57de94a10a8 data/create/recipes/emptying/compat/farmersdelight/milk_bottle.json c26d003e921720308c05ad7b9f3cb57de94a10a8 data/create/recipes/emptying/compat/farmersdelight/milk_bottle.json
60c0edfb5b759e4f13427b631861f503f8552923 data/create/recipes/emptying/compat/neapolitan/milk_bottle.json 60c0edfb5b759e4f13427b631861f503f8552923 data/create/recipes/emptying/compat/neapolitan/milk_bottle.json
20b7c7c62fa2e33199e08188dd8836844a6d9cfd data/create/recipes/emptying/honey_bottle.json 20b7c7c62fa2e33199e08188dd8836844a6d9cfd data/create/recipes/emptying/honey_bottle.json

View file

@ -8,6 +8,17 @@
{ {
"type": "minecraft:item", "type": "minecraft:item",
"functions": [ "functions": [
{
"function": "minecraft:copy_nbt",
"source": "block_entity",
"ops": [
{
"source": "FullNBT",
"target": "{}",
"op": "merge"
}
]
},
{ {
"function": "minecraft:copy_name", "function": "minecraft:copy_name",
"source": "block_entity" "source": "block_entity"

View file

@ -8,6 +8,17 @@
{ {
"type": "minecraft:item", "type": "minecraft:item",
"functions": [ "functions": [
{
"function": "minecraft:copy_nbt",
"source": "block_entity",
"ops": [
{
"source": "FullNBT",
"target": "{}",
"op": "merge"
}
]
},
{ {
"function": "minecraft:copy_name", "function": "minecraft:copy_name",
"source": "block_entity" "source": "block_entity"

View file

@ -16,7 +16,7 @@
], ],
"conditions": [ "conditions": [
{ {
"modid": "atmospheric", "modid": "alexsmobs",
"type": "forge:mod_loaded" "type": "forge:mod_loaded"
} }
] ]

View file

@ -83,7 +83,7 @@ public class BacktankBlock extends HorizontalKineticBlock
@Override @Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState,
LevelAccessor world, BlockPos pos, BlockPos neighbourPos) { LevelAccessor world, BlockPos pos, BlockPos neighbourPos) {
if (state.getValue(BlockStateProperties.WATERLOGGED)) if (state.getValue(BlockStateProperties.WATERLOGGED))
world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
return state; return state;
} }
@ -121,6 +121,7 @@ public class BacktankBlock extends HorizontalKineticBlock
be.setEnchantmentTag(stack.getEnchantmentTags()); be.setEnchantmentTag(stack.getEnchantmentTags());
if (stack.hasCustomHoverName()) if (stack.hasCustomHoverName())
be.setCustomName(stack.getHoverName()); be.setCustomName(stack.getHoverName());
be.setFullNbt(stack.getOrCreateTag());
}); });
} }
@ -157,9 +158,10 @@ public class BacktankBlock extends HorizontalKineticBlock
ItemStack stack = new ItemStack(item); ItemStack stack = new ItemStack(item);
Optional<BacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(blockGetter, pos); Optional<BacktankBlockEntity> blockEntityOptional = getBlockEntityOptional(blockGetter, pos);
CompoundTag tag = blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(stack.getOrCreateTag());
int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel)
.orElse(0); .orElse(0);
CompoundTag tag = stack.getOrCreateTag();
tag.putInt("Air", air); tag.putInt("Air", air);
ListTag enchants = blockEntityOptional.map(BacktankBlockEntity::getEnchantmentTag) ListTag enchants = blockEntityOptional.map(BacktankBlockEntity::getEnchantmentTag)
@ -174,6 +176,7 @@ public class BacktankBlock extends HorizontalKineticBlock
.orElse(null); .orElse(null);
if (customName != null) if (customName != null)
stack.setHoverName(customName); stack.setHoverName(customName);
stack.setTag(tag);
return stack; return stack;
} }
@ -187,7 +190,7 @@ public class BacktankBlock extends HorizontalKineticBlock
public Class<BacktankBlockEntity> getBlockEntityClass() { public Class<BacktankBlockEntity> getBlockEntityClass() {
return BacktankBlockEntity.class; return BacktankBlockEntity.class;
} }
@Override @Override
public BlockEntityType<? extends BacktankBlockEntity> getBlockEntityType() { public BlockEntityType<? extends BacktankBlockEntity> getBlockEntityType() {
return AllBlockEntityTypes.BACKTANK.get(); return AllBlockEntityTypes.BACKTANK.get();

View file

@ -37,10 +37,13 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
private int capacityEnchantLevel; private int capacityEnchantLevel;
private ListTag enchantmentTag; private ListTag enchantmentTag;
private CompoundTag fullNbt;
public BacktankBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { public BacktankBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state); super(type, pos, state);
defaultName = getDefaultName(state); defaultName = getDefaultName(state);
enchantmentTag = new ListTag(); enchantmentTag = new ListTag();
fullNbt = new CompoundTag();
} }
public static Component getDefaultName(BlockState state) { public static Component getDefaultName(BlockState state) {
@ -118,6 +121,7 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
if (this.customName != null) if (this.customName != null)
compound.putString("CustomName", Component.Serializer.toJson(this.customName)); compound.putString("CustomName", Component.Serializer.toJson(this.customName));
compound.put("Enchantments", enchantmentTag); compound.put("Enchantments", enchantmentTag);
compound.put("FullNBT", fullNbt);
} }
@Override @Override
@ -128,6 +132,7 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
airLevel = compound.getInt("Air"); airLevel = compound.getInt("Air");
airLevelTimer = compound.getInt("Timer"); airLevelTimer = compound.getInt("Timer");
enchantmentTag = compound.getList("Enchantments", Tag.TAG_COMPOUND); enchantmentTag = compound.getList("Enchantments", Tag.TAG_COMPOUND);
this.fullNbt = compound.getCompound("FullNBT");
if (compound.contains("CustomName", 8)) if (compound.contains("CustomName", 8))
this.customName = Component.Serializer.fromJson(compound.getString("CustomName")); this.customName = Component.Serializer.fromJson(compound.getString("CustomName"));
if (prev != 0 && prev != airLevel && airLevel == BacktankUtil.maxAir(capacityEnchantLevel) && clientPacket) if (prev != 0 && prev != airLevel && airLevel == BacktankUtil.maxAir(capacityEnchantLevel) && clientPacket)
@ -182,4 +187,14 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable
this.capacityEnchantLevel = capacityEnchantLevel; this.capacityEnchantLevel = capacityEnchantLevel;
} }
public CompoundTag getFullNbt()
{
return fullNbt;
}
public void setFullNbt(CompoundTag fullNbt)
{
this.fullNbt = fullNbt;
}
} }

View file

@ -73,6 +73,8 @@ import net.minecraft.world.level.storage.loot.LootTable.Builder;
import net.minecraft.world.level.storage.loot.entries.LootItem; import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; import net.minecraft.world.level.storage.loot.functions.CopyNameFunction;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
import net.minecraft.world.level.storage.loot.functions.SetNbtFunction;
import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition; import net.minecraft.world.level.storage.loot.predicates.ExplosionCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
@ -435,6 +437,8 @@ public class BuilderTransformers {
.when(survivesExplosion) .when(survivesExplosion)
.setRolls(ConstantValue.exactly(1)) .setRolls(ConstantValue.exactly(1))
.add(LootItem.lootTableItem(drop.get()) .add(LootItem.lootTableItem(drop.get())
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY)
.copy("FullNBT", "{}", CopyNbtFunction.MergeStrategy.MERGE))
.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)) .apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY))
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY)
.copy("Air", "Air")) .copy("Air", "Air"))