这个类比较简单,是合成台输出合成结果的格子,主要实现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;
}
}