diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index e8b04142f..ab3d01d23 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -3329,7 +3329,7 @@ c2b075008849e152f20e8da946e89c9722325df6 data/create/loot_tables/blocks/content_ 69b4b25d7d271458177fbbaeba2c797daccc38a2 data/create/loot_tables/blocks/contraption_controls.json 28856dc862efc6bcc421d035d26386740458f868 data/create/loot_tables/blocks/controller_rail.json 2c2785e39e1891dff2c50cba93e814b56d935154 data/create/loot_tables/blocks/controls.json -830949a5dc64982392db2c1f651d2a9d0ff659a8 data/create/loot_tables/blocks/copper_backtank.json +ac15351000c44cf0924e8e3b3c6d92e3d54bb084 data/create/loot_tables/blocks/copper_backtank.json 6697e619d5c6dcb81aad4f5c88ba319d13665b35 data/create/loot_tables/blocks/copper_bars.json 8010db6b2427536c74312c85425b3ba83abc363c data/create/loot_tables/blocks/copper_casing.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 5c1df8443043b3fe3b665dba348e2ff188bcbe31 data/create/loot_tables/blocks/minecart_anchor.json 1e73d28fdd2e54910074aeadbe5617425a8ae656 data/create/loot_tables/blocks/mysterious_cuckoo_clock.json -9be92bab82bc1e83533f1d4679b09bd0513b07eb data/create/loot_tables/blocks/netherite_backtank.json +188de41337119f55117c48eeb8d31cdf12cebd76 data/create/loot_tables/blocks/netherite_backtank.json 2e21a06c0d671e543bffecb0b67d97b51fa83ddc data/create/loot_tables/blocks/nixie_tube.json f6b4095a518a01081f3663d7268d67063bdb44ee data/create/loot_tables/blocks/nozzle.json d378be8f13fc7ed625813eae3a50b68e8706a297 data/create/loot_tables/blocks/oak_window.json diff --git a/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json b/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json index 2ae4e172a..f06a7a321 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json +++ b/src/generated/resources/data/create/loot_tables/blocks/copper_backtank.json @@ -13,16 +13,12 @@ "source": "block_entity", "ops": [ { - "source": "FullNBT", + "source": "VanillaTag", "target": "{}", "op": "merge" } ] }, - { - "function": "minecraft:copy_name", - "source": "block_entity" - }, { "function": "minecraft:copy_nbt", "source": "block_entity", @@ -33,17 +29,6 @@ "op": "replace" } ] - }, - { - "function": "minecraft:copy_nbt", - "source": "block_entity", - "ops": [ - { - "source": "Enchantments", - "target": "Enchantments", - "op": "replace" - } - ] } ], "name": "create:copper_backtank" diff --git a/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json b/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json index dde8be2fa..337fb1e51 100644 --- a/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json +++ b/src/generated/resources/data/create/loot_tables/blocks/netherite_backtank.json @@ -13,16 +13,12 @@ "source": "block_entity", "ops": [ { - "source": "FullNBT", + "source": "VanillaTag", "target": "{}", "op": "merge" } ] }, - { - "function": "minecraft:copy_name", - "source": "block_entity" - }, { "function": "minecraft:copy_nbt", "source": "block_entity", @@ -33,17 +29,6 @@ "op": "replace" } ] - }, - { - "function": "minecraft:copy_nbt", - "source": "block_entity", - "ops": [ - { - "source": "Enchantments", - "target": "Enchantments", - "op": "replace" - } - ] } ], "name": "create:netherite_backtank" diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java index aa07e001f..62f78e3c8 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlock.java @@ -1,11 +1,15 @@ package com.simibubi.create.content.equipment.armor; +import java.util.List; import java.util.Optional; import com.simibubi.create.AllBlockEntityTypes; import com.simibubi.create.AllEnchantments; import com.simibubi.create.AllShapes; import com.simibubi.create.content.kinetics.base.HorizontalKineticBlock; +import com.simibubi.create.content.schematics.requirement.ISpecialBlockItemRequirement; +import com.simibubi.create.content.schematics.requirement.ItemRequirement; +import com.simibubi.create.content.schematics.requirement.ItemRequirement.ItemUseType; import com.simibubi.create.foundation.block.IBE; import net.minecraft.core.BlockPos; @@ -13,8 +17,6 @@ import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; @@ -34,6 +36,7 @@ import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition.Builder; @@ -41,13 +44,14 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraftforge.common.util.FakePlayer; -public class BacktankBlock extends HorizontalKineticBlock - implements IBE, SimpleWaterloggedBlock { +public class BacktankBlock extends HorizontalKineticBlock implements IBE, SimpleWaterloggedBlock, ISpecialBlockItemRequirement { public BacktankBlock(Properties properties) { super(properties); @@ -81,8 +85,8 @@ public class BacktankBlock extends HorizontalKineticBlock } @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, - LevelAccessor world, BlockPos pos, BlockPos neighbourPos) { + public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, LevelAccessor world, + BlockPos pos, BlockPos neighbourPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); return state; @@ -114,17 +118,46 @@ public class BacktankBlock extends HorizontalKineticBlock if (stack == null) return; 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()); + be.setCapacityEnchantLevel( + EnchantmentHelper.getItemEnchantmentLevel(AllEnchantments.CAPACITY.get(), stack)); + CompoundTag vanillaTag = stack.getOrCreateTag(); + be.setAirLevel(vanillaTag.getInt("Air")); if (stack.hasCustomHoverName()) be.setCustomName(stack.getHoverName()); - be.setFullNbt(stack.getOrCreateTag()); + + CompoundTag nbt = stack.serializeNBT(); + CompoundTag forgeCapsTag = nbt.contains("ForgeCaps") ? nbt.getCompound("ForgeCaps") : null; + be.setTags(vanillaTag, forgeCapsTag); }); } + @Override + @SuppressWarnings("deprecation") + // Re-adding ForgeCaps to item here as there is no loot function that can modify + // outside of the vanilla tag + public List getDrops(BlockState pState, LootContext.Builder pBuilder) { + List lootDrops = super.getDrops(pState, pBuilder); + + BlockEntity blockEntity = pBuilder.getOptionalParameter(LootContextParams.BLOCK_ENTITY); + if (!(blockEntity instanceof BacktankBlockEntity bbe)) + return lootDrops; + + CompoundTag forgeCapsTag = bbe.getForgeCapsTag(); + if (forgeCapsTag == null) + return lootDrops; + + return lootDrops.stream() + .map(stack -> { + if (!(stack.getItem() instanceof BacktankItem)) + return stack; + + ItemStack modifiedStack = new ItemStack(stack.getItem(), stack.getCount(), forgeCapsTag.copy()); + modifiedStack.setTag(stack.getTag()); + return modifiedStack; + }) + .toList(); + } + @Override public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { @@ -151,32 +184,21 @@ public class BacktankBlock extends HorizontalKineticBlock @Override public ItemStack getCloneItemStack(BlockGetter blockGetter, BlockPos pos, BlockState state) { Item item = asItem(); - if (item instanceof BacktankItem.BacktankBlockItem placeable) { + if (item instanceof BacktankItem.BacktankBlockItem placeable) item = placeable.getActualItem(); - } - ItemStack stack = new ItemStack(item); Optional blockEntityOptional = getBlockEntityOptional(blockGetter, pos); - CompoundTag tag = blockEntityOptional.map(BacktankBlockEntity::getFullNbt).orElse(stack.getOrCreateTag()); - + CompoundTag forgeCapsTag = blockEntityOptional.map(BacktankBlockEntity::getForgeCapsTag) + .orElse(null); + CompoundTag vanillaTag = blockEntityOptional.map(BacktankBlockEntity::getVanillaTag) + .orElse(new CompoundTag()); int air = blockEntityOptional.map(BacktankBlockEntity::getAirLevel) .orElse(0); - tag.putInt("Air", air); - ListTag enchants = blockEntityOptional.map(BacktankBlockEntity::getEnchantmentTag) - .orElse(new ListTag()); - if (!enchants.isEmpty()) { - ListTag enchantmentTagList = stack.getEnchantmentTags(); - enchantmentTagList.addAll(enchants); - tag.put("Enchantments", enchantmentTagList); - } - - Component customName = blockEntityOptional.map(BacktankBlockEntity::getCustomName) - .orElse(null); - if (customName != null) - stack.setHoverName(customName); - stack.setTag(tag); + ItemStack stack = new ItemStack(item, 1, forgeCapsTag); + vanillaTag.putInt("Air", air); + stack.setTag(vanillaTag); return stack; } @@ -201,4 +223,12 @@ public class BacktankBlock extends HorizontalKineticBlock return false; } + @Override + public ItemRequirement getRequiredItems(BlockState state, BlockEntity blockEntity) { + Item item = asItem(); + if (item instanceof BacktankItem.BacktankBlockItem placeable) + item = placeable.getActualItem(); + return new ItemRequirement(ItemUseType.CONSUME, item); + } + } diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java index cca4eda3f..181e5b1bb 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/BacktankBlockEntity.java @@ -2,6 +2,8 @@ package com.simibubi.create.content.equipment.armor; import java.util.List; +import javax.annotation.Nullable; + import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.AllSoundEvents; @@ -16,8 +18,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction.Axis; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.world.Nameable; @@ -35,23 +35,25 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable private Component customName; private int capacityEnchantLevel; - private ListTag enchantmentTag; - private CompoundTag fullNbt; + private CompoundTag vanillaTag; + private CompoundTag forgeCapsTag; public BacktankBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); defaultName = getDefaultName(state); - enchantmentTag = new ListTag(); - fullNbt = new CompoundTag(); + vanillaTag = new CompoundTag(); + forgeCapsTag = null; } public static Component getDefaultName(BlockState state) { if (AllBlocks.NETHERITE_BACKTANK.has(state)) { - AllItems.NETHERITE_BACKTANK.get().getDescription(); + AllItems.NETHERITE_BACKTANK.get() + .getDescription(); } - return AllItems.COPPER_BACKTANK.get().getDescription(); + return AllItems.COPPER_BACKTANK.get() + .getDescription(); } @Override @@ -118,23 +120,29 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable compound.putInt("Air", airLevel); compound.putInt("Timer", airLevelTimer); compound.putInt("CapacityEnchantment", capacityEnchantLevel); + if (this.customName != null) compound.putString("CustomName", Component.Serializer.toJson(this.customName)); - compound.put("Enchantments", enchantmentTag); - compound.put("FullNBT", fullNbt); + + compound.put("VanillaTag", vanillaTag); + if (forgeCapsTag != null) + compound.put("ForgeCapsTag", forgeCapsTag); } @Override protected void read(CompoundTag compound, boolean clientPacket) { super.read(compound, clientPacket); int prev = airLevel; - capacityEnchantLevel = compound.getInt("CapacityEnchantment"); airLevel = compound.getInt("Air"); airLevelTimer = compound.getInt("Timer"); - enchantmentTag = compound.getList("Enchantments", Tag.TAG_COMPOUND); - this.fullNbt = compound.getCompound("FullNBT"); + capacityEnchantLevel = compound.getInt("CapacityEnchantment"); + if (compound.contains("CustomName", 8)) this.customName = Component.Serializer.fromJson(compound.getString("CustomName")); + + vanillaTag = compound.getCompound("VanillaTag"); + forgeCapsTag = compound.contains("ForgeCapsTag") ? compound.getCompound("ForgeCapsTag") : null; + if (prev != 0 && prev != airLevel && airLevel == BacktankUtil.maxAir(capacityEnchantLevel) && clientPacket) playFilledEffect(); } @@ -154,8 +162,7 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable @Override public Component getName() { - return this.customName != null ? this.customName - : defaultName; + return this.customName != null ? this.customName : defaultName; } public int getAirLevel() { @@ -171,30 +178,21 @@ public class BacktankBlockEntity extends KineticBlockEntity implements Nameable this.customName = customName; } - public Component getCustomName() { - return customName; - } - - public ListTag getEnchantmentTag() { - return enchantmentTag; - } - - public void setEnchantmentTag(ListTag enchantmentTag) { - this.enchantmentTag = enchantmentTag; - } - public void setCapacityEnchantLevel(int capacityEnchantLevel) { this.capacityEnchantLevel = capacityEnchantLevel; } - - public CompoundTag getFullNbt() - { - return fullNbt; + + public void setTags(CompoundTag vanillaTag, @Nullable CompoundTag forgeCapsTag) { + this.vanillaTag = vanillaTag; + this.forgeCapsTag = forgeCapsTag; } - public void setFullNbt(CompoundTag fullNbt) - { - this.fullNbt = fullNbt; + public CompoundTag getVanillaTag() { + return vanillaTag; + } + + public CompoundTag getForgeCapsTag() { + return forgeCapsTag; } } diff --git a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java index 0a7148cf2..b985cfbb4 100644 --- a/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java +++ b/src/main/java/com/simibubi/create/foundation/data/BuilderTransformers.java @@ -435,13 +435,10 @@ public class BuilderTransformers { .when(survivesExplosion) .setRolls(ConstantValue.exactly(1)) .add(LootItem.lootTableItem(drop.get()) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) - .copy("FullNBT", "{}", CopyNbtFunction.MergeStrategy.MERGE)) - .apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)) .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) - .copy("Air", "Air")) + .copy("VanillaTag", "{}", CopyNbtFunction.MergeStrategy.MERGE)) .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) - .copy("Enchantments", "Enchantments"))))); + .copy("Air", "Air"))))); }); }