diff --git a/src/generated/resources/data/superbwarfare/loot_table/blocks/lucky_container.json b/src/generated/resources/data/superbwarfare/loot_table/blocks/lucky_container.json index d2dd041f2..ac106f1da 100644 --- a/src/generated/resources/data/superbwarfare/loot_table/blocks/lucky_container.json +++ b/src/generated/resources/data/superbwarfare/loot_table/blocks/lucky_container.json @@ -1,4 +1,30 @@ { "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "superbwarfare:lucky_container" + } + ], + "functions": [ + { + "function": "minecraft:copy_components", + "include": [ + "minecraft:block_entity_data" + ], + "source": "block_entity" + } + ], + "rolls": 1.0 + } + ], "random_sequence": "superbwarfare:blocks/lucky_container" } \ No newline at end of file diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/LuckyContainerBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/LuckyContainerBlockEntity.java index e721cb42b..22862d01e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/LuckyContainerBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/LuckyContainerBlockEntity.java @@ -34,6 +34,8 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn @Nullable public ResourceLocation location; + @Nullable + public ResourceLocation icon; public int tick = 0; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -109,6 +111,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn if (tag.contains("Location", 8)) { this.location = ResourceLocation.parse(tag.getString("Location")); } + if (tag.contains("Icon", 8)) { + this.icon = ResourceLocation.parse(tag.getString("Icon")); + } this.tick = tag.getInt("Tick"); } @@ -119,6 +124,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn if (this.location != null) { tag.putString("Location", this.location.toString()); } + if (this.icon != null) { + tag.putString("Icon", this.icon.toString()); + } tag.putInt("Tick", this.tick); } @@ -139,6 +147,9 @@ public class LuckyContainerBlockEntity extends BlockEntity implements GeoBlockEn if (this.location != null) { tag.putString("Location", this.location.toString()); } + if (this.icon != null) { + tag.putString("Icon", this.icon.toString()); + } BlockItem.setBlockEntityData(stack, this.getType(), tag); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/decorator/LuckyContainerItemDecorator.java b/src/main/java/com/atsuishio/superbwarfare/client/decorator/LuckyContainerItemDecorator.java index 877e8e286..d3d268507 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/decorator/LuckyContainerItemDecorator.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/decorator/LuckyContainerItemDecorator.java @@ -2,9 +2,9 @@ package com.atsuishio.superbwarfare.client.decorator; import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.item.common.container.LuckyContainerBlockItem; -import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.component.DataComponents; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.neoforged.api.distmarker.Dist; @@ -20,7 +20,10 @@ public class LuckyContainerItemDecorator implements IItemDecorator { @ParametersAreNonnullByDefault public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int xOffset, int yOffset) { if (!(stack.getItem() instanceof LuckyContainerBlockItem)) return false; - var tag = NBTTool.getTag(stack); + var data = stack.get(DataComponents.BLOCK_ENTITY_DATA); + if (data == null) return false; + + var tag = data.copyTag(); if (!tag.contains("Icon")) return false; var iconTag = tag.getString("Icon"); ResourceLocation icon = ResourceLocation.tryParse(iconTag); diff --git a/src/main/java/com/atsuishio/superbwarfare/datagen/ModBlockLootProvider.java b/src/main/java/com/atsuishio/superbwarfare/datagen/ModBlockLootProvider.java index 00d22b071..a0d79edf5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/datagen/ModBlockLootProvider.java +++ b/src/main/java/com/atsuishio/superbwarfare/datagen/ModBlockLootProvider.java @@ -73,8 +73,9 @@ public class ModBlockLootProvider extends BlockLootSubProvider { .include(DataComponents.CONTAINER_LOOT) ) ))); - // TODO 改成正确的loot table - this.add(ModBlocks.LUCKY_CONTAINER.get(), noDrop()); + this.add(ModBlocks.LUCKY_CONTAINER.get(), LootTable.lootTable().withPool(this.applyExplosionCondition(ModBlocks.LUCKY_CONTAINER.get(), + LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.LUCKY_CONTAINER.get())) + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY).include(DataComponents.BLOCK_ENTITY_DATA))))); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/item/common/container/LuckyContainerBlockItem.java b/src/main/java/com/atsuishio/superbwarfare/item/common/container/LuckyContainerBlockItem.java index bd653aa46..929a41d64 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/common/container/LuckyContainerBlockItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/common/container/LuckyContainerBlockItem.java @@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.client.renderer.item.LuckyContainerBlockItemR import com.atsuishio.superbwarfare.init.ModBlockEntities; import com.atsuishio.superbwarfare.init.ModBlocks; import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -103,12 +102,10 @@ public class LuckyContainerBlockItem extends BlockItem implements GeoItem { CompoundTag tag = new CompoundTag(); tag.putString("Location", location.toString()); - BlockItem.setBlockEntityData(stack, ModBlockEntities.LUCKY_CONTAINER.get(), tag); if (icon != null) { - var iconTag = NBTTool.getTag(stack); - iconTag.putString("Icon", icon.toString()); - NBTTool.saveTag(stack, iconTag); + tag.putString("Icon", icon.toString()); } + BlockItem.setBlockEntityData(stack, ModBlockEntities.LUCKY_CONTAINER.get(), tag); return stack; }