@@ -43,6 +43,8 @@ public class ArmorersWorkbenchScreen extends AbstractRecipeBookScreen<ArmorersWo
4343
4444 private final MineTaleRecipeBookComponent mineTaleRecipeBook ;
4545
46+ private RecipeDisplayId lastKnownSelectedId = null ;
47+
4648 private Button craftOneBtn ;
4749 private Button craftTenBtn ;
4850 private Button craftAllBtn ;
@@ -81,10 +83,10 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(ArmorersWor
8183 ItemStack tabIcon = new ItemStack (ModBlocks .ARMORERS_WORKBENCH_BLOCK .asItem ());
8284
8385 List <RecipeBookComponent .TabInfo > tabs = List .of (
84- new RecipeBookComponent .TabInfo (tabIcon .getItem (), ModRecipeDisplay .WORKBENCH_SEARCH )
86+ new RecipeBookComponent .TabInfo (tabIcon .getItem (), ModRecipeDisplay .ARMORERS_SEARCH )
8587 );
8688
87- return new MineTaleRecipeBookComponent (menu , tabs , ModRecipes .WORKBENCH_TYPE );
89+ return new MineTaleRecipeBookComponent (menu , tabs , ModRecipes .ARMORERS_TYPE );
8890 }
8991
9092 /**
@@ -128,34 +130,52 @@ protected void init() {
128130 * @param amount the quantity to craft; use -1 to request crafting of the full available stack ("All")
129131 */
130132
131- private void handleCraftRequest (int amount ) {
132- // 1. Cast the book component to the Accessor to get the selected data
133- RecipeBookComponentAccessor accessor = (RecipeBookComponentAccessor ) this .mineTaleRecipeBook ;
133+ // private void handleCraftRequest(int amount) {
134+ // // 1. Cast the book component to the Accessor to get the selected data
135+ // RecipeBookComponentAccessor accessor = (RecipeBookComponentAccessor) this.mineTaleRecipeBook;
134136
135- RecipeCollection collection = accessor .getLastRecipeCollection ();
136- RecipeDisplayId displayId = accessor .getLastRecipe ();
137-
138- if (collection != null && displayId != null ) {
139- // 2. Find the visual entry
140- for (RecipeDisplayEntry entry : collection .getSelectedRecipes (RecipeCollection .CraftableStatus .ANY )) {
141- if (entry .id ().equals (displayId )) {
142- // 3. Resolve result for the packet
143- List <ItemStack > results = entry .resultItems (SlotDisplayContext .fromLevel (this .minecraft .level ));
137+ // RecipeCollection collection = accessor.getLastRecipeCollection();
138+ // RecipeDisplayId displayId = accessor.getLastRecipe();
139+
140+ // if (collection != null && displayId != null) {
141+ // // 2. Find the visual entry
142+ // for (RecipeDisplayEntry entry : collection.getSelectedRecipes(RecipeCollection.CraftableStatus.ANY)) {
143+ // if (entry.id().equals(displayId)) {
144+ // // 3. Resolve result for the packet
145+ // List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
144146
145- if (!results .isEmpty ()) {
146- ItemStack resultStack = results .get (0 );
147+ // if (!results.isEmpty()) {
148+ // ItemStack resultStack = results.get(0);
147149
148- // 4. LOG FOR DEBUGGING
149- System .out .println ("Sending craft request for: " + resultStack + " amount: " + amount );
150+ // // 4. LOG FOR DEBUGGING
151+ // System.out.println("Sending craft request for: " + resultStack + " amount: " + amount);
150152
151- ClientPlayNetworking .send (new CraftRequestPayload (resultStack , amount ));
152- }
153- break ;
153+ // ClientPlayNetworking.send(new CraftRequestPayload(resultStack, amount));
154+ // }
155+ // break;
156+ // }
157+ // }
158+ // } else {
159+ // System.out.println("Request failed: Collection or DisplayID is null!");
160+ // }
161+ // }
162+
163+ private void handleCraftRequest (int amount ) {
164+ // Look at our "Memory" instead of the component
165+ if (this .lastKnownSelectedId != null ) {
166+ ClientRecipeBook book = this .minecraft .player .getRecipeBook ();
167+ RecipeDisplayEntry entry = ((ClientRecipeBookAccessor ) book ).getKnown ().get (this .lastKnownSelectedId );
168+
169+ if (entry != null ) {
170+ List <ItemStack > results = entry .resultItems (SlotDisplayContext .fromLevel (this .minecraft .level ));
171+ if (!results .isEmpty ()) {
172+ System .out .println ("Persistent Selection Success: " + results .get (0 ));
173+ ClientPlayNetworking .send (new CraftRequestPayload (results .get (0 ), amount ));
174+ return ;
154175 }
155176 }
156- } else {
157- System .out .println ("Request failed: Collection or DisplayID is null!" );
158177 }
178+ System .out .println ("Request failed: No recipe was ever selected!" );
159179 }
160180
161181 /**
@@ -177,18 +197,22 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
177197 renderBackground (graphics , mouseX , mouseY , delta );
178198 super .render (graphics , mouseX , mouseY , delta );
179199
180- // Get the ID of the recipe clicked in the ghost-book
181- RecipeDisplayId displayId = this .mineTaleRecipeBook .getSelectedRecipeId ();
182- RecipeDisplayEntry selectedEntry = null ;
200+ // 1. Get the current selection from the book
201+ RecipeDisplayId currentId = this .mineTaleRecipeBook .getSelectedRecipeId ();
202+
203+ // 2. If it's NOT null, remember it!
204+ if (currentId != null ) {
205+ this .lastKnownSelectedId = currentId ;
206+ }
183207
184- if (displayId != null && this .minecraft .level != null ) {
208+ // 3. Use the remembered ID to find the entry for button activation
209+ RecipeDisplayEntry selectedEntry = null ;
210+ if (this .lastKnownSelectedId != null && this .minecraft .level != null ) {
185211 ClientRecipeBook book = this .minecraft .player .getRecipeBook ();
186- // Accessing the known recipes via your Accessor
187- Map <RecipeDisplayId , RecipeDisplayEntry > knownRecipes = ((ClientRecipeBookAccessor ) book ).getKnown ();
188- selectedEntry = knownRecipes .get (displayId );
212+ selectedEntry = ((ClientRecipeBookAccessor ) book ).getKnown ().get (this .lastKnownSelectedId );
189213 }
190214
191- // 2. Button Activation Logic
215+ // Logic for enabling/disabling buttons...
192216 if (selectedEntry != null ) {
193217 // We use the entry directly. It contains the 15 ingredients needed!
194218 boolean canCraftOne = canCraft (this .minecraft .player , selectedEntry , 1 );
0 commit comments