11package com .silvermoon .boxplusplus .client ;
22
3- import java .lang .reflect .InvocationTargetException ;
4- import java .lang .reflect .Method ;
53import java .util .*;
64
75import net .minecraft .client .gui .GuiButton ;
8- import net .minecraft .client .gui .GuiScreen ;
9- import net .minecraft .client .gui .inventory .GuiContainer ;
106import net .minecraft .entity .player .EntityPlayer ;
117import net .minecraftforge .client .event .GuiScreenEvent ;
128
139import com .gtnewhorizons .modularui .common .internal .wrapper .ModularGui ;
1410import com .silvermoon .boxplusplus .common .tileentities .GTMachineBox ;
11+ import com .silvermoon .boxplusplus .mixins .AccessorGuiContainer ;
12+ import com .silvermoon .boxplusplus .mixins .AccessorGuiRecipe ;
13+ import com .silvermoon .boxplusplus .mixins .AccessorGuiScreen ;
1514import com .silvermoon .boxplusplus .util .BoxRoutings ;
1615import com .silvermoon .boxplusplus .util .Util ;
1716
1817import codechicken .nei .GuiNEIButton ;
1918import codechicken .nei .recipe .*;
20- import cpw .mods .fml .common .ObfuscationReflectionHelper ;
2119import cpw .mods .fml .common .eventhandler .SubscribeEvent ;
2220import gregtech .nei .GTNEIDefaultHandler ;
2321
@@ -29,32 +27,25 @@ public class BoxNEIHandler {
2927
3028 @ SubscribeEvent
3129 public void onDrawScreen (GuiScreenEvent .DrawScreenEvent .Post event ) {
32- if (event .gui instanceof GuiRecipe gui && gui .firstGui instanceof ModularGui mui
30+ if (event .gui instanceof GuiRecipe <?> gui && gui .firstGui instanceof ModularGui mui
3331 && mui .getContext ()
3432 .isWindowOpen (10 )) {
35- EntityPlayer player = (( ModularGui ) gui . firstGui ) .getContext ()
33+ EntityPlayer player = mui .getContext ()
3634 .getPlayer ();
3735 GTMachineBox box = Util .boxMap .get (player );
3836 if (box == null || box .getBaseMetaTileEntity ()
3937 .isDead () || box .recipe .islocked ) return ;
40- List buttonList = ObfuscationReflectionHelper
41- .getPrivateValue (GuiScreen .class , gui , "field_146292_n" , "buttonList" );
38+ List <GuiButton > buttonList = ((AccessorGuiScreen ) gui ).getButtonList ();
4239 if (buttons != null ) {
4340 buttonList .removeIf (Arrays .asList (buttons )::contains );
4441 }
45- Method getRecipesPerPage ;
46- try {
47- getRecipesPerPage = GuiRecipe .class .getDeclaredMethod ("getRecipesPerPage" );
48- getRecipesPerPage .setAccessible (true );
49- recipesPerPage = (int ) getRecipesPerPage .invoke (gui );
50- } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored ) {}
42+ recipesPerPage = ((AccessorGuiRecipe ) gui ).invokeGetRecipesPerPage ();
5143 buttons = new GuiButton [recipesPerPage ];
5244 int OVERLAY_BUTTON_ID_START = 4 ;
53- int guiTop = ObfuscationReflectionHelper
54- .getPrivateValue (GuiContainer .class , gui , "field_147009_r" , "guiTop" );
55- int buttonWidth = ObfuscationReflectionHelper .getPrivateValue (GuiRecipe .class , gui , "buttonWidth" );
56- int buttonHeight = ObfuscationReflectionHelper .getPrivateValue (GuiRecipe .class , gui , "buttonHeight" );
57- HandlerInfo handlerInfo = ObfuscationReflectionHelper .getPrivateValue (GuiRecipe .class , gui , "handlerInfo" );
45+ int guiTop = ((AccessorGuiContainer ) gui ).getGuiTop ();
46+ int buttonWidth = ((AccessorGuiRecipe ) gui ).getButtonWidth ();
47+ int buttonHeight = ((AccessorGuiRecipe ) gui ).getButtonHeight ();
48+ HandlerInfo handlerInfo = ((AccessorGuiRecipe ) gui ).getHandlerInfo ();
5849 for (int i = 0 ; i < recipesPerPage ; i ++) {
5950 buttons [i ] = new GuiNEIButton (
6051 OVERLAY_BUTTON_ID_START + i ,
@@ -81,17 +72,17 @@ public void onDrawScreen(GuiScreenEvent.DrawScreenEvent.Post event) {
8172
8273 @ SubscribeEvent
8374 public void onActionPerformedEventPre (GuiScreenEvent .ActionPerformedEvent .Pre event ) {
84- if (event .gui instanceof GuiRecipe gui && gui .firstGui instanceof ModularGui mui
75+ if (event .gui instanceof GuiRecipe <?> gui && gui .firstGui instanceof ModularGui mui
8576 && mui .getContext ()
8677 .isWindowOpen (10 )) {
87- EntityPlayer player = (( ModularGui ) gui . firstGui ) .getContext ()
78+ EntityPlayer player = mui .getContext ()
8879 .getPlayer ();
8980 List <GuiButton > overlayButtons = new ArrayList <>(
90- Arrays .asList (ObfuscationReflectionHelper . getPrivateValue ( GuiRecipe . class , gui , "overlayButtons" )));
81+ Arrays .asList ((( AccessorGuiRecipe ) gui ). getOverlayButtons ( )));
9182 int OVERLAY_BUTTON_ID_START = 4 ;
9283 if (event .button .id >= OVERLAY_BUTTON_ID_START
9384 && event .button .id < OVERLAY_BUTTON_ID_START + overlayButtons .size ()) {
94- IRecipeHandler handler = ( IRecipeHandler ) gui .currenthandlers .get (gui .recipetype );
85+ IRecipeHandler handler = gui .currenthandlers .get (gui .recipetype );
9586 if (recipesPerPage >= 0 && handler != null ) {
9687 int recipe = gui .page * recipesPerPage + event .button .id - OVERLAY_BUTTON_ID_START ;
9788 BoxRoutings
0 commit comments