跳到主要内容

22自定义花朵

dahlia花

在ModBlocks中,定义花和盆栽花:

public static final Block DAHLIA = registerBlock("dahlia",
new FlowerBlock(StatusEffects.FIRE_RESISTANCE, 10,
FabricBlockSettings.copyOf(Blocks.ALLIUM).nonOpaque().noCollision()));
public static final Block POTTED_DAHLIA = Registry.register(Registries.BLOCK, new Identifier(TutorialMod.MOD_ID, "potted_dahlia"),
new FlowerPotBlock(DAHLIA, FabricBlockSettings.copyOf(Blocks.POTTED_ALLIUM).nonOpaque()));

在ModItemGroups中,加入到物品组

entries.add(ModBlocks.DAHLIA);

在ModLootTableProvider中,添加掉落物:

addDrop(ModBlocks.DAHLIA);
addPottedPlantDrops(ModBlocks.POTTED_DAHLIA);

在ModModelProvider中:

blockStateModelGenerator.registerFlowerPotPlant(ModBlocks.DAHLIA, ModBlocks.POTTED_DAHLIA, BlockStateModelGenerator.TintType.NOT_TINTED);

在TutorialModClient中:

        BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.DAHLIA, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.POTTED_DAHLIA, RenderLayer.getCutout());

最后在lang中添加翻译,以及textures中添加block的图片

效果

image-20240825085936826