跳到主要内容

34定制木型

代码

在ModBlocks中注册木头相关方块:

public static final Block CHESTNUT_LOG = registerBlock("chestnut_log",
new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_LOG).strength(4f)));
public static final Block CHESTNUT_WOOD = registerBlock("chestnut_wood",
new PillarBlock(FabricBlockSettings.copyOf(Blocks.OAK_WOOD).strength(4f)));
public static final Block STRIPPED_CHESTNUT_LOG = registerBlock("stripped_chestnut_log",
new PillarBlock(FabricBlockSettings.copyOf(Blocks.STRIPPED_OAK_LOG).strength(4f)));
public static final Block STRIPPED_CHESTNUT_WOOD = registerBlock("stripped_chestnut_wood",
new PillarBlock(FabricBlockSettings.copyOf(Blocks.STRIPPED_OAK_WOOD).strength(4f)));

public static final Block CHESTNUT_PLANKS = registerBlock("chestnut_planks",
new Block(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).strength(4f)));
public static final Block CHESTNUT_LEAVES = registerBlock("chestnut_leaves",
new LeavesBlock(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).strength(4f).nonOpaque()));

在ModItemGroups中添加到物品组:

entries.add(ModBlocks.CHESTNUT_LOG);
entries.add(ModBlocks.CHESTNUT_WOOD);
entries.add(ModBlocks.STRIPPED_CHESTNUT_LOG);
entries.add(ModBlocks.STRIPPED_CHESTNUT_WOOD);
entries.add(ModBlocks.CHESTNUT_PLANKS);
entries.add(ModBlocks.CHESTNUT_LEAVES);

配置代码生成:

ModBlockTagProvider:

getOrCreateTagBuilder(BlockTags.LOGS_THAT_BURN)
.add(ModBlocks.CHESTNUT_LOG)
.add(ModBlocks.CHESTNUT_WOOD)
.add(ModBlocks.STRIPPED_CHESTNUT_LOG)
.add(ModBlocks.STRIPPED_CHESTNUT_WOOD);

ModItemTagProvider:

getOrCreateTagBuilder(ItemTags.PLANKS)
.add(ModBlocks.CHESTNUT_PLANKS.asItem());

getOrCreateTagBuilder(ItemTags.LOGS_THAT_BURN)
.add(ModBlocks.CHESTNUT_LOG.asItem())
.add(ModBlocks.CHESTNUT_WOOD.asItem())
.add(ModBlocks.STRIPPED_CHESTNUT_LOG.asItem())
.add(ModBlocks.STRIPPED_CHESTNUT_WOOD.asItem());

ModLootTableProvider

addDrop(ModBlocks.CHESTNUT_LOG);
addDrop(ModBlocks.CHESTNUT_WOOD);
addDrop(ModBlocks.STRIPPED_CHESTNUT_LOG);
addDrop(ModBlocks.STRIPPED_CHESTNUT_WOOD);
addDrop(ModBlocks.CHESTNUT_PLANKS);

addDrop(ModBlocks.CHESTNUT_LEAVES, leavesDrops(ModBlocks.CHESTNUT_LEAVES, ModBlocks.RUBY_SLAB, 0.0025f)); // TODO

ModModelProvider:

blockStateModelGenerator.registerLog(ModBlocks.CHESTNUT_LOG).log(ModBlocks.CHESTNUT_LOG).wood(ModBlocks.CHESTNUT_WOOD);
blockStateModelGenerator.registerLog(ModBlocks.STRIPPED_CHESTNUT_LOG).log(ModBlocks.STRIPPED_CHESTNUT_LOG).wood(ModBlocks.STRIPPED_CHESTNUT_WOOD);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.CHESTNUT_PLANKS);
blockStateModelGenerator.registerSimpleCubeAll(ModBlocks.CHESTNUT_LEAVES);

为了加入木头燃烧等效果:

TutorialMod:

StrippableBlockRegistry.register(ModBlocks.CHESTNUT_LOG, ModBlocks.STRIPPED_CHESTNUT_LOG);
StrippableBlockRegistry.register(ModBlocks.CHESTNUT_WOOD, ModBlocks.STRIPPED_CHESTNUT_WOOD);

FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.CHESTNUT_LOG, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.CHESTNUT_WOOD, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.STRIPPED_CHESTNUT_LOG, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.STRIPPED_CHESTNUT_WOOD, 5, 5);

FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.CHESTNUT_PLANKS, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(ModBlocks.CHESTNUT_LEAVES, 30, 60);

TutorialModClient:

BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.CHESTNUT_LEAVES, RenderLayer.getCutout());

##效果

image-20240825184323715