Skip to content

Commit

Permalink
添加:菜刀
Browse files Browse the repository at this point in the history
调整:统一方块注册属性代码规范
  • Loading branch information
MCZME committed Aug 10, 2024
1 parent 4e14feb commit 9b85eb5
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"lingshi:chopping_board"
]
}
19 changes: 8 additions & 11 deletions src/main/java/mczme/lingshi/common/block/ChoppingBoardBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> 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<ItemStack> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mczme/lingshi/common/block/TeaBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mczme/lingshi/common/block/TeaTreeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mczme/lingshi/common/data/DataGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
}
4 changes: 3 additions & 1 deletion src/main/java/mczme/lingshi/common/data/loot/BlockLoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class BlockLoot extends BlockLootSubProvider {

public static final Set<Block> BLOCK = Set.of(
ModBlocks.TEA_TREE.get(),
ModBlocks.TEA_LEAF.get()
ModBlocks.TEA_LEAF.get(),
ModBlocks.CHOPPING_BOARD.get()
);

public BlockLoot(HolderLookup.Provider lookupProvider) {
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/mczme/lingshi/common/data/tag/BlockTags.java
Original file line number Diff line number Diff line change
@@ -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<HolderLookup.Provider> 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());
}
}
13 changes: 13 additions & 0 deletions src/main/java/mczme/lingshi/common/item/KnifeItem.java
Original file line number Diff line number Diff line change
@@ -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<Block> pBlocks, Properties pProperties) {
super(pTier, pBlocks, pProperties);
}
}
23 changes: 12 additions & 11 deletions src/main/java/mczme/lingshi/common/registry/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,19 +17,19 @@ public class ModBlocks {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(lingshi.MODID);

public static final Supplier<CropBlock> 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<RiceSeedlingBlock> RICE_SEEDLING = BLOCKS.registerBlock("rice_seedling", RiceSeedlingBlock::new, BlockBehaviour.Properties.of());
public static final Supplier<RiceSeedlingTopBlock> 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<RiceSeedlingBlock> 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<RiceSeedlingTopBlock> 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<TeaTreeBlock> TEA_TREE = BLOCKS.registerBlock("tea_tree", TeaTreeBlock::new,BlockBehaviour.Properties.of());
public static final Supplier<TeaBlock> TEA_LEAF = BLOCKS.registerBlock("tea_leaf", TeaBlock::new,BlockBehaviour.Properties.of());
public static final Supplier<TeaTreeBlock> 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<TeaBlock> 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<ChoppingBoardBlock> CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new,BlockBehaviour.Properties.of());
public static final Supplier<ChoppingBoardBlock> CHOPPING_BOARD = BLOCKS.registerBlock("chopping_board", ChoppingBoardBlock::new,
BlockBehaviour.Properties.ofFullCopy(Blocks.OAK_PLANKS));

public static void register(IEventBus modEventBus) {
BLOCKS.register(modEventBus);
Expand Down

0 comments on commit 9b85eb5

Please sign in to comment.