11package com .coflnet .gui .cofl ;
22
33import CoflCore .CoflCore ;
4- import CoflCore .CoflSkyCommand ;
54import CoflCore .commands .models .FlipData ;
65import com .coflnet .gui .AuctionStatus ;
6+ import com .coflnet .gui .BinGUI ;
77import com .coflnet .gui .RenderUtils ;
88import com .coflnet .gui .widget .ItemWidget ;
99import com .coflnet .gui .widget .ScrollableDynamicTextWidget ;
1010import net .minecraft .client .MinecraftClient ;
11- import net .minecraft .client .font .MultilineText ;
1211import net .minecraft .client .gui .DrawContext ;
13- import net .minecraft .client .gui .screen .Screen ;
1412import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
1513import net .minecraft .client .gui .screen .narration .NarrationMessageBuilder ;
1614import net .minecraft .client .gui .widget .*;
17- import net .minecraft .client .render .item .ItemRenderer ;
18- import net .minecraft .entity .player .PlayerEntity ;
1915import net .minecraft .item .Item ;
20- import net .minecraft .item .ItemStack ;
2116import net .minecraft .item .Items ;
22- import net .minecraft .screen .GenericContainerScreenHandler ;
23- import net .minecraft .screen .ScreenHandler ;
24- import net .minecraft .screen .ScreenHandlerListener ;
2517import net .minecraft .screen .ScreenHandlerType ;
26- import net .minecraft .screen .slot .SlotActionType ;
27- import net .minecraft .text .HoverEvent ;
2818import net .minecraft .text .MutableText ;
29- import net .minecraft .text .Style ;
3019import net .minecraft .text .Text ;
31- import org .lwjgl .glfw .GLFWWindowRefreshCallback ;
32- import org .lwjgl .glfw .GLFWWindowSizeCallback ;
3320import oshi .util .tuples .Pair ;
3421
35- import java .awt .event .WindowEvent ;
36- import java .awt .event .WindowStateListener ;
3722import java .util .List ;
3823
39- import static com .coflnet .Utils .ChatComponent ;
40-
41- public class CoflBinGUI extends Screen {
24+ public class CoflBinGUI extends BinGUI {
4225 private TextWidget titleTextWidget ;
43- private ItemWidget itemWidget ;
4426 private ScrollableDynamicTextWidget loreScrollableTextWidget ;
4527 private ClickableWidget rightClickableWidget ;
4628 private ClickableWidget leftClickableWidget ;
4729
48- private int width ;
49- private int height ;
50- private int p ;
51- private int r ;
52- private final int ITEM_SLOT = 13 ;
53- private final int BUY_SLOT = 31 ;
54- private final int AUCTION_CANCEL_SLOT = 49 ;
55- private final int CONFIRM_SLOT = 11 ;
56- private final int CONFIRMATION_CANCEL_SLOT = 15 ;
57- private AuctionStatus auctionStatus ;
58- public GenericContainerScreenHandler gcsh ;
59- public GenericContainerScreen gcs ;
6030 public String title = "" ;
6131 public Text lore = Text .of (RenderUtils .lorem ());
6232 public Pair <Integer , Integer > rightButtonCol = new Pair <>(CoflColConfig .BACKGROUND_SECONDARY , CoflColConfig .BACKGROUND_SECONDARY );
6333
6434 public CoflBinGUI (GenericContainerScreen gcs , String flipId ){
65- super (Text .literal ("Cofl Bin Gui" ));
35+ super (Text .literal ("Cofl Bin Gui" ), gcs );
6636
6737 FlipData f = CoflCore .flipHandler .fds .getFlipById (flipId );
6838 if (f == null ){
6939 System .out .println ("NO FLIP FOUND" );
7040 } else System .out .println ("FLIP FOUND WTF" );
7141
72- int screenWidth = MinecraftClient .getInstance ().currentScreen .width ;
73- int screenHeight = MinecraftClient .getInstance ().currentScreen .height ;
74-
75- this .gcs = gcs ;
76- this .gcsh = gcs .getScreenHandler ();
77-
78- this .width = screenWidth / 2 ;
79- if (width < 300 ) this .width = 300 ;
80-
81- this .height = screenHeight / 3 * 2 ;
82- if (height < 225 ) this .height = 225 ;
83-
8442 this .p = 5 ;
8543 this .r = 4 ;
8644
8745 if (gcsh .getType () == ScreenHandlerType .GENERIC_9X3 ){
8846 this .auctionStatus = AuctionStatus .CONFIRMING ;
8947 } else this .auctionStatus = AuctionStatus .INIT ;
9048
49+ clearAndInitWidgets (screenWidth , screenHeight );
50+ }
51+
52+ @ Override
53+ protected void clearAndInitWidgets (int screenWidth , int screenHeight ) {
54+ this .clearChildren ();
9155 leftClickableWidget = new ClickableWidget (
9256 screenWidth / 2 - width / 2 + p ,
9357 screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5 ) - screenHeight / 15 ,
@@ -123,9 +87,9 @@ public void onClick(double mouseX, double mouseY) {
12387 @ Override
12488 protected void renderWidget (DrawContext context , int mouseX , int mouseY , float delta ) {
12589 boolean mouseOver = mouseX >= (double )(screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 )
126- && mouseY >= (double )(screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p *5 ) - screenHeight / 15 )
127- && mouseX < (double )((screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 ) + (tempWidth / 5 * 3 - p *2 ))
128- && mouseY < (double )((screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p *5 ) - screenHeight / 15 ) + (225 - 150 - 12 - p *5 + screenHeight / 15 ));
90+ && mouseY >= (double )(screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p *5 ) - screenHeight / 15 )
91+ && mouseX < (double )((screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 ) + (tempWidth / 5 * 3 - p *2 ))
92+ && mouseY < (double )((screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p *5 ) - screenHeight / 15 ) + (225 - 150 - 12 - p *5 + screenHeight / 15 ));
12993
13094 RenderUtils .drawRoundedRect (context ,
13195 screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 ,
@@ -187,7 +151,6 @@ public void onClick(double mouseX, double mouseY) {
187151 Items .AIR .getDefaultStack ()
188152 );
189153
190-
191154 if (auctionStatus == AuctionStatus .CONFIRMING ) setRightButtonConfig (AuctionStatus .CONFIRMING );
192155
193156 this .addDrawableChild (titleTextWidget );
@@ -197,18 +160,6 @@ public void onClick(double mouseX, double mouseY) {
197160 this .addDrawableChild (leftClickableWidget );
198161 }
199162
200- private void clickSlot (int slotId ) {
201- PlayerEntity player = client .player ;
202-
203- client .interactionManager .clickSlot (
204- gcsh .syncId ,
205- slotId ,
206- 0 ,
207- SlotActionType .PICKUP ,
208- player
209- );
210- }
211-
212163 private AuctionStatus setAuctionStatus (Item item ){
213164 if (item == Items .GOLD_NUGGET ) auctionStatus = AuctionStatus .BUYING ;
214165 if (item == Items .RED_BED ) auctionStatus = AuctionStatus .WAITING ;
@@ -235,12 +186,6 @@ private void setRightButtonConfig(AuctionStatus auctionStatus){
235186 }
236187 }
237188
238- public void setItem (ItemStack item ) {
239- lore = convertTextList (getTooltipFromItem (MinecraftClient .getInstance (), item ));
240- loreScrollableTextWidget .updateText (lore );
241- this .itemWidget .item = item ;
242- }
243-
244189 public MutableText convertTextList (List <Text > collection ){
245190 MutableText res = Text .empty ();
246191 if (collection == null || collection .isEmpty ()) return res ;
@@ -255,17 +200,17 @@ public MutableText convertTextList(List<Text> collection){
255200 return res ;
256201 }
257202
258- @ Override
259- public boolean shouldPause () {
260- return false ;
261- }
262203
263204 @ Override
264205 public void renderBackground (DrawContext drawContext , int mouseX , int mouseY , float delta ) {
265- int screenWidth = MinecraftClient . getInstance (). currentScreen . width ;
266- int screenHeight = MinecraftClient . getInstance (). currentScreen . height ;
206+ super . renderBackground ( drawContext , mouseX , mouseY , delta ) ;
207+
267208 if (!gcsh .getInventory ().isEmpty ()){
268- if (gcsh .getInventory ().getStack (ITEM_SLOT ).getItem () != Items .AIR ) setItem (gcsh .getInventory ().getStack (ITEM_SLOT ));
209+ if (gcsh .getInventory ().getStack (ITEM_SLOT ).getItem () != Items .AIR ) {
210+ setItem (gcsh .getInventory ().getStack (ITEM_SLOT ));
211+ lore = convertTextList (getTooltipFromItem (MinecraftClient .getInstance (), currentItem ));
212+ loreScrollableTextWidget .updateText (lore );
213+ }
269214 if (gcsh .getInventory ().getStack (BUY_SLOT ).getItem () != Items .AIR ) setRightButtonConfig (setAuctionStatus (gcsh .getInventory ().getStack (ITEM_SLOT ).getItem ()));
270215 }
271216
@@ -279,10 +224,4 @@ public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, fl
279224 RenderUtils .drawRoundedRect (drawContext ,screenWidth / 2 - width / 2 + p + 20 + p , screenHeight / 2 - height / 2 + p + 12 + p , width - 20 - p *3 , height - 75 - screenHeight / 15 , r , CoflColConfig .BACKGROUND_SECONDARY );
280225 }
281226
282- @ Override
283- public void close () {
284- auctionStatus = AuctionStatus .INIT ;
285- gcs .close ();
286- super .close ();
287- }
288227}
0 commit comments