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 ;
7+ import com .tcm .MineTale .recipe .MineTaleRecipeBookComponent ;
8+ import com .tcm .MineTale .registry .ModBlocks ;
59
610import net .minecraft .client .gui .GuiGraphics ;
7- import net .minecraft .client .gui .screens .inventory .AbstractContainerScreen ;
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 ;
814import net .minecraft .client .renderer .RenderPipelines ;
915import net .minecraft .resources .Identifier ;
1016import net .minecraft .world .entity .player .Inventory ;
17+ import net .minecraft .world .item .ItemStack ;
18+ import net .minecraft .world .item .crafting .RecipeBookCategories ;
1119import net .minecraft .network .chat .Component ;
1220
13- public class FurnaceWorkbenchScreen extends AbstractContainerScreen <FurnaceWorkbenchMenu > {
21+ public class FurnaceWorkbenchScreen extends AbstractRecipeBookScreen <FurnaceWorkbenchMenu > {
1422 private static final Identifier TEXTURE =
1523 Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "textures/gui/container/furnace_workbench.png" );
1624
1725 /**
18- * Creates a new furnace workbench screen for the given menu, player inventory, and title.
19- *
20- * @param menu the container menu that provides slots and syncs state for this screen
21- * @param inventory the player's inventory to display and interact with
22- * @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.
2328 */
2429 public FurnaceWorkbenchScreen (FurnaceWorkbenchMenu menu , Inventory inventory , Component title ) {
25- super (menu , inventory , title );
30+ super (menu , createRecipeBookComponent ( menu ), inventory , title );
2631 }
2732
2833 /**
29- * 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.
3036 */
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+
3147 @ Override
3248 protected void init () {
49+ this .imageWidth = 176 ;
50+ this .imageHeight = 166 ;
51+
3352 super .init ();
34- this .titleLabelX = (this .imageWidth - this .font .width (this .title )) / 2 ;
53+
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+ // ));
3571 }
3672
37- /**
38- * Draws the furnace workbench background texture onto the screen.
39- *
40- * @param guiGraphics the graphics context used for drawing
41- * @param f partial tick time used for interpolation
42- * @param i current mouse x position
43- * @param j current mouse y position
44- */
45- protected void renderBg (GuiGraphics guiGraphics , float f , int i , int j ) {
46- int k = this .leftPos ;
47- int l = this .topPos ;
48- guiGraphics .blit (RenderPipelines .GUI_TEXTURED , TEXTURE , k , l , 0.0F , 0.0F , this .imageWidth , this .imageHeight , 256 , 256 );
49- }
73+ @ Override
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 );
78+ }
5079
51- /**
52- * Renders the furnace workbench screen, drawing its background, contents, and tooltips.
53- *
54- * @param graphics the graphics context used for rendering
55- * @param mouseX the current mouse X coordinate
56- * @param mouseY the current mouse Y coordinate
57- * @param delta the frame time delta (partial tick) used for animated rendering
58- */
5980 @ Override
6081 public void render (GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
6182 renderBackground (graphics , mouseX , mouseY , delta );
83+
84+ // if (this.recipeBookComponent != null) {
85+ // this.recipeBookComponent.render(graphics, mouseX, mouseY, delta);
86+ // }
87+
6288 super .render (graphics , mouseX , mouseY , delta );
89+
90+ // if (this.recipeBookComponent != null) {
91+ // this.recipeBookComponent.renderGhostRecipe(graphics, true);
92+ // this.recipeBookComponent.renderTooltip(graphics, this.leftPos, this.topPos, this.hoveredSlot);
93+ // }
94+
6395 renderTooltip (graphics , mouseX , mouseY );
6496 }
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+ }
65104}
0 commit comments