From 9b85eb5df437377a231b714e48b8a7dfd7e40d3e Mon Sep 17 00:00:00 2001 From: MCZME <13183052+mczme@user.noreply.gitee.com> Date: Sat, 10 Aug 2024 17:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0:=E8=8F=9C=E5=88=80=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=9A=E7=BB=9F=E4=B8=80=E6=96=B9=E5=9D=97?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=B1=9E=E6=80=A7=E4=BB=A3=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../59eb3dbb5f86130e09b3c62d89b9525ee01cf52d | 3 ++- .../d88813880ae3e40e9724fa9bc86e438c1f5ddb3d | 2 ++ .../loot_table/blocks/chopping_board.json | 21 +++++++++++++++ .../minecraft/tags/block/mineable/axe.json | 5 ++++ .../common/block/ChoppingBoardBlock.java | 19 ++++++-------- .../common/block/RiceSeedlingBlock.java | 2 +- .../common/block/RiceSeedlingTopBlock.java | 2 +- .../mczme/lingshi/common/block/TeaBlock.java | 2 +- .../lingshi/common/block/TeaTreeBlock.java | 2 +- .../lingshi/common/data/DataGenerators.java | 7 +++++ .../lingshi/common/data/loot/BlockLoot.java | 4 ++- .../lingshi/common/data/tag/BlockTags.java | 26 +++++++++++++++++++ .../mczme/lingshi/common/item/KnifeItem.java | 13 ++++++++++ .../lingshi/common/registry/ModBlocks.java | 23 ++++++++-------- 14 files changed, 103 insertions(+), 28 deletions(-) create mode 100644 src/generated/resources/.cache/d88813880ae3e40e9724fa9bc86e438c1f5ddb3d create mode 100644 src/generated/resources/data/lingshi/loot_table/blocks/chopping_board.json create mode 100644 src/generated/resources/data/minecraft/tags/block/mineable/axe.json create mode 100644 src/main/java/mczme/lingshi/common/data/tag/BlockTags.java create mode 100644 src/main/java/mczme/lingshi/common/item/KnifeItem.java diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index 7cb2919..18f22d6 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,3 +1,4 @@ -// 1.21 2024-08-06T21:56:13.9856387 Loot Tables +// 1.21 2024-08-10T17:07:03.6586838 Loot Tables +032b2242788b8411178136ca48214246ef2af8a9 data/lingshi/loot_table/blocks/chopping_board.json c843630bb0739aad37078f0119c9cc31f5316c3a data/lingshi/loot_table/blocks/tea_leaf.json 3cd0ced47f090fec162cddcb8b2f75284fa134cb data/lingshi/loot_table/blocks/tea_tree.json diff --git a/src/generated/resources/.cache/d88813880ae3e40e9724fa9bc86e438c1f5ddb3d b/src/generated/resources/.cache/d88813880ae3e40e9724fa9bc86e438c1f5ddb3d new file mode 100644 index 0000000..4106df1 --- /dev/null +++ b/src/generated/resources/.cache/d88813880ae3e40e9724fa9bc86e438c1f5ddb3d @@ -0,0 +1,2 @@ +// 1.21 2024-08-10T17:02:48.5453931 Tags for minecraft:block mod id lingshi +e00d57f2828f9f55903e8c8c9f4b95dfeca4135d data/minecraft/tags/block/mineable/axe.json diff --git a/src/generated/resources/data/lingshi/loot_table/blocks/chopping_board.json b/src/generated/resources/data/lingshi/loot_table/blocks/chopping_board.json new file mode 100644 index 0000000..65f312f --- /dev/null +++ b/src/generated/resources/data/lingshi/loot_table/blocks/chopping_board.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "lingshi:chopping_board" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "lingshi:blocks/chopping_board" +} \ No newline at end of file diff --git a/src/generated/resources/data/minecraft/tags/block/mineable/axe.json b/src/generated/resources/data/minecraft/tags/block/mineable/axe.json new file mode 100644 index 0000000..5c61c3d --- /dev/null +++ b/src/generated/resources/data/minecraft/tags/block/mineable/axe.json @@ -0,0 +1,5 @@ +{ + "values": [ + "lingshi:chopping_board" + ] +} \ No newline at end of file diff --git a/src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java b/src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java index edd4781..8a2cac5 100644 --- a/src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java +++ b/src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java @@ -67,18 +67,15 @@ public ItemInteractionResult useItemOn( blockEntity.setTheItem(stack); blockEntity.setChanged(); return ItemInteractionResult.SUCCESS; - } else if(!blockEntity.getTheItem().isEmpty()&& !stack.isEmpty()) { - if(pPlayer.getMainHandItem().is(Items.DIAMOND)) - { - List stacks = blockEntity.getRecipeAndResult(blockEntity.getTheItem()); - if(stacks == null||stacks.getFirst().isEmpty()) { - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; - } - stacks.forEach(itemStack -> Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), itemStack)); - blockEntity.setTheItem(ItemStack.EMPTY); - blockEntity.setChanged(); - return ItemInteractionResult.SUCCESS; + } else if(!blockEntity.getTheItem().isEmpty()&& !stack.isEmpty() && pPlayer.getMainHandItem().is(Items.DIAMOND)) { + List stacks = blockEntity.getRecipeAndResult(blockEntity.getTheItem()); + if(stacks == null||stacks.getFirst().isEmpty()) { + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } + stacks.forEach(itemStack -> Containers.dropItemStack(pLevel, pPos.getX(), pPos.getY(), pPos.getZ(), itemStack)); + blockEntity.setTheItem(ItemStack.EMPTY); + blockEntity.setChanged(); + return ItemInteractionResult.SUCCESS; }else { return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java b/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java index 32121d4..b0977db 100644 --- a/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java +++ b/src/main/java/mczme/lingshi/common/block/RiceSeedlingBlock.java @@ -40,7 +40,7 @@ public class RiceSeedlingBlock extends BushBlock implements BonemealableBlock, L }; public RiceSeedlingBlock(Properties properties) { - super(properties.noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); + super(properties); this.registerDefaultState(this.defaultBlockState().setValue(EMERGE, false).setValue(AGE, 0).setValue(WATERLOGGED, true)); } diff --git a/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java index f920622..0a12db8 100644 --- a/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java +++ b/src/main/java/mczme/lingshi/common/block/RiceSeedlingTopBlock.java @@ -31,7 +31,7 @@ public class RiceSeedlingTopBlock extends CropBlock { }; public RiceSeedlingTopBlock(Properties properties) { - super(properties.noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); + super(properties); this.registerDefaultState(this.defaultBlockState().setValue(AGE, 0)); } diff --git a/src/main/java/mczme/lingshi/common/block/TeaBlock.java b/src/main/java/mczme/lingshi/common/block/TeaBlock.java index 0770839..bc8dab6 100644 --- a/src/main/java/mczme/lingshi/common/block/TeaBlock.java +++ b/src/main/java/mczme/lingshi/common/block/TeaBlock.java @@ -27,7 +27,7 @@ public class TeaBlock extends CropBlock { }; public TeaBlock(Properties properties) { - super(properties.randomTicks().noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)); + super(properties); } @Override diff --git a/src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java b/src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java index b6d6dd2..52fd42d 100644 --- a/src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java +++ b/src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java @@ -34,7 +34,7 @@ public class TeaTreeBlock extends BushBlock implements BonemealableBlock { Shapes.or(Block.box(7.0, 0, 7.0, 10, 5, 10),Block.box(0,5,0,16,16,16))}; public TeaTreeBlock(Properties properties) { - super(properties.randomTicks().noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)); + super(properties); this.registerDefaultState(this.defaultBlockState().setValue(AGE, 0)); } diff --git a/src/main/java/mczme/lingshi/common/data/DataGenerators.java b/src/main/java/mczme/lingshi/common/data/DataGenerators.java index 3003308..21fbeed 100644 --- a/src/main/java/mczme/lingshi/common/data/DataGenerators.java +++ b/src/main/java/mczme/lingshi/common/data/DataGenerators.java @@ -3,6 +3,7 @@ import mczme.lingshi.common.data.lang.ChineseLanguageProvider; import mczme.lingshi.common.data.loot.BlockLoot; import mczme.lingshi.common.data.recipe.ChoppingBoardRecipeDatagen; +import mczme.lingshi.common.data.tag.BlockTags; import mczme.lingshi.lingshi; import net.minecraft.core.HolderLookup; import net.minecraft.data.DataGenerator; @@ -54,5 +55,11 @@ public static void onGatherData(GatherDataEvent event) { event.includeServer(), new ChoppingBoardRecipeDatagen(output, lookupProvider) ); + +// block tag datagen + event.getGenerator().addProvider( + event.includeServer(), + new BlockTags(output, lookupProvider,existingFileHelper) + ); } } diff --git a/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java b/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java index b4e083c..383c495 100644 --- a/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java +++ b/src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java @@ -13,7 +13,8 @@ public class BlockLoot extends BlockLootSubProvider { public static final Set BLOCK = Set.of( ModBlocks.TEA_TREE.get(), - ModBlocks.TEA_LEAF.get() + ModBlocks.TEA_LEAF.get(), + ModBlocks.CHOPPING_BOARD.get() ); public BlockLoot(HolderLookup.Provider lookupProvider) { @@ -25,6 +26,7 @@ public BlockLoot(HolderLookup.Provider lookupProvider) { protected void generate() { dropSelf(ModBlocks.TEA_TREE.get()); dropOther(ModBlocks.TEA_LEAF.get(), ModItems.TEA_LEAF.get()); + dropSelf(ModBlocks.CHOPPING_BOARD.get()); } @Override diff --git a/src/main/java/mczme/lingshi/common/data/tag/BlockTags.java b/src/main/java/mczme/lingshi/common/data/tag/BlockTags.java new file mode 100644 index 0000000..8d6af74 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/data/tag/BlockTags.java @@ -0,0 +1,26 @@ +package mczme.lingshi.common.data.tag; + +import mczme.lingshi.common.registry.ModBlocks; +import mczme.lingshi.lingshi; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.neoforged.neoforge.common.data.BlockTagsProvider; +import net.neoforged.neoforge.common.data.ExistingFileHelper; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.concurrent.CompletableFuture; + +import static net.minecraft.tags.BlockTags.*; + +public class BlockTags extends BlockTagsProvider { + public BlockTags(PackOutput output, CompletableFuture lookupProvider, @Nullable ExistingFileHelper existingFileHelper) { + super(output, lookupProvider, lingshi.MODID, existingFileHelper); + } + + @Override + protected void addTags(HolderLookup.@NotNull Provider pProvider) { +// 斧 可挖掘 + tag(MINEABLE_WITH_AXE).add(ModBlocks.CHOPPING_BOARD.get()); + } +} diff --git a/src/main/java/mczme/lingshi/common/item/KnifeItem.java b/src/main/java/mczme/lingshi/common/item/KnifeItem.java new file mode 100644 index 0000000..0400697 --- /dev/null +++ b/src/main/java/mczme/lingshi/common/item/KnifeItem.java @@ -0,0 +1,13 @@ +package mczme.lingshi.common.item; + +import net.minecraft.tags.TagKey; +import net.minecraft.world.item.DiggerItem; +import net.minecraft.world.item.Tier; +import net.minecraft.world.level.block.Block; + +public class KnifeItem extends DiggerItem { + + public KnifeItem(Tier pTier, TagKey pBlocks, Properties pProperties) { + super(pTier, pBlocks, pProperties); + } +} diff --git a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java index c2cd0d7..4029af6 100644 --- a/src/main/java/mczme/lingshi/common/registry/ModBlocks.java +++ b/src/main/java/mczme/lingshi/common/registry/ModBlocks.java @@ -2,6 +2,7 @@ import mczme.lingshi.common.block.*; import mczme.lingshi.lingshi; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.CropBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; @@ -16,19 +17,19 @@ public class ModBlocks { public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(lingshi.MODID); public static final Supplier RICE = BLOCKS.registerBlock("rice", RiceBlock::new, - BlockBehaviour.Properties.of().mapColor(MapColor.PLANT) - .noCollission() - .randomTicks() - .instabreak() - .sound(SoundType.CROP) - .pushReaction(PushReaction.DESTROY)); - public static final Supplier RICE_SEEDLING = BLOCKS.registerBlock("rice_seedling", RiceSeedlingBlock::new, BlockBehaviour.Properties.of()); - public static final Supplier RICE_SEEDING_TOP = BLOCKS.registerBlock("rice_seedling_top", RiceSeedlingTopBlock::new, BlockBehaviour.Properties.of()); + BlockBehaviour.Properties.of().mapColor(MapColor.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)); + public static final Supplier RICE_SEEDLING = BLOCKS.registerBlock("rice_seedling", RiceSeedlingBlock::new, + BlockBehaviour.Properties.of().noCollission().mapColor(MapColor.PLANT).instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); + public static final Supplier RICE_SEEDING_TOP = BLOCKS.registerBlock("rice_seedling_top", RiceSeedlingTopBlock::new, + BlockBehaviour.Properties.of().noCollission().mapColor(MapColor.PLANT).instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY).randomTicks()); - public static final Supplier TEA_TREE = BLOCKS.registerBlock("tea_tree", TeaTreeBlock::new,BlockBehaviour.Properties.of()); - public static final Supplier TEA_LEAF = BLOCKS.registerBlock("tea_leaf", TeaBlock::new,BlockBehaviour.Properties.of()); + public static final Supplier TEA_TREE = BLOCKS.registerBlock("tea_tree", TeaTreeBlock::new, + BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)); + public static final Supplier TEA_LEAF = BLOCKS.registerBlock("tea_leaf", TeaBlock::new, + BlockBehaviour.Properties.of().randomTicks().mapColor(MapColor.PLANT).noCollission().instabreak().sound(SoundType.CROP).pushReaction(PushReaction.DESTROY)); - public static final Supplier CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new,BlockBehaviour.Properties.of()); + public static final Supplier CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new, + BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_PLANKS)); public static void register(IEventBus modEventBus) { BLOCKS.register(modEventBus);