55import com .gregtechceu .gtceu .api .registry .GTRegistries ;
66import com .gregtechceu .gtceu .common .data .machines .GTMultiMachines ;
77
8+ import com .lowdragmc .lowdraglib .gui .widget .Widget ;
89import com .lowdragmc .lowdraglib .jei .ModularUIRecipeCategory ;
910
11+ import net .minecraft .MethodsReturnNonnullByDefault ;
12+ import net .minecraft .client .gui .navigation .ScreenPosition ;
1013import net .minecraft .network .chat .Component ;
14+ import net .minecraft .resources .ResourceLocation ;
1115
1216import mezz .jei .api .gui .drawable .IDrawable ;
17+ import mezz .jei .api .gui .ingredient .IRecipeSlotDrawable ;
18+ import mezz .jei .api .gui .inputs .RecipeSlotUnderMouse ;
19+ import mezz .jei .api .gui .widgets .IRecipeExtrasBuilder ;
20+ import mezz .jei .api .gui .widgets .ISlottedRecipeWidget ;
1321import mezz .jei .api .helpers .IGuiHelper ;
1422import mezz .jei .api .helpers .IJeiHelpers ;
23+ import mezz .jei .api .recipe .IFocusGroup ;
1524import mezz .jei .api .recipe .RecipeType ;
1625import mezz .jei .api .registration .IRecipeRegistration ;
1726import org .jetbrains .annotations .NotNull ;
27+ import org .jetbrains .annotations .Nullable ;
1828
29+ import java .util .ArrayList ;
30+ import java .util .List ;
31+ import java .util .Optional ;
32+
33+ import javax .annotation .ParametersAreNonnullByDefault ;
34+
35+ @ MethodsReturnNonnullByDefault
36+ @ ParametersAreNonnullByDefault
1937public class MultiblockInfoCategory extends ModularUIRecipeCategory <MultiblockInfoWrapper > {
2038
2139 public final static RecipeType <MultiblockInfoWrapper > RECIPE_TYPE = new RecipeType <>(GTCEu .id ("multiblock_info" ),
@@ -38,6 +56,51 @@ public static void registerRecipes(IRecipeRegistration registry) {
3856 .toList ());
3957 }
4058
59+ @ Override
60+ public void createRecipeExtras (@ NotNull IRecipeExtrasBuilder builder , @ NotNull MultiblockInfoWrapper recipe ,
61+ @ NotNull IFocusGroup focuses ) {
62+ super .createRecipeExtras (builder , recipe , focuses );
63+ List <IRecipeSlotDrawable > slots = new ArrayList <>(builder .getRecipeSlots ().getSlots ());
64+ class ProxyRecipeWidget implements ISlottedRecipeWidget {
65+
66+ private final ScreenPosition position = new ScreenPosition (0 , 0 );
67+
68+ @ Override
69+ public Optional <RecipeSlotUnderMouse > getSlotUnderMouse (double mouseX , double mouseY ) {
70+ var panel = recipe .getWidget ();
71+ var pos = panel .getSelfPosition ();
72+ var size = panel .getSize ();
73+ boolean inParent = Widget .isMouseOver (pos .x , pos .y , size .width , size .height , mouseX , mouseY );
74+ if (!inParent ) return Optional .empty ();
75+ List <Widget > widgets = recipe .modularUI .getFlatWidgetCollection ();
76+ return slots .stream ()
77+ .filter (slot -> {
78+ Optional <String > slotName = slot .getSlotName ();
79+ if (slotName .isEmpty ()) return false ;
80+ String name = slotName .get ();
81+ int index = Integer .parseInt (name .substring (5 ));
82+ Widget widget = widgets .get (index );
83+ slot .setPosition (widget .getPositionX (), widget .getPositionY ());
84+ return slot .isMouseOver (mouseX , mouseY );
85+ })
86+ .findFirst ()
87+ .map (slot -> new RecipeSlotUnderMouse (slot , 0 , 0 ));
88+ }
89+
90+ @ Override
91+ public ScreenPosition getPosition () {
92+ return position ;
93+ }
94+ }
95+
96+ builder .addSlottedWidget (new ProxyRecipeWidget (), slots );
97+ }
98+
99+ @ Override
100+ public @ Nullable ResourceLocation getRegistryName (@ NotNull MultiblockInfoWrapper recipe ) {
101+ return recipe .definition .getId ();
102+ }
103+
41104 @ Override
42105 @ NotNull
43106 public RecipeType <MultiblockInfoWrapper > getRecipeType () {
0 commit comments