跳至主要內容

3 红宝石块和矿石

我的世界fabric我的世界fabric小于 1 分钟约 227 字全民制作人ikun

3 红宝石块和矿石

创建一个Block

public class ModBlocks {
    public static final Block RUBY_BLOCK =
            registerBlock("ruby_block", new Block(
                    FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.AMETHYST_BLOCK)
            ));
    public static final Block RAW_RUBY_BLOCK =
            registerBlock("raw_ruby_block", new Block(
                    FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.AMETHYST_BLOCK)
            ));

    private static Block registerBlock(String name, Block block) {
        registerBlockItem(name, block);
        return Registry.register(Registries.BLOCK, new Identifier(DemoMod1.MOD_ID, name), block);
    }


    private static Item registerBlockItem(String name, Block block) {
        return Registry.register(Registries.ITEM, new Identifier(DemoMod1.MOD_ID, name),
                new BlockItem(block, new Item.Settings()));
    }

    public static void registerModBlocks() {
        DemoMod1.LOGGER.info("Registering blocks for " + DemoMod1.MOD_ID);
    }
}

将他们添加到ruby group中:

public static final ItemGroup RUBY_GROUP = Registry.register(Registries.ITEM_GROUP,
        new Identifier(DemoMod1.MOD_ID, "ruby"),
        FabricItemGroup.builder().displayName(Text.translatable("itemgroup.ruby"))
                .icon(() -> new ItemStack(ModItems.RUBY)).entries((displayContext, entries) -> {
                    entries.add(ModItems.RUBY);
                    entries.add(ModItems.RAW_RUBY);
                    entries.add(Items.DIAMOND);
                    entries.add(ModBlocks.RUBY_BLOCK);
                    entries.add(ModBlocks.RAW_RUBY_BLOCK);
                }).build());

在初始化的时候进行注册:

ModBlocks.registerModBlocks();

其他文件主要体现在目录结构上:

image-20240611170034846
image-20240611170034846

blockstates/ruby_block.json

{
  "variants": {
    "": {
      "model": "demo01:block/ruby_block"
    }
  }
}

models/block/ruby_block.json

{
  "parent": "block/cube_all",
  "textures": {
    "all": "demo01:block/ruby_block"
  }
}

item/ruby_block.json

{
  "parent": "demo01:block/ruby_block"
}

运行结果:

image-20240611170202892
image-20240611170202892

物品组里:

image-20240611170212640
image-20240611170212640
上次编辑于:
贡献者: yunfeidog