CraftingRecipeBookComponent.java

net.minecraft.client.gui.screens.recipebook.CraftingRecipeBookComponent

信息

  • 全限定名:net.minecraft.client.gui.screens.recipebook.CraftingRecipeBookComponent
  • 类型:public class
  • 包:net.minecraft.client.gui.screens.recipebook
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/recipebook/CraftingRecipeBookComponent.java
  • 起始行号:L21
  • 继承:RecipeBookComponent
  • 职责:

    TODO

字段/常量

  • FILTER_BUTTON_SPRITES

    • 类型: WidgetSprites
    • 修饰符: private static final
    • 源码定位: L22
    • 说明:

      TODO

  • ONLY_CRAFTABLES_TOOLTIP

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • TABS

    • 类型: List<RecipeBookComponent.TabInfo>
    • 修饰符: private static final
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

构造器

public CraftingRecipeBookComponent(AbstractCraftingMenu menu) @ L37

  • 构造器名:CraftingRecipeBookComponent
  • 源码定位:L37
  • 修饰符:public

参数:

  • menu: AbstractCraftingMenu

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected boolean isCraftingSlot(Slot slot) @ L41

  • 方法名:isCraftingSlot
  • 源码定位:L41
  • 返回类型:boolean
  • 修饰符:protected

参数:

  • slot: Slot

说明:

TODO

private boolean canDisplay(RecipeDisplay display) @ L46

  • 方法名:canDisplay
  • 源码定位:L46
  • 返回类型:boolean
  • 修饰符:private

参数:

  • display: RecipeDisplay

说明:

TODO

protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipe, ContextMap context) @ L57

  • 方法名:fillGhostRecipe
  • 源码定位:L57
  • 返回类型:void
  • 修饰符:protected

参数:

  • ghostSlots: GhostSlots
  • recipe: RecipeDisplay
  • context: ContextMap

说明:

TODO

protected WidgetSprites getFilterButtonTextures() @ L91

  • 方法名:getFilterButtonTextures
  • 源码定位:L91
  • 返回类型:WidgetSprites
  • 修饰符:protected

参数:

说明:

TODO

protected Component getRecipeFilterName() @ L96

  • 方法名:getRecipeFilterName
  • 源码定位:L96
  • 返回类型:Component
  • 修饰符:protected

参数:

说明:

TODO

protected void selectMatchingRecipes(RecipeCollection collection, StackedItemContents stackedContents) @ L101

  • 方法名:selectMatchingRecipes
  • 源码定位:L101
  • 返回类型:void
  • 修饰符:protected

参数:

  • collection: RecipeCollection
  • stackedContents: StackedItemContents

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class CraftingRecipeBookComponent extends RecipeBookComponent<AbstractCraftingMenu> {
    private static final WidgetSprites FILTER_BUTTON_SPRITES = new WidgetSprites(
        Identifier.withDefaultNamespace("recipe_book/filter_enabled"),
        Identifier.withDefaultNamespace("recipe_book/filter_disabled"),
        Identifier.withDefaultNamespace("recipe_book/filter_enabled_highlighted"),
        Identifier.withDefaultNamespace("recipe_book/filter_disabled_highlighted")
    );
    private static final Component ONLY_CRAFTABLES_TOOLTIP = Component.translatable("gui.recipebook.toggleRecipes.craftable");
    private static final List<RecipeBookComponent.TabInfo> TABS = List.of(
        new RecipeBookComponent.TabInfo(SearchRecipeBookCategory.CRAFTING),
        new RecipeBookComponent.TabInfo(Items.IRON_AXE, Items.GOLDEN_SWORD, RecipeBookCategories.CRAFTING_EQUIPMENT),
        new RecipeBookComponent.TabInfo(Items.BRICKS, RecipeBookCategories.CRAFTING_BUILDING_BLOCKS),
        new RecipeBookComponent.TabInfo(Items.LAVA_BUCKET, Items.APPLE, RecipeBookCategories.CRAFTING_MISC),
        new RecipeBookComponent.TabInfo(Items.REDSTONE, RecipeBookCategories.CRAFTING_REDSTONE)
    );
 
    public CraftingRecipeBookComponent(AbstractCraftingMenu menu) {
        super(menu, TABS);
    }
 
    @Override
    protected boolean isCraftingSlot(Slot slot) {
        return this.menu.getResultSlot() == slot || this.menu.getInputGridSlots().contains(slot);
    }
 
    private boolean canDisplay(RecipeDisplay display) {
        int gridWidth = this.menu.getGridWidth();
        int gridHeight = this.menu.getGridHeight();
 
        return switch (display) {
            case ShapedCraftingRecipeDisplay shaped -> gridWidth >= shaped.width() && gridHeight >= shaped.height();
            case ShapelessCraftingRecipeDisplay shapeless -> gridWidth * gridHeight >= shapeless.ingredients().size();
            default -> false;
        };
    }
 
    @Override
    protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipe, ContextMap context) {
        ghostSlots.setResult(this.menu.getResultSlot(), context, recipe.result());
        switch (recipe) {
            case ShapedCraftingRecipeDisplay shaped: {
                List<Slot> inputSlots = this.menu.getInputGridSlots();
                PlaceRecipeHelper.placeRecipe(
                    this.menu.getGridWidth(),
                    this.menu.getGridHeight(),
                    shaped.width(),
                    shaped.height(),
                    shaped.ingredients(),
                    (ingredient, gridIndex, gridXPos, gridYPos) -> {
                        Slot slot = inputSlots.get(gridIndex);
                        ghostSlots.setInput(slot, context, ingredient);
                    }
                );
                break;
            }
            case ShapelessCraftingRecipeDisplay shapeless: {
                label15: {
                    List<Slot> inputSlots = this.menu.getInputGridSlots();
                    int slotCount = Math.min(shapeless.ingredients().size(), inputSlots.size());
 
                    for (int i = 0; i < slotCount; i++) {
                        ghostSlots.setInput(inputSlots.get(i), context, shapeless.ingredients().get(i));
                    }
                    break label15;
                }
            }
            default:
        }
    }
 
    @Override
    protected WidgetSprites getFilterButtonTextures() {
        return FILTER_BUTTON_SPRITES;
    }
 
    @Override
    protected Component getRecipeFilterName() {
        return ONLY_CRAFTABLES_TOOLTIP;
    }
 
    @Override
    protected void selectMatchingRecipes(RecipeCollection collection, StackedItemContents stackedContents) {
        collection.selectRecipes(stackedContents, this::canDisplay);
    }
}

引用的其他类