11package com .tcm .MineTale .block .workbenches .screen ;
22
3+ import java .util .List ;
4+
35import com .tcm .MineTale .MineTale ;
46import com .tcm .MineTale .block .workbenches .menu .FurnaceWorkbenchMenu ;
5- import com .tcm .MineTale .recipe .FurnaceRecipeBookComponent ;
7+ import com .tcm .MineTale .recipe .MineTaleRecipeBookComponent ;
8+ import com .tcm .MineTale .registry .ModBlocks ;
69
710import net .minecraft .client .gui .GuiGraphics ;
8- import net .minecraft .client .gui .screens .inventory .AbstractContainerScreen ;
9- import net .minecraft .client .input .KeyEvent ;
11+ import net .minecraft .client .gui .navigation .ScreenPosition ;
12+ import net .minecraft .client .gui .screens .inventory .AbstractRecipeBookScreen ;
13+ import net .minecraft .client .gui .screens .recipebook .RecipeBookComponent ;
1014import net .minecraft .client .renderer .RenderPipelines ;
1115import net .minecraft .resources .Identifier ;
1216import net .minecraft .world .entity .player .Inventory ;
17+ import net .minecraft .world .item .ItemStack ;
18+ import net .minecraft .world .item .crafting .RecipeBookCategories ;
1319import net .minecraft .network .chat .Component ;
1420
15- public class FurnaceWorkbenchScreen extends AbstractContainerScreen <FurnaceWorkbenchMenu > {
21+ public class FurnaceWorkbenchScreen extends AbstractRecipeBookScreen <FurnaceWorkbenchMenu > {
1622 private static final Identifier TEXTURE =
1723 Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "textures/gui/container/furnace_workbench.png" );
1824
19- private FurnaceRecipeBookComponent recipeBookComponent ;
20-
2125 /**
22- * Creates a new furnace workbench screen for the given menu, player inventory, and title.
23- *
24- * @param menu the container menu that provides slots and syncs state for this screen
25- * @param inventory the player's inventory to display and interact with
26- * @param title the title component shown at the top of the screen
26+ * Creates a new furnace workbench screen.
27+ * Note: recipeBookComponent is inherited from AbstractRecipeBookScreen.
2728 */
2829 public FurnaceWorkbenchScreen (FurnaceWorkbenchMenu menu , Inventory inventory , Component title ) {
29- super (menu , inventory , title );
30+ super (menu , createRecipeBookComponent ( menu ), inventory , title );
3031 }
3132
3233 /**
33- * Initializes the screen and centers the title horizontally by setting {@code titleLabelX}.
34+ * Static helper to build the component with the custom MineTale tabs.
35+ * This uses the FURNACE_WORKBENCH icon for this specific screen's tab.
3436 */
37+ private static MineTaleRecipeBookComponent createRecipeBookComponent (FurnaceWorkbenchMenu menu ) {
38+ ItemStack tabIcon = new ItemStack (ModBlocks .FURNACE_WORKBENCH_BLOCK_T1 .asItem ());
39+
40+ List <RecipeBookComponent .TabInfo > tabs = List .of (
41+ new RecipeBookComponent .TabInfo (tabIcon .getItem (), RecipeBookCategories .CRAFTING_MISC )
42+ );
43+
44+ return new MineTaleRecipeBookComponent (menu , tabs );
45+ }
46+
3547 @ Override
3648 protected void init () {
49+ this .imageWidth = 176 ;
50+ this .imageHeight = 166 ;
51+
3752 super .init ();
3853
39- // 2. Initialize it here where 'this.menu' is available
40- if (this .recipeBookComponent == null ) {
41- this .recipeBookComponent = new FurnaceRecipeBookComponent (this .menu );
42- }
43-
44- // Standard init and visibility logic
45- this .recipeBookComponent .init (this .width , this .height , this .minecraft , false );
46- if (!this .recipeBookComponent .isVisible ()) {
47- this .recipeBookComponent .toggleVisibility ();
48- }
49- this .leftPos = this .recipeBookComponent .updateScreenPosition (this .width , this .imageWidth );
54+ // // Initialize the inherited recipeBookComponent UI state
55+ // this.recipeBookComponent.init(this.width, this.height, this.minecraft, false);
56+ // this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
57+
58+ // // The toggle button is managed via getRecipeBookButtonPosition() in 1.21.1
59+ // // but we add the ImageButton manually to match your CampfireWorkbenchScreen logic exactly.
60+ // this.addRenderableWidget(new ImageButton(
61+ // this.leftPos + 5,
62+ // this.height / 2 - 49,
63+ // 20, 18,
64+ // RecipeBookComponent.RECIPE_BUTTON_SPRITES,
65+ // (button) -> {
66+ // this.recipeBookComponent.toggleVisibility();
67+ // this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
68+ // button.setPosition(this.leftPos + 5, this.height / 2 - 49);
69+ // }
70+ // ));
5071 }
5172
5273 @ Override
53- public boolean keyPressed (KeyEvent keyEvent ) {
54- // 1. Let the search bar in the recipe book use the key first
55- // If your RecipeBookComponent doesn't take KeyEvent, you'll need to map
56- // the keyEvent.getKeyCode() to the standard int keyCode version.
57- if (this .recipeBookComponent .keyPressed (keyEvent )) {
58- return true ;
59- }
60-
61- // 2. Identify the Recipe Book toggle key (Standard 'B')
62- // We check the code to see if it matches the vanilla keybind
63- // int keyCode = keyEvent.getKeyCode();
64- // this.minecraft.options.ke
65- // if (this.minecraft.options.keyRecipeBook.matches(keyCode, 0)) {
66- // return true; // Return true to "consume" the press and do nothing
67- // }
68-
69- return super .keyPressed (keyEvent );
74+ protected void renderBg (GuiGraphics guiGraphics , float f , int i , int j ) {
75+ int k = this .leftPos ;
76+ int l = this .topPos ;
77+ guiGraphics .blit (RenderPipelines .GUI_TEXTURED , TEXTURE , k , l , 0.0F , 0.0F , this .imageWidth , this .imageHeight , 256 , 256 );
7078 }
7179
72- /**
73- * Draws the furnace workbench background texture onto the screen.
74- *
75- * @param guiGraphics the graphics context used for drawing
76- * @param f partial tick time used for interpolation
77- * @param i current mouse x position
78- * @param j current mouse y position
79- */
80- protected void renderBg (GuiGraphics guiGraphics , float f , int i , int j ) {
81- int k = this .leftPos ;
82- int l = this .topPos ;
83- guiGraphics .blit (RenderPipelines .GUI_TEXTURED , TEXTURE , k , l , 0.0F , 0.0F , this .imageWidth , this .imageHeight , 256 , 256 );
84- }
85-
86- /**
87- * Renders the furnace workbench screen, drawing its background, contents, and tooltips.
88- *
89- * @param graphics the graphics context used for rendering
90- * @param mouseX the current mouse X coordinate
91- * @param mouseY the current mouse Y coordinate
92- * @param delta the frame time delta (partial tick) used for animated rendering
93- */
94- // @Override
95- // public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
96- // // Render the dark background tint
97- // renderBackground(graphics, mouseX, mouseY, delta);
98-
99- // // Always render the book and the main GUI together
100- // this.recipeBookComponent.render(graphics, mouseX, mouseY, delta);
101- // super.render(graphics, mouseX, mouseY, delta);
102- // this.recipeBookComponent.renderGhostRecipe(graphics, true);
103-
104- // renderTooltip(graphics, mouseX, mouseY);
105- // // this.recipeBookComponent.renderTooltip(graphics, this.leftPos, this.topPos, mouseX, mouseY);
106- // }
107-
10880 @ Override
10981 public void render (GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
110- // 1. Always render the dark background tint first
11182 renderBackground (graphics , mouseX , mouseY , delta );
11283
113- // 2. Add a null check before calling ANY methods on the component
114- if (this .recipeBookComponent != null ) {
115- this .recipeBookComponent .render (graphics , mouseX , mouseY , delta );
116- }
84+ // if (this.recipeBookComponent != null) {
85+ // this.recipeBookComponent.render(graphics, mouseX, mouseY, delta);
86+ // }
11787
118- // 3. Call super (this draws your slots and items)
11988 super .render (graphics , mouseX , mouseY , delta );
12089
121- // 4. Ghost recipes and Tooltips also need the null check
122- if (this .recipeBookComponent != null ) {
123- this .recipeBookComponent .renderGhostRecipe (graphics , true );
124- this .recipeBookComponent .renderTooltip (graphics , this .leftPos , this .topPos , this .hoveredSlot );
125- }
90+ // if (this.recipeBookComponent != null) {
91+ // this.recipeBookComponent.renderGhostRecipe(graphics, true);
92+ // this.recipeBookComponent.renderTooltip(graphics, this.leftPos, this.topPos, this.hoveredSlot);
93+ // }
12694
12795 renderTooltip (graphics , mouseX , mouseY );
12896 }
97+
98+ @ Override
99+ protected ScreenPosition getRecipeBookButtonPosition () {
100+ int guiLeft = (this .width - this .imageWidth ) / 2 ;
101+ int guiTop = (this .height - this .imageHeight ) / 2 ;
102+ return new ScreenPosition (guiLeft + 5 , guiTop + this .imageHeight / 2 - 49 );
103+ }
129104}
0 commit comments