MC Fabric 1.20.1 学习笔记 —— 制作一个独立配方的工作台 05 ResultInventory/RecipeUnlocker

100 阅读1分钟

这个类比较简单,是合成台输出合成结果的格子,主要实现RecipeUnlocker即可。

public class WorkBlockResultInventory implements Inventory, RecipeUnlocker, EasyInventory {
    // 这个类最关键的是实现RecipeUnlocker接口
    private final DefaultedList<ItemStack> stacks = DefaultedList.ofSize(1, ItemStack.EMPTY);
    // 来自RecipeUnlocker
    @Nullable
    private Recipe<?> lastRecipe;
    // 来自RecipeUnlocker 由fabric调用,下同
    @Override
    public void setLastRecipe(@Nullable Recipe<?> recipe) {
        this.lastRecipe = recipe;
    }
    // 来自RecipeUnlocker
    @Nullable
    @Override
    public Recipe<?> getLastRecipe() {
        return this.lastRecipe;
    }
    // 来自EasyInventory
    @Override
    public DefaultedList<ItemStack> getItems() {
        return stacks;
    }
}