Skip to content

Commit 090107f

Browse files
committed
changed how CoflBinGUI updates Item data
1 parent dabf70c commit 090107f

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

src/client/java/com/coflnet/CoflModClient.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
2121
import net.fabricmc.loader.api.FabricLoader;
2222
import net.minecraft.client.MinecraftClient;
23-
import net.minecraft.client.WindowEventHandler;
2423
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
2524
import net.minecraft.client.option.KeyBinding;
2625
import net.minecraft.client.util.InputUtil;
2726
import net.minecraft.item.Items;
2827
import net.minecraft.text.Text;
2928
import org.greenrobot.eventbus.Subscribe;
3029
import org.lwjgl.glfw.GLFW;
31-
32-
import java.awt.event.WindowEvent;
3330
import java.nio.file.Path;
3431

3532
import static com.coflnet.Utils.ChatComponent;
@@ -58,7 +55,7 @@ public void onInitializeClient() {
5855
ClientTickEvents.END_CLIENT_TICK.register(client -> {
5956
while (bestflipsKeyBinding.wasPressed()) {
6057
//client.player.sendMessage(Text.literal(), false);
61-
client.getServer().getCommandManager().executeWithPrefix(client.getServer().getCommandSource(), "cofl bestflips");
58+
CoflCore.flipHandler.fds.CurrentFlips();
6259
}
6360
});
6461

@@ -79,12 +76,13 @@ public void onInitializeClient() {
7976

8077
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
8178
if (screen instanceof GenericContainerScreen gcs) {
82-
ScreenEvents.beforeRender(gcs).register((screen1, drawContext, mouseX, mouseY, tickDelta) -> {
79+
System.out.println(gcs.getTitle().getString());
80+
ScreenEvents.beforeRender(screen).register((screen1, drawContext, a, b, c) -> {
8381
GenericContainerScreen gcs1 = (GenericContainerScreen) screen1;
84-
if (CoflCore.config.purchaseOverlay != null
85-
&& (gcs.getTitle().getLiteralString().contains("BIN Auction View")
82+
if (CoflCore.config.purchaseOverlay != null && gcs.getTitle() != null
83+
&& (gcs.getTitle().getString().contains("BIN Auction View")
8684
&& gcs.getScreenHandler().getInventory().size() == 9 * 6
87-
|| gcs.getTitle().getLiteralString().contains("Confirm Purchase")
85+
|| gcs.getTitle().getString().contains("Confirm Purchase")
8886
&& gcs.getScreenHandler().getInventory().size() == 9 * 3)
8987
) {
9088
if (!(client.currentScreen instanceof CoflBinGUI || client.currentScreen instanceof TfmBinGUI)) {

src/client/java/com/coflnet/gui/cofl/CoflBinGUI.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.coflnet.gui.cofl;
22

3+
import CoflCore.CoflSkyCommand;
34
import com.coflnet.gui.AuctionStatus;
45
import com.coflnet.gui.RenderUtils;
56
import com.coflnet.gui.widget.ItemWidget;
@@ -23,6 +24,7 @@
2324
import net.minecraft.screen.slot.SlotActionType;
2425
import net.minecraft.text.HoverEvent;
2526
import net.minecraft.text.MutableText;
27+
import net.minecraft.text.Style;
2628
import net.minecraft.text.Text;
2729
import org.lwjgl.glfw.GLFWWindowRefreshCallback;
2830
import org.lwjgl.glfw.GLFWWindowSizeCallback;
@@ -32,6 +34,8 @@
3234
import java.awt.event.WindowStateListener;
3335
import java.util.List;
3436

37+
import static com.coflnet.Utils.ChatComponent;
38+
3539
public class CoflBinGUI extends Screen {
3640
private TextWidget titleTextWidget;
3741
private ItemWidget itemWidget;
@@ -64,10 +68,6 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
6468
this.gcs = gcs;
6569
this.gcsh = gcs.getScreenHandler();
6670

67-
if (gcsh.getType() == ScreenHandlerType.GENERIC_9X3){
68-
this.auctionStatus = AuctionStatus.CONFIRMING;
69-
} else this.auctionStatus = AuctionStatus.INIT;
70-
7171
this.width = screenWidth / 2;
7272
if (width < 300) this.width = 300;
7373

@@ -77,6 +77,10 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
7777
this.p = 5;
7878
this.r = 4;
7979

80+
if (gcsh.getType() == ScreenHandlerType.GENERIC_9X3){
81+
this.auctionStatus = AuctionStatus.CONFIRMING;
82+
} else this.auctionStatus = AuctionStatus.INIT;
83+
8084
leftClickableWidget = new ClickableWidget(
8185
screenWidth / 2 - width / 2 + p,
8286
screenHeight / 2 + height / 2 - p - (225 - 150 - 12 - p * 5) - screenHeight / 15,
@@ -87,7 +91,7 @@ public CoflBinGUI(Item item, GenericContainerScreen gcs){
8791
@Override
8892
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
8993
RenderUtils.drawRoundedRect(context, getX(), getY(), getWidth(), getHeight(), r, this.isMouseOver(mouseX,mouseY) ? CoflColConfig.CANCEL_HOVER : CoflColConfig.CANCEL);
90-
RenderUtils.drawString(context, this.getMessage().getLiteralString(), getX() + 6, getY() + 4, 0xFFEEEEEE);
94+
RenderUtils.drawString(context, this.getMessage().getLiteralString(), getX() + 6, getY() + 4, CoflColConfig.TEXT_PRIMARY);
9195
}
9296

9397
@Override
@@ -128,7 +132,7 @@ protected void renderWidget(DrawContext context, int mouseX, int mouseY, float d
128132
this.getMessage().getString(),
129133
screenWidth / 2 - tempWidth / 2 + p + tempWidth / 5 * 2 + 6,
130134
screenHeight / 2 + tempHeight / 2 - p - (225 - 150 - 12 - p*5) - screenHeight / 15 + 4,
131-
0xFFEEEEEE
135+
CoflColConfig.TEXT_PRIMARY
132136
);
133137
}
134138

@@ -141,6 +145,7 @@ public void onClick(double mouseX, double mouseY) {
141145
leftClickableWidget.onClick(mouseX, mouseY);
142146
} else {
143147
if(auctionStatus != AuctionStatus.CONFIRMING) clickSlot(BUY_SLOT);
148+
else if(auctionStatus == AuctionStatus.WAITING) MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.literal("[§1C§6oflnet§f]§7: waiting for auction grace period "));
144149
else clickSlot(CONFIRM_SLOT);
145150
}
146151
}
@@ -164,41 +169,34 @@ public void onClick(double mouseX, double mouseY) {
164169
protected void drawBox(DrawContext context) {}
165170

166171
@Override
167-
public boolean mouseReleased(double mouseX, double mouseY, int button) {
168-
if(super.mouseReleased(mouseX, mouseY, button) && isMouseOver(mouseX,mouseY) && button == 0){
169-
rightClickableWidget.onClick(mouseX,mouseY);
170-
}
171-
return super.mouseReleased(mouseX, mouseY, button);
172+
public void onClick(double mouseX, double mouseY) {
173+
rightClickableWidget.onClick(mouseX,mouseY);
172174
}
173175
};
174-
//loreScrollableTextWidget.updateText(Text.of("AAAAAAAAAAAAAa"));
175-
176176

177177
itemWidget = new ItemWidget(
178178
screenWidth / 2 - width / 2 + p + 2,
179179
screenHeight / 2 - height / 2 + p + 12 + p + 2,
180180
Items.AIR.getDefaultStack()
181181
);
182182

183-
this.addDrawableChild(titleTextWidget);
184-
this.addDrawableChild(loreScrollableTextWidget);
185-
this.addDrawableChild(itemWidget);
186-
this.addDrawableChild(rightClickableWidget);
187-
this.addDrawableChild(leftClickableWidget);
188-
189183
gcsh.addListener(new ScreenHandlerListener() {
190184
@Override
191185
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack) {
192186
//if (stack.getItem() != Items.AIR) System.out.println("slotid: "+slotId);
193-
if (slotId == ITEM_SLOT) setItem(stack);
194-
if (auctionStatus != AuctionStatus.CONFIRMING){
195-
if(slotId == BUY_SLOT) setRightButtonConfig(setAuctionStatus(stack.getItem()));
196-
} else if (auctionStatus == AuctionStatus.CONFIRMING && slotId == CONFIRM_SLOT) setRightButtonConfig(AuctionStatus.CONFIRMING);
187+
// if (slotId == ITEM_SLOT) setItem(stack);
188+
if (auctionStatus == AuctionStatus.CONFIRMING && slotId == CONFIRM_SLOT) setRightButtonConfig(AuctionStatus.CONFIRMING);
197189
}
198190

199191
@Override
200192
public void onPropertyUpdate(ScreenHandler handler, int property, int value) {}
201193
});
194+
195+
this.addDrawableChild(titleTextWidget);
196+
this.addDrawableChild(loreScrollableTextWidget);
197+
this.addDrawableChild(itemWidget);
198+
this.addDrawableChild(rightClickableWidget);
199+
this.addDrawableChild(leftClickableWidget);
202200
}
203201

204202
private void clickSlot(int slotId) {
@@ -225,7 +223,6 @@ private void setRightButtonConfig(AuctionStatus auctionStatus){
225223
case INIT:
226224
case BUYING:
227225
case WAITING:
228-
System.out.println("CASE ENTERED");
229226
rightButtonCol = new Pair<>(CoflColConfig.CONFIRM, CoflColConfig.CONFIRM_HOVER);
230227
rightClickableWidget.setMessage(Text.of("Buy (You can click anywhere)"));
231228
break;
@@ -250,12 +247,12 @@ public MutableText convertTextList(List<Text> collection){
250247
MutableText res = Text.empty();
251248
if (collection == null || collection.isEmpty()) return res;
252249

253-
res = Text.literal(collection.getFirst().getString()).setStyle(collection.getFirst().getStyle());
250+
res.append(collection.getFirst());
254251
collection.removeFirst();
255252

256253
for (Text text : collection) {
257-
MutableText toAppend = Text.literal("\n"+text.getString()).setStyle(text.getStyle());
258-
res.append(toAppend);
254+
res.append(Text.literal("\n"));
255+
res.append(text);
259256
}
260257
return res;
261258
}
@@ -269,6 +266,10 @@ public boolean shouldPause() {
269266
public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
270267
int screenWidth = MinecraftClient.getInstance().currentScreen.width;
271268
int screenHeight = MinecraftClient.getInstance().currentScreen.height;
269+
if(!gcsh.getInventory().isEmpty()){
270+
if (gcsh.getInventory().getStack(ITEM_SLOT).getItem() != Items.AIR) setItem(gcsh.getInventory().getStack(ITEM_SLOT));
271+
if (gcsh.getInventory().getStack(BUY_SLOT).getItem() != Items.AIR) setRightButtonConfig(setAuctionStatus(gcsh.getInventory().getStack(ITEM_SLOT).getItem()));
272+
}
272273

273274
// Background
274275
RenderUtils.drawRoundedRect(drawContext, screenWidth / 2 - width / 2,screenHeight / 2 - height / 2, width, height, r, CoflColConfig.BACKGROUND_PRIMARY);
@@ -282,6 +283,7 @@ public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, fl
282283

283284
@Override
284285
public void close() {
286+
auctionStatus = AuctionStatus.INIT;
285287
gcs.close();
286288
super.close();
287289
}

src/client/java/com/coflnet/gui/cofl/CoflColConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public abstract class CoflColConfig {
88
public static final int CANCEL = 0xFFB21E1E;
99
public static final int CANCEL_HOVER = 0xFFf75555;
1010
public static final int UNAVAILABLE = 0xFFD07916;
11-
public static final int TEXT_PRIMARY = 0xFFFFFFFF;
11+
public static final int TEXT_PRIMARY = 0xFFEEEEEE;
1212
}

0 commit comments

Comments
 (0)