1+ package com .tcm .MineTale .block .workbenches .screen ;
2+
3+ import java .util .List ;
4+
5+ import com .tcm .MineTale .MineTale ;
6+ import com .tcm .MineTale .block .workbenches .menu .WorkbenchWorkbenchMenu ;
7+ import com .tcm .MineTale .recipe .MineTaleRecipeBookComponent ;
8+ import com .tcm .MineTale .registry .ModBlocks ;
9+ import com .tcm .MineTale .registry .ModRecipeDisplay ;
10+ import com .tcm .MineTale .registry .ModRecipes ;
11+
12+ import net .minecraft .client .gui .GuiGraphics ;
13+ import net .minecraft .client .gui .navigation .ScreenPosition ;
14+ import net .minecraft .client .gui .screens .inventory .AbstractRecipeBookScreen ;
15+ import net .minecraft .client .gui .screens .recipebook .RecipeBookComponent ;
16+ import net .minecraft .client .renderer .RenderPipelines ;
17+ import net .minecraft .resources .Identifier ;
18+ import net .minecraft .world .entity .player .Inventory ;
19+ import net .minecraft .world .item .ItemStack ;
20+ import net .minecraft .network .chat .Component ;
21+
22+ public class WorkbenchWorkbenchScreen extends AbstractRecipeBookScreen <WorkbenchWorkbenchMenu > {
23+ private static final Identifier TEXTURE =
24+ Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "textures/gui/container/furnace_workbench.png" );
25+
26+ /**
27+ * Creates a campfire workbench screen for the provided menu, player inventory, and title.
28+ *
29+ * @param menu the container menu that provides slots and synchronizes state for this screen
30+ * @param inventory the player's inventory to display and interact with
31+ * @param title the title component shown at the top of the screen
32+ */
33+ public WorkbenchWorkbenchScreen (WorkbenchWorkbenchMenu menu , Inventory inventory , Component title ) {
34+ super (menu , createRecipeBookComponent (menu ), inventory , title );
35+ }
36+
37+ /**
38+ * Static helper to build the component with the custom MineTale tabs
39+ * before the super constructor is called.
40+ */
41+ private static MineTaleRecipeBookComponent createRecipeBookComponent (WorkbenchWorkbenchMenu menu ) {
42+ ItemStack tabIcon = new ItemStack (ModBlocks .WORKBENCH_WORKBENCH_BLOCK .asItem ());
43+
44+ List <RecipeBookComponent .TabInfo > tabs = List .of (
45+ new RecipeBookComponent .TabInfo (tabIcon .getItem (), ModRecipeDisplay .WORKBENCH_SEARCH )
46+ );
47+
48+ return new MineTaleRecipeBookComponent (menu , tabs , ModRecipes .WORKBENCH_TYPE );
49+ }
50+
51+ /**
52+ * Initializes the screen and centers the title horizontally by setting {@code titleLabelX}.
53+ */
54+ @ Override
55+ protected void init () {
56+ // Important: Set your GUI size before super.init()
57+ this .imageWidth = 176 ;
58+ this .imageHeight = 166 ;
59+
60+ super .init ();
61+ }
62+
63+ /**
64+ * Renders the campfire workbench background texture at the screen's top-left position.
65+ *
66+ * @param guiGraphics the graphics context used for drawing
67+ * @param f partial ticks for interpolation
68+ * @param i current mouse x position
69+ * @param j current mouse y position
70+ */
71+ protected void renderBg (GuiGraphics guiGraphics , float f , int i , int j ) {
72+ int k = this .leftPos ;
73+ int l = this .topPos ;
74+ guiGraphics .blit (RenderPipelines .GUI_TEXTURED , TEXTURE , k , l , 0.0F , 0.0F , this .imageWidth , this .imageHeight , 256 , 256 );
75+ }
76+
77+ /**
78+ * Renders the campfire workbench screen, drawing its background, contents, and tooltips.
79+ *
80+ * @param graphics the graphics context used for rendering
81+ * @param mouseX the current mouse X coordinate
82+ * @param mouseY the current mouse Y coordinate
83+ * @param delta the frame time delta (partial tick) used for animated rendering
84+ */
85+ @ Override
86+ public void render (GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
87+ // 1. Always render the dark background tint first
88+ renderBackground (graphics , mouseX , mouseY , delta );
89+
90+ // 3. Call super (this draws your slots and items)
91+ super .render (graphics , mouseX , mouseY , delta );
92+
93+ renderTooltip (graphics , mouseX , mouseY );
94+ }
95+
96+ @ Override
97+ protected ScreenPosition getRecipeBookButtonPosition () {
98+ // 1. Calculate the start (left) of your workbench GUI
99+ int guiLeft = (this .width - this .imageWidth ) / 2 ;
100+
101+ // 2. Calculate the top of your workbench GUI
102+ int guiTop = (this .height - this .imageHeight ) / 2 ;
103+
104+ // 3. Standard Vanilla positioning:
105+ // Usually 5 pixels in from the left and 49 pixels up from the center
106+ return new ScreenPosition (guiLeft + 5 , guiTop + this .imageHeight / 2 - 49 );
107+ }
108+ }
0 commit comments