2020import net .minecraft .client .gui .GuiGraphics ;
2121import net .minecraft .client .gui .components .Button ;
2222import net .minecraft .client .gui .navigation .ScreenPosition ;
23- import net .minecraft .client .gui .screens .inventory .AbstractRecipeBookScreen ;
2423import net .minecraft .client .gui .screens .recipebook .RecipeBookComponent ;
2524import net .minecraft .client .renderer .RenderPipelines ;
2625import net .minecraft .core .Holder ;
3433import net .minecraft .world .item .crafting .display .RecipeDisplayId ;
3534import net .minecraft .world .item .crafting .display .SlotDisplayContext ;
3635import net .minecraft .network .chat .Component ;
36+ import org .jspecify .annotations .NonNull ;
3737
38- public class BuildersWorkbenchScreen extends AbstractRecipeBookScreen <BuildersWorkbenchMenu > {
38+ public class BuildersWorkbenchScreen extends ModAbstractContainerScreen <BuildersWorkbenchMenu > {
3939 private static final Identifier TEXTURE =
4040 Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "textures/gui/container/workbench_workbench.png" );
4141
@@ -159,8 +159,8 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
159159 guiGraphics .blit (RenderPipelines .GUI_TEXTURED , TEXTURE , k , l , 0.0F , 0.0F , this .imageWidth , this .imageHeight , 256 , 256 );
160160 }
161161
162- @ Override
163- public void render (GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
162+ @ Override
163+ public void render (@ NonNull GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
164164 renderBackground (graphics , mouseX , mouseY , delta );
165165 super .render (graphics , mouseX , mouseY , delta );
166166
@@ -186,7 +186,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
186186 this .craftAllBtn .active = canCraftMoreThanOne ;
187187
188188 // NEW: Render the Ingredients List
189- renderIngredientList (graphics , selectedEntry , mouseX , mouseY );
189+ this . renderIngredientList (graphics , selectedEntry , mouseX , mouseY );
190190 } else {
191191 this .craftOneBtn .active = false ;
192192 this .craftTenBtn .active = false ;
@@ -196,75 +196,6 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
196196 renderTooltip (graphics , mouseX , mouseY );
197197 }
198198
199- private void renderIngredientList (GuiGraphics graphics , RecipeDisplayEntry entry , int mouseX , int mouseY ) {
200- Optional <List <Ingredient >> reqs = entry .craftingRequirements ();
201- if (reqs .isEmpty ()) return ;
202-
203- // Group requirements to avoid duplicate rows for the same item type
204- Map <List <Holder <Item >>, Integer > aggregated = new HashMap <>();
205- Map <List <Holder <Item >>, Ingredient > holderToIng = new HashMap <>();
206-
207- for (Ingredient ing : reqs .get ()) {
208- List <Holder <Item >> key = ing .items ().toList ();
209- aggregated .put (key , aggregated .getOrDefault (key , 0 ) + 1 );
210- holderToIng .putIfAbsent (key , ing );
211- }
212-
213- int startX = this .leftPos + 8 ; // Adjust to fit your texture's empty space
214- int startY = this .topPos + 20 ;
215- int rowHeight = 20 ;
216- int index = 0 ;
217-
218- for (Map .Entry <List <Holder <Item >>, Integer > reqEntry : aggregated .entrySet ()) {
219- Ingredient ing = holderToIng .get (reqEntry .getKey ());
220- int amountNeeded = reqEntry .getValue ();
221- int currentY = startY + (index * rowHeight );
222-
223- // Calculate total available (Inv + Nearby)
224- int available = getAvailableCount (ing );
225-
226- // Draw Item Icon
227- // Inside your loop
228- ItemStack [] variants = ing .items ().map (ItemStack ::new ).toArray (ItemStack []::new );
229- if (variants .length > 0 ) {
230- long time = System .currentTimeMillis () / 1000 ;
231- ItemStack displayStack = variants [(int ) (time % variants .length )];
232-
233- graphics .renderFakeItem (displayStack , startX , currentY );
234-
235- int color = (available < amountNeeded ) ? 0xFFFF5555 : 0xFFFFFFFF ; // Added alpha channel
236- String progress = available + "/" + amountNeeded ;
237- graphics .drawString (this .font , progress , startX + 22 , currentY + 4 , color );
238-
239- if (mouseX >= startX && mouseX <= startX + 16 && mouseY >= currentY && mouseY <= currentY + 16 ) {
240- graphics .setTooltipForNextFrame (this .font , displayStack , mouseX , mouseY );
241- }
242- }
243- index ++;
244- }
245- }
246-
247- private int getAvailableCount (Ingredient ingredient ) {
248- int found = 0 ;
249- // Check Player Inventory
250- // Use getContainerSize() and getItem(i) for safe access
251- Inventory inv = this .minecraft .player .getInventory ();
252- for (int i = 0 ; i < inv .getContainerSize (); i ++) {
253- ItemStack stack = inv .getItem (i );
254- if (ingredient .test (stack )) {
255- found += stack .getCount ();
256- }
257- }
258-
259- // Check Networked Nearby Items
260- if (this .menu instanceof AbstractWorkbenchContainerMenu workbenchMenu ) {
261- for (ItemStack stack : workbenchMenu .getNetworkedNearbyItems ()) {
262- if (ingredient .test (stack )) found += stack .getCount ();
263- }
264- }
265- return found ;
266- }
267-
268199 /**
269200 * Determines whether the player has enough ingredients to craft the given recipe the specified number of times.
270201 *
0 commit comments