1616
1717package dev .terminalmc .moremousetweaks .mixin .quick .craft ;
1818
19+ import com .llamalad7 .mixinextras .sugar .Local ;
20+ import dev .terminalmc .moremousetweaks .MoreMouseTweaks ;
1921import dev .terminalmc .moremousetweaks .config .Config ;
2022import net .minecraft .client .Minecraft ;
2123import net .minecraft .client .gui .screens .recipebook .OverlayRecipeComponent ;
24+ import net .minecraft .client .gui .screens .recipebook .RecipeCollection ;
25+ import net .minecraft .util .context .ContextMap ;
2226import net .minecraft .world .item .ItemStack ;
23- import net .minecraft .world .item .crafting .RecipeHolder ;
27+ import net .minecraft .world .item .crafting .display .RecipeDisplayEntry ;
28+ import net .minecraft .world .item .crafting .display .RecipeDisplayId ;
2429import org .spongepowered .asm .mixin .Final ;
2530import org .spongepowered .asm .mixin .Mixin ;
2631import org .spongepowered .asm .mixin .Shadow ;
32+ import org .spongepowered .asm .mixin .Unique ;
2733import org .spongepowered .asm .mixin .injection .At ;
2834import org .spongepowered .asm .mixin .injection .Inject ;
35+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2936import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
3037import yalter .mousetweaks .MouseButton ;
3138
39+ import java .util .ArrayList ;
3240import java .util .Iterator ;
3341import java .util .List ;
3442
@@ -42,9 +50,26 @@ public class MixinOverlayRecipeComponent {
4250 @ Shadow
4351 @ Final private List <OverlayRecipeComponent .OverlayRecipeButton > recipeButtons ;
4452 @ Shadow
45- private RecipeHolder <?> lastRecipeClicked ;
46- @ Shadow
47- private Minecraft minecraft ;
53+ private RecipeDisplayId lastRecipeClicked ;
54+
55+ @ Unique
56+ private ContextMap mmt$contextMap ;
57+ @ Unique
58+ private final List <RecipeDisplayEntry > mmt$recipes = new ArrayList <>();
59+
60+ @ Inject (
61+ method = "init" ,
62+ at = @ At (
63+ value = "INVOKE" ,
64+ target = "Ljava/util/List;add(Ljava/lang/Object;)Z" ,
65+ shift = At .Shift .AFTER
66+ )
67+ )
68+ private void wrapAdd (RecipeCollection $$0 , ContextMap contextMap , boolean $$2 , int $$3 , int $$4 ,
69+ int $$5 , int $$6 , float $$7 , CallbackInfo ci , @ Local RecipeDisplayEntry entry ) {
70+ mmt$contextMap = contextMap ;
71+ mmt$recipes .add (entry );
72+ }
4873
4974 @ Inject (
5075 method = "mouseClicked" ,
@@ -57,20 +82,22 @@ private void onMouseClicked(double mouseX, double mouseY, int button,
5782 options ().quickCrafting
5883 && button == MouseButton .RIGHT .getValue ()
5984 ) {
60- Iterator <OverlayRecipeComponent .OverlayRecipeButton > iter = this .recipeButtons .iterator ();
85+ Iterator <OverlayRecipeComponent .OverlayRecipeButton > buttonIter = this .recipeButtons .iterator ();
6186 OverlayRecipeComponent .OverlayRecipeButton overlayButton ;
87+ Iterator <RecipeDisplayEntry > recipeIter = mmt$recipes .iterator ();
88+ RecipeDisplayEntry recipe ;
6289 do {
63- if (!iter .hasNext ()) {
90+ if (!buttonIter . hasNext () || ! recipeIter .hasNext ()) {
6491 cir .setReturnValue (false );
6592 return ; // Crash prevention
6693 }
67- overlayButton = iter .next ();
94+ overlayButton = buttonIter .next ();
95+ recipe = recipeIter .next ();
6896 } while (!overlayButton .mouseClicked (mouseX , mouseY , MouseButton .LEFT .getValue ()));
6997
7098 // Optionally prevent clicking past a full carried stack
71- ItemStack carried = minecraft .player .containerMenu .getCarried ();
72- ItemStack result = overlayButton .recipe .value ().getResultItem (
73- minecraft .level .registryAccess ());
99+ ItemStack carried = Minecraft .getInstance ().player .containerMenu .getCarried ();
100+ ItemStack result = recipe .display ().result ().resolveForFirstStack (mmt$contextMap );
74101 if (
75102 !options ().qcOverflowMode .equals (Config .Options .QcOverflowMode .NONE )
76103 || carried .isEmpty ()
@@ -81,6 +108,8 @@ private void onMouseClicked(double mouseX, double mouseY, int button,
81108 ) {
82109 // Quick-craft
83110 this .lastRecipeClicked = overlayButton .recipe ;
111+ // Notify of result stack
112+ MoreMouseTweaks .resultStack = result ;
84113 cir .setReturnValue (true );
85114 }
86115 }
0 commit comments