我們昨天講到,非典型方塊的註冊,我們繼續講一些註冊上的參數。
public static final Block SIDERITE_FENCE_GATE = registerBlock("siderite_fence_gate",
new FenceGateBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK), WoodType.ACACIA));
這裡我們註冊了柵欄門,我們在最後一個參數指定了木頭的材質,雖然這個柵欄們還是我們的隕鐵外觀,不過樣式上會跟指定的木頭材質一樣。
public static final Block SIDERITE_TRAPDOOR = registerBlock("siderite_trapdoor",
new TrapdoorBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), BlockSetType.STONE));
這是我們註冊活板門的程式,可以看到這裡有nonOpaque,代表這個活版們可以讓光線通過,不是完全不透明。
回到我們的DataGen,我們可以發現其實這些物品的合成表都與原版是相同的規律,程式上我們也只需要這樣寫
offerSlabRecipe(exporter, RecipeCategory.BUILDING_BLOCKS,ModBlocks.SIDERITE_SLAB,Moditems.Siderite);
offerWallRecipe(exporter, RecipeCategory.BUILDING_BLOCKS,ModBlocks.SIDERITE_WALL,Moditems.Siderite );
offerPressurePlateRecipe(exporter, ModBlocks.SIDERITE_PRESSURE_PLATE, Moditems.Siderite);
createDoorRecipe(ModBlocks.SIDERITE_DOOR, Ingredient.ofItems(Moditems.Siderite)).criterion(hasItem(Moditems.Siderite),conditionsFromItem(Moditems.Siderite)).offerTo(exporter, new Identifier(getRecipeName(ModBlocks.SIDERITE_DOOR)));
createFenceRecipe(ModBlocks.SIDERITE_FENCE, Ingredient.ofItems(Moditems.Siderite)).criterion(hasItem(Moditems.Siderite),conditionsFromItem(Moditems.Siderite)).offerTo(exporter, new Identifier(getRecipeName(ModBlocks.SIDERITE_FENCE)));
createFenceGateRecipe(ModBlocks.SIDERITE_FENCE_GATE, Ingredient.ofItems(Moditems.Siderite)).criterion(hasItem(Moditems.Siderite),conditionsFromItem(Moditems.Siderite)).offerTo(exporter, new Identifier(getRecipeName(ModBlocks.SIDERITE_FENCE_GATE)));
createStairsRecipe(ModBlocks.SIDERITE_STAIRS, Ingredient.ofItems(Moditems.Siderite)).criterion(hasItem(Moditems.Siderite),conditionsFromItem(Moditems.Siderite)).offerTo(exporter, new Identifier(getRecipeName(ModBlocks.SIDERITE_STAIRS)));
createTrapdoorRecipe(ModBlocks.SIDERITE_STAIRS, Ingredient.ofItems(Moditems.Siderite)).criterion(hasItem(Moditems.Siderite),conditionsFromItem(Moditems.Siderite)).offerTo(exporter, new Identifier(getRecipeName(ModBlocks.SIDERITE_TRAPDOOR)));
可以看到我們前三個物品都是使用offerXXXRecipe 我們基本上帶入exporter 產物跟原料即可,後面的四個我們就沒有offerXX這種方法了,我們必須使用createXXXRecipe,參數中我們先指定我們的產物,下一個參數是我們的原料,我們使用Ingredient.ofItems指定原料,criterion讓玩家只有在已經獲得原料(這裡是siderite)的狀況下解鎖合成表,offerTo()再將合成表交給datagen。