44import java .util .Date ;
55import java .util .List ;
66
7- import net .minecraft .client .Minecraft ;
87import net .minecraft .entity .player .EntityPlayer ;
98import net .minecraft .util .EnumChatFormatting ;
109
10+ import com .github .ae2patterngen .AE2PatternGen ;
1111import com .github .ae2patterngen .network .NetworkHandler ;
1212import com .github .ae2patterngen .network .PacketStorageAction ;
1313import com .github .ae2patterngen .storage .PatternStorage ;
1414import com .gtnewhorizons .modularui .api .drawable .shapes .Rectangle ;
15- import com .gtnewhorizons .modularui .api .screen .ModularUIContext ;
1615import com .gtnewhorizons .modularui .api .screen .ModularWindow ;
1716import com .gtnewhorizons .modularui .api .screen .UIBuildContext ;
18- import com .gtnewhorizons .modularui .common .internal .wrapper .ModularGui ;
19- import com .gtnewhorizons .modularui .common .internal .wrapper .ModularUIContainer ;
2017import com .gtnewhorizons .modularui .common .widget .ButtonWidget ;
2118import com .gtnewhorizons .modularui .common .widget .Scrollable ;
2219import com .gtnewhorizons .modularui .common .widget .TextWidget ;
@@ -41,9 +38,7 @@ public static ModularWindow createWindow(UIBuildContext buildContext, EntityPlay
4138 if (summary .count == 0 ) {
4239 String msg = "仓储为空,请先在配置 GUI 中生成样板" ;
4340 TextWidget emptyText = new TextWidget (msg );
44- // Rough centering based on character count approx if getStringWidth isn't
45- // available easily from here (but it is)
46- int strW = Minecraft .getMinecraft ().fontRenderer .getStringWidth (msg );
41+ int strW = approximateTextWidth (msg );
4742 emptyText .setPos (GUI_W / 2 - strW / 2 , 40 );
4843 builder .widget (emptyText );
4944 } else {
@@ -97,13 +92,7 @@ public static ModularWindow createWindow(UIBuildContext buildContext, EntityPlay
9792 rowBtn .setOnClick ((cd , w ) -> {
9893 PatternStorage .PatternDetail detail = PatternStorage .getPatternDetail (player .getUniqueID (), index );
9994 if (detail != null ) {
100- Minecraft .getMinecraft ().thePlayer .closeScreen ();
101- UIBuildContext newContext = new UIBuildContext (player );
102- ModularUIContext muiContext = new ModularUIContext (newContext , () -> {});
103- ModularWindow detailWindow = GuiPatternDetail
104- .createWindow (newContext , index , detail .inputs , detail .outputs );
105- Minecraft .getMinecraft ()
106- .displayGuiScreen (new ModularGui (new ModularUIContainer (muiContext , detailWindow )));
95+ AE2PatternGen .proxy .openPatternDetailScreen (player , index , detail .inputs , detail .outputs );
10796 }
10897 });
10998
@@ -126,7 +115,7 @@ public static ModularWindow createWindow(UIBuildContext buildContext, EntityPlay
126115 btnExtText .setPos (GUI_W / 2 - btnW - 4 + 16 , btnY + 6 );
127116 btnExtract .setOnClick ((cd , w ) -> {
128117 NetworkHandler .INSTANCE .sendToServer (new PacketStorageAction (PacketStorageAction .ACTION_EXTRACT ));
129- Minecraft . getMinecraft (). thePlayer . closeScreen ();
118+ AE2PatternGen . proxy . closeCurrentScreen ();
130119 });
131120 builder .widget (btnExtract );
132121 builder .widget (btnExtText );
@@ -139,7 +128,7 @@ public static ModularWindow createWindow(UIBuildContext buildContext, EntityPlay
139128 btnClrText .setPos (GUI_W / 2 + 4 + 20 , btnY + 6 );
140129 btnClear .setOnClick ((cd , w ) -> {
141130 NetworkHandler .INSTANCE .sendToServer (new PacketStorageAction (PacketStorageAction .ACTION_CLEAR ));
142- Minecraft . getMinecraft (). thePlayer . closeScreen ();
131+ AE2PatternGen . proxy . closeCurrentScreen ();
143132 });
144133 builder .widget (btnClear );
145134 builder .widget (btnClrText );
@@ -150,4 +139,11 @@ public static ModularWindow createWindow(UIBuildContext buildContext, EntityPlay
150139
151140 return builder .build ();
152141 }
142+
143+ private static int approximateTextWidth (String text ) {
144+ if (text == null || text .isEmpty ()) {
145+ return 0 ;
146+ }
147+ return text .length () * 6 ;
148+ }
153149}
0 commit comments