1+ package com .tcm .MineTale .recipe ;
2+
3+ import net .minecraft .client .gui .components .WidgetSprites ;
4+ import net .minecraft .client .gui .screens .recipebook .GhostSlots ;
5+ import net .minecraft .client .gui .screens .recipebook .GhostSlotsProxy ;
6+ import net .minecraft .client .gui .screens .recipebook .RecipeBookComponent ;
7+ import net .minecraft .client .gui .screens .recipebook .RecipeCollection ;
8+ import net .minecraft .network .chat .Component ;
9+ import net .minecraft .resources .Identifier ;
10+ import net .minecraft .util .context .ContextMap ;
11+ import net .minecraft .world .entity .player .StackedItemContents ;
12+ import net .minecraft .world .inventory .RecipeBookMenu ;
13+ import net .minecraft .world .inventory .Slot ;
14+ import net .minecraft .world .item .ItemStack ;
15+ import net .minecraft .world .item .Items ;
16+ import net .minecraft .world .item .crafting .RecipeBookCategories ;
17+ import net .minecraft .world .item .crafting .display .FurnaceRecipeDisplay ;
18+ import net .minecraft .world .item .crafting .display .RecipeDisplay ;
19+ import net .minecraft .world .item .crafting .display .SlotDisplay ;
20+
21+ import java .util .List ;
22+ import java .util .Optional ;
23+
24+ import org .jetbrains .annotations .Nullable ;
25+
26+ public class FurnaceRecipeBookComponent extends RecipeBookComponent <RecipeBookMenu > {
27+
28+ public FurnaceRecipeBookComponent (RecipeBookMenu menu ) {
29+ // Pass the menu and the list of tabs required by the super constructor
30+ super (menu , List .of (
31+ new RecipeBookComponent .TabInfo (new ItemStack (Items .PORKCHOP ), Optional .empty (), RecipeBookCategories .FURNACE_FOOD )
32+ ));
33+ }
34+
35+ // Standard Furnace filter button textures (the little flame/ore icon)
36+ private static final WidgetSprites FILTER_BUTTON_SPRITES = new WidgetSprites (
37+ Identifier .withDefaultNamespace ("recipe_book/furnace_filter_enabled" ),
38+ Identifier .withDefaultNamespace ("recipe_book/furnace_filter_disabled" ),
39+ Identifier .withDefaultNamespace ("recipe_book/furnace_filter_enabled_highlighted" ),
40+ Identifier .withDefaultNamespace ("recipe_book/furnace_filter_disabled_highlighted" )
41+ );
42+
43+ @ Override
44+ public void slotClicked (@ Nullable Slot slot ) {
45+ // This is often where the 'can I craft this' state is refreshed
46+ super .slotClicked (slot );
47+ }
48+
49+ @ Override
50+ protected WidgetSprites getFilterButtonTextures () {
51+ return FILTER_BUTTON_SPRITES ;
52+ }
53+
54+ @ Override
55+ protected Component getRecipeFilterName () {
56+ // This is the tooltip text when hovering over the "show craftable" toggle
57+ return Component .translatable ("gui.recipebook.toggleRecipes.smeltable" );
58+ }
59+
60+ @ Override
61+ protected boolean isCraftingSlot (Slot slot ) {
62+ // Temporarily allow the book to 'see' all furnace slots (0-3)
63+ // to see if the pork recipe finally enables.
64+ return slot .index == 0 || slot .index == 1 ;
65+ }
66+
67+ @ Override
68+ protected void selectMatchingRecipes (RecipeCollection recipeCollection , StackedItemContents stackedItemContents ) {
69+ // selectRecipes takes the items you have (stackedContents)
70+ // and a Predicate to decide if the recipe "fits" this machine.
71+ recipeCollection .selectRecipes (stackedItemContents , recipeDisplay -> {
72+ // Option A: Check if it's your custom display type (if you made one)
73+ // Option B: For now, let's accept everything to see if it lights up
74+ return true ;
75+ });
76+ }
77+
78+ // @Override
79+ // protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipeDisplay, ContextMap contextMap) {
80+ // GhostSlotsProxy.setResultProxy(ghostSlots, this.menu.getSlot(3), contextMap, recipeDisplay.result());
81+
82+ // if (recipeDisplay instanceof FurnaceRecipeDisplay cooking) {
83+ // GhostSlotsProxy.setInputProxy(ghostSlots, this.menu.getSlot(1), contextMap, cooking.ingredient());
84+ // }
85+ // }
86+
87+ @ Override
88+ protected void fillGhostRecipe (GhostSlots ghostSlots , RecipeDisplay recipeDisplay , ContextMap contextMap ) {
89+ // 1. Set the Result (Index 2 in your Menu)
90+ // recipeDisplay.result() provides the SlotDisplay for the output
91+ GhostSlotsProxy .setResultProxy (ghostSlots , this .menu .getSlot (2 ), contextMap , recipeDisplay .result ());
92+
93+
94+ // 2. Map Ingredients to your Inputs (Indices 0 and 1)
95+ SlotDisplay ingredient = recipeDisplay .result ();
96+
97+ if (ingredient != null ) {
98+ GhostSlotsProxy .setInputProxy (ghostSlots , this .menu .getSlot (0 ), contextMap , ingredient );
99+ }
100+ }
101+
102+ // @Override
103+ // protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipeDisplay, ContextMap contextMap) {
104+ // // 1. Clear any existing ghost items first
105+ // ghostSlots.clear();
106+
107+ // // 2. Set the Result (Output) Slot Ghost
108+ // // Assuming index 2 is your output slot in the Menu
109+ // ghostSlots.setResult(this.menu.slots.get(2), contextMap, recipeDisplay.result());
110+
111+ // // 3. Set the Input (Ingredient) Slot Ghost
112+ // // We check if the recipe has ingredients to avoid IndexOutOfBounds
113+ // if (!recipeDisplay.ingredients().isEmpty()) {
114+ // // We target the 'Active' processing slot (index 0)
115+ // // This is the physical slot at the front of your queue
116+ // SlotDisplay inputDisplay = recipeDisplay.ingredients().get(0);
117+ // ghostSlots.setInput(this.menu.slots.get(0), contextMap, inputDisplay);
118+ // }
119+ // }
120+ }
0 commit comments