4红宝石合成表
这一节我们将为红宝石制作一个合成表,主要内容包括:
- 使用九个红宝石合成一个红宝石块
- 一个红宝石块合成9个红宝石
- 将红宝石原料烧制成红宝石
本节的代码如下,主要是data目录下的合成表:
大约 3 分钟
这一节我们将为红宝石制作一个合成表,主要内容包括:
本节的代码如下,主要是data目录下的合成表:
创建一个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);
}
}
这里我们新建两个物品:红宝石
public class ModItems {
public static final Item RUBY = registerItem("ruby", new Item(new Item.Settings()));
public static final Item RAW_RUBY = registerItem("raw_ruby", new Item(new Item.Settings()));
public static void registerModItems() {
DemoMod1.LOGGER.info("Registering items");
ItemGroupEvents.modifyEntriesEvent(ItemGroups.INGREDIENTS)
.register(ModItems::addItemsToIngredientTabItemGroup);
}
public static void addItemsToIngredientTabItemGroup(FabricItemGroupEntries entries) {
entries.add(RUBY);
entries.add(RAW_RUBY);
}
public static Item registerItem(String name, Item item) {
DemoMod1.LOGGER.info("Registering item " + name);
Registry.register(Registries.ITEM, new Identifier(DemoMod1.MOD_ID, name), item);
return item;
}
}