Skip to content

Commit 58e6c5d

Browse files
committed
updated RenderUtils / diverse changes
1 parent 2a628c8 commit 58e6c5d

File tree

5 files changed

+54
-61
lines changed

5 files changed

+54
-61
lines changed

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.fabricmc.loader.api.FabricLoader;
3232
import net.minecraft.client.MinecraftClient;
3333
import net.minecraft.client.font.TextRenderer;
34+
import net.minecraft.client.gui.screen.ChatScreen;
3435
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
3536
import net.minecraft.client.option.KeyBinding;
3637
import net.minecraft.client.util.InputUtil;
@@ -124,9 +125,6 @@ public void onInitializeClient() {
124125
dispatcher.register(ClientCommandManager.literal("cofl")
125126
.then(ClientCommandManager.argument("args", StringArgumentType.greedyString()).executes(context -> {
126127
String[] args = context.getArgument("args", String.class).split(" ");
127-
// if (args[0].compareToIgnoreCase("openauctiongui") == 0){
128-
// flip = CoflCore.flipHandler.fds.getFlipById(args[1]);
129-
// } else flip = null;
130128
CoflSkyCommand.processCommand(args,username);
131129
return 1;
132130
})));
@@ -140,7 +138,7 @@ public void onInitializeClient() {
140138
&& gcs.getScreenHandler().getInventory().size() == 9 * 6
141139
|| gcs.getTitle().getString().contains("Confirm Purchase")
142140
&& gcs.getScreenHandler().getInventory().size() == 9 * 3)
143-
) {
141+
){
144142
if (!(client.currentScreen instanceof CoflBinGUI || client.currentScreen instanceof TfmBinGUI)) {
145143
switch (CoflCore.config.purchaseOverlay) {
146144
case COFL: client.setScreen(new CoflBinGUI(gcs));break;
@@ -153,17 +151,14 @@ public void onInitializeClient() {
153151
});
154152

155153
HudRenderCallback.EVENT.register((drawContext, tickCounter) -> {
156-
if (showCountdown && countdownData != null){
157-
//RenderUtils.drawString(drawContext, "New flips in: "+String.format("%.1f", countdown), 10, 10, 0xFFFFFFFF);
158-
MinecraftClient.getInstance().textRenderer.draw(
159-
countdownData.getPrefix()+String.format("New flips in: %.1f", countdown),
154+
if (showCountdown && countdownData != null
155+
&& (MinecraftClient.getInstance().currentScreen == null
156+
|| MinecraftClient.getInstance().currentScreen instanceof ChatScreen)){
157+
RenderUtils.drawStringWithShadow(
158+
drawContext, countdownData.getPrefix()+"New flips in: "+String.format("%.1f", countdown),
160159
MinecraftClient.getInstance().getWindow().getWidth()/countdownData.getWidthPercentage(),
161160
MinecraftClient.getInstance().getWindow().getHeight()/countdownData.getHeightPercentage(),
162-
0xFFFFFFFF, false,
163-
drawContext.getMatrices().peek().getPositionMatrix(),
164-
drawContext.getVertexConsumers(),
165-
TextRenderer.TextLayerType.NORMAL,
166-
0x00FFFFFF, 100
161+
0xFFFFFFFF, countdownData.getScale()
167162
);
168163
}
169164
});

src/client/java/com/coflnet/gui/BinGUI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import net.minecraft.client.gui.screen.Screen;
99
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
1010
import net.minecraft.entity.player.PlayerEntity;
11+
import net.minecraft.item.Item;
1112
import net.minecraft.item.ItemStack;
13+
import net.minecraft.item.Items;
1214
import net.minecraft.screen.GenericContainerScreenHandler;
1315
import net.minecraft.screen.ScreenHandlerType;
1416
import net.minecraft.screen.slot.SlotActionType;
@@ -91,6 +93,14 @@ protected void clickSlot(int slotId) {
9193
);
9294
}
9395

96+
protected AuctionStatus updateAuctionStatus(Item item){
97+
if (item == Items.GOLD_NUGGET) auctionStatus = AuctionStatus.BUYING;
98+
if (item == Items.RED_BED) auctionStatus = AuctionStatus.WAITING;
99+
if (item == Items.POTATO) auctionStatus = AuctionStatus.SOLD;
100+
if (item == Items.GREEN_TERRACOTTA) auctionStatus = AuctionStatus.CONFIRMING;
101+
return auctionStatus;
102+
}
103+
94104
@Override
95105
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
96106
if (screenWidth != MinecraftClient.getInstance().currentScreen.width

src/client/java/com/coflnet/gui/RenderUtils.java

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.client.font.TextRenderer;
66
import net.minecraft.client.gui.DrawContext;
77
import net.minecraft.client.render.*;
8+
import net.minecraft.client.util.math.MatrixStack;
89
import net.minecraft.item.ItemStack;
910
import org.jetbrains.annotations.NotNull;
1011
import org.lwjgl.opengl.GL11;
@@ -30,15 +31,13 @@ public static void init(){
3031
//draw a rectangle
3132
public static void drawRect(DrawContext context, float x, float y, float width, float height, int color) {
3233
buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
33-
34+
3435
buffer.vertex(context.getMatrices().peek().getPositionMatrix(), x, y, z).color(color);
3536
buffer.vertex(context.getMatrices().peek().getPositionMatrix(), x, y + height, z).color(color);
3637
buffer.vertex(context.getMatrices().peek().getPositionMatrix(), x + width, y + height, z).color(color);
3738
buffer.vertex(context.getMatrices().peek().getPositionMatrix(), x + width, y, z).color(color);
3839

3940
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
40-
//RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 0.0F);
41-
4241
BufferRenderer.drawWithGlobalProgram(buffer.end());
4342
}
4443

@@ -157,14 +156,11 @@ public static void drawLoadingCircle(DrawContext context, float x, float y, floa
157156

158157
//draws a rounded rectangle with a given radius and color and size
159158
public static void drawRoundedRect(DrawContext context, int x, int y, int width, int height, int radius, @NotNull int color) {
160-
161159
//draw the two rectangles
162160
drawRect(context, x + radius, y, width - radius * 2, height, color);
163161
drawRect(context, x, y + radius, radius, height - radius * 2, color);
164162
drawRect(context, x + width - radius, y + radius, radius, height - radius * 2, color);
165163

166-
//drawRect(x + radius, y, width - radius - radius, height, color.getRGB());
167-
//drawRect(x, y + radius, width, height - radius - radius, color.getRGB());
168164
//draw the circles
169165
//drawArc(x + radius, y + radius, radius, 180, 270, color);
170166
//drawArc(x + width - radius, y + radius, radius, 90, 180, color);
@@ -229,41 +225,34 @@ public static void drawCenteredStringWithShadow(DrawContext context, String text
229225
true
230226
);
231227
}
232-
/*
228+
233229
//draws a string with custom scale
234-
public static void drawString(String text, int x, int y, int color, int scale) {
235-
drawContext.drawText(textRenderer, text, x, y, color, false);
230+
private static void drawString(DrawContext context, String text, int x, int y, int color, int scale, boolean centered, boolean shadow) {
231+
MatrixStack ms = context.getMatrices();
232+
ms.push();
233+
ms.scale(scale,scale,0);
234+
context.drawText(textRenderer, text, centered ? x - textRenderer.getWidth(text) / 2 : x, y, color, shadow);
235+
ms.pop();
236236
}
237237

238-
//draws a string with custom scale and shadow
239-
public static void drawStringWithShadow(String text, int x, int y, Color color, int scale) {
240-
setColor(color);
241-
FontRenderer fr = mc.fontRendererObj;
242-
fr.drawStringWithShadow(text, x, y, color.getRGB());
238+
//draws a string with custom scale
239+
public static void drawString(DrawContext context, String text, int x, int y, int color, int scale) {
240+
drawString(context, text, x, y, color, scale, false, false);
243241
}
244242

245-
public static void drawCenteredString(String text, int x, int y, Color color, int scale) {
246-
setColor(color);
247-
FontRenderer fr = mc.fontRendererObj;
248-
fr.drawString(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
243+
//draws a string with custom scale and shadow
244+
public static void drawStringWithShadow(DrawContext context, String text, int x, int y, int color, int scale) {
245+
drawString(context, text, x, y, color, scale, false, true);
249246
}
250247

251-
public static void drawCenteredStringWithShadow(String text, int x, int y, Color color, int scale) {
252-
setColor(color);
253-
FontRenderer fr = mc.fontRendererObj;
254-
fr.drawStringWithShadow(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
248+
public static void drawCenteredString(DrawContext context, String text, int x, int y, int color, int scale) {
249+
drawString(context, text, x, y, color, scale, true, false);
255250
}
256251

257-
public static void drawCenteredStringWithShadow(String text, int x, int y, Color color, int scale, boolean centered) {
258-
setColor(color);
259-
FontRenderer fr = mc.fontRendererObj;
260-
if (centered) {
261-
fr.drawStringWithShadow(text, x - fr.getStringWidth(text) / 2, y, color.getRGB());
262-
} else {
263-
fr.drawStringWithShadow(text, x, y, color.getRGB());
264-
}
252+
public static void drawCenteredStringWithShadow(DrawContext context, String text, int x, int y, int color, int scale) {
253+
drawString(context, text, x, y, color, scale, true, true);
265254
}
266-
*/
255+
267256
//draws an ItemStack at a given position with a given scale
268257
public static void drawItemStack(DrawContext context, ItemStack itemStack, int x, int y, float scale) {
269258
context.drawItem(itemStack, x, y, 0, z);

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

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

3-
import CoflCore.CoflCore;
4-
import CoflCore.commands.models.FlipData;
5-
import com.coflnet.CoflModClient;
63
import com.coflnet.gui.AuctionStatus;
74
import com.coflnet.gui.BinGUI;
85
import com.coflnet.gui.RenderUtils;
@@ -15,7 +12,6 @@
1512
import net.minecraft.client.gui.widget.*;
1613
import net.minecraft.item.Item;
1714
import net.minecraft.item.Items;
18-
import net.minecraft.screen.ScreenHandlerType;
1915
import net.minecraft.text.MutableText;
2016
import net.minecraft.text.Text;
2117
import oshi.util.tuples.Pair;
@@ -138,7 +134,7 @@ public void onClick(double mouseX, double mouseY) {
138134
}
139135
};
140136

141-
if (auctionStatus == AuctionStatus.CONFIRMING) setRightButtonConfig(AuctionStatus.CONFIRMING);
137+
if(auctionStatus.compareTo(AuctionStatus.CONFIRMING) == 0) setRightButtonConfig(auctionStatus);
142138

143139
this.addDrawableChild(titleTextWidget);
144140
this.addDrawableChild(loreScrollableTextWidget);
@@ -147,13 +143,6 @@ public void onClick(double mouseX, double mouseY) {
147143
this.addDrawableChild(itemWidget);
148144
}
149145

150-
private AuctionStatus setAuctionStatus(Item item){
151-
if (item == Items.GOLD_NUGGET) auctionStatus = AuctionStatus.BUYING;
152-
if (item == Items.RED_BED) auctionStatus = AuctionStatus.WAITING;
153-
if (item == Items.POTATO) auctionStatus = AuctionStatus.SOLD;
154-
return auctionStatus;
155-
}
156-
157146
private void setRightButtonConfig(AuctionStatus auctionStatus){
158147
switch (auctionStatus){
159148
case INIT:
@@ -196,9 +185,18 @@ public void renderBackground(DrawContext drawContext, int mouseX, int mouseY, fl
196185
if (gcsh.getInventory().getStack(ITEM_SLOT).getItem() != Items.AIR) {
197186
setItem(gcsh.getInventory().getStack(ITEM_SLOT));
198187
lore = convertTextList(getTooltipFromItem(MinecraftClient.getInstance(), currentItem));
199-
loreScrollableTextWidget.updateText(lore);
188+
loreScrollableTextWidget.updateText(lore == null ? Text.empty() : lore);
189+
}
190+
191+
if (gcsh.getInventory()
192+
.getStack(auctionStatus.compareTo(AuctionStatus.CONFIRMING) == 0 ? CONFIRM_SLOT : BUY_SLOT)
193+
.getItem() != Items.AIR) {
194+
setRightButtonConfig(updateAuctionStatus(
195+
gcsh.getInventory()
196+
.getStack(auctionStatus.compareTo(AuctionStatus.CONFIRMING) == 0 ? CONFIRM_SLOT : BUY_SLOT)
197+
.getItem()
198+
));
200199
}
201-
if (gcsh.getInventory().getStack(BUY_SLOT).getItem() != Items.AIR) setRightButtonConfig(setAuctionStatus(gcsh.getInventory().getStack(ITEM_SLOT).getItem()));
202200
}
203201

204202
// Background

src/client/java/com/coflnet/gui/widget/ScrollableDynamicTextWidget.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.client.gui.widget.MultilineTextWidget;
88
import net.minecraft.client.gui.widget.ScrollableWidget;
99
import net.minecraft.text.Text;
10+
import org.jetbrains.annotations.NotNull;
1011

1112
import java.util.Objects;
1213

@@ -17,11 +18,11 @@ public class ScrollableDynamicTextWidget extends ScrollableWidget {
1718
public ScrollableDynamicTextWidget(int x, int y, int width, int height, Text message, TextRenderer textRenderer) {
1819
super(x, y, width, height, message);
1920
this.textRenderer = textRenderer;
20-
this.wrapped = (new MultilineTextWidget(message, textRenderer)).setMaxWidth(this.getWidth() - this.getPaddingDoubled());
21+
this.wrapped = (new MultilineTextWidget(message == null ? Text.empty() : message, textRenderer)).setMaxWidth(this.getWidth() - this.getPaddingDoubled());
2122
}
2223

2324
public void updateText(Text message) {
24-
this.wrapped = (new MultilineTextWidget(message, textRenderer)).setMaxWidth(this.getWidth() - this.getPaddingDoubled());
25+
this.wrapped = (new MultilineTextWidget(message == null ? Text.empty() : message, textRenderer)).setMaxWidth(this.getWidth() - this.getPaddingDoubled());
2526
}
2627

2728
public ScrollableDynamicTextWidget textColor(int textColor) {
@@ -79,6 +80,6 @@ protected void renderContents(DrawContext context, int mouseX, int mouseY, float
7980
}
8081

8182
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
82-
builder.put(NarrationPart.TITLE, this.getMessage());
83+
builder.put(NarrationPart.TITLE, this.getMessage() == null ? Text.empty() : this.getMessage());
8384
}
8485
}

0 commit comments

Comments
 (0)