Skip to content

Commit 747dd76

Browse files
authored
Update for v1.4.1.
1 parent 01febb8 commit 747dd76

File tree

8 files changed

+59
-47
lines changed

8 files changed

+59
-47
lines changed

gradle.properties

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Done to increase the memory available to gradle.
2-
org.gradle.jvmargs=-Xmx2G
2+
org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
5-
# check these on https://fabricmc.net/develop
6-
minecraft_version=1.20.2
7-
yarn_mappings=1.20.2+build.1
8-
loader_version=0.14.22
5+
# check these on https://fabricmc.net/develop
6+
minecraft_version=1.20.2
7+
yarn_mappings=1.20.2+build.1
8+
loader_version=0.14.22
99

1010
# Mod Properties
11-
mod_version = 1.4.0
12-
maven_group = org.uiutils
13-
archives_base_name = uiutils
11+
mod_version = 1.4.1
12+
maven_group = org.uiutils
13+
archives_base_name = uiutils
1414

1515
# Dependencies
16-
fabric_version=0.89.2+1.20.2
16+
fabric_version=0.89.2+1.20.2

src/main/java/org/uiutils/MainClient.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ public class MainClient implements ClientModInitializer {
3434
public static Color darkWhite;
3535

3636
public static KeyBinding restoreScreenKey;
37-
public static boolean isMac = false;
3837

3938
@Override
4039
public void onInitializeClient() {
4140
String os = System.getProperty("os.name").toLowerCase();
4241
if (os.contains("mac") || os.contains("darwin") || os.contains("osx")) {
43-
isMac = true;
42+
SharedVariables.isMac = true;
4443
}
4544

4645
// register "restore screen" key
@@ -58,7 +57,7 @@ public void onInitializeClient() {
5857
});
5958

6059
// set java.awt.headless to false if os is not mac (allows for jframe guis to be used)
61-
if (!isMac) {
60+
if (!SharedVariables.isMac) {
6261
System.setProperty("java.awt.headless", "false");
6362
monospace = new Font(Font.MONOSPACED, Font.PLAIN, 10);
6463
darkWhite = new Color(220, 220, 220);
@@ -73,7 +72,7 @@ public static void createText(MinecraftClient mc, DrawContext context, TextRende
7372
context.drawText(textRenderer, "UI-Utils made by Coderx Gamer.", 10, mc.currentScreen.height - 20, Color.WHITE.getRGB(), false);
7473
}
7574

76-
public static void createWidgets(MinecraftClient mc, Screen screen, TextRenderer textRenderer) {
75+
public static void createWidgets(MinecraftClient mc, Screen screen) {
7776
// register "close without packet" button in all HandledScreens
7877
screen.addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> {
7978
// closes the current gui without sending a packet to the current server
@@ -119,14 +118,12 @@ public static void createWidgets(MinecraftClient mc, Screen screen, TextRenderer
119118
// register "disconnect and send packets" button in all HandledScreens
120119
screen.addDrawableChild(ButtonWidget.builder(Text.of("Disconnect and send packets"), (button) -> {
121120
// sends all "delayed" gui related packets before disconnecting, use: potential race conditions on non-vanilla servers
122-
if (!SharedVariables.delayedUIPackets.isEmpty()) {
123-
SharedVariables.delayUIPackets = false;
124-
for (Packet<?> packet : SharedVariables.delayedUIPackets) {
125-
mc.getNetworkHandler().sendPacket(packet);
126-
}
127-
mc.getNetworkHandler().getConnection().disconnect(Text.of("Disconnecting (UI UTILS)"));
128-
SharedVariables.delayedUIPackets.clear();
121+
SharedVariables.delayUIPackets = false;
122+
for (Packet<?> packet : SharedVariables.delayedUIPackets) {
123+
mc.getNetworkHandler().sendPacket(packet);
129124
}
125+
mc.getNetworkHandler().getConnection().disconnect(Text.of("Disconnecting (UI-UTILS)"));
126+
SharedVariables.delayedUIPackets.clear();
130127
}).width(160).position(5, 155).build());
131128

132129
// register "fabricate packet" button in all HandledScreens
@@ -444,7 +441,7 @@ public static void createWidgets(MinecraftClient mc, Screen screen, TextRenderer
444441
frame.add(buttonClickButton);
445442
frame.setVisible(true);
446443
}).width(115).position(5, 185).build();
447-
fabricatePacketButton.active = !isMac;
444+
fabricatePacketButton.active = !SharedVariables.isMac;
448445
screen.addDrawableChild(fabricatePacketButton);
449446

450447
screen.addDrawableChild(ButtonWidget.builder(Text.of("Copy GUI Title JSON"), (button) -> {

src/main/java/org/uiutils/SharedVariables.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ public class SharedVariables {
1717
public static ScreenHandler storedScreenHandler = null;
1818

1919
public static boolean enabled = true;
20+
public static boolean isMac = false;
2021
}

src/main/java/org/uiutils/mixin/HandledScreenMixin.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ protected HandledScreenMixin(Text title) {
3939
@Inject(at = @At("TAIL"), method = "init")
4040
public void init(CallbackInfo ci) {
4141
if (SharedVariables.enabled) {
42-
MainClient.createWidgets(mc, this, this.textRenderer);
42+
MainClient.createWidgets(mc, this);
4343

4444
// create chat box
45-
this.addressField = new TextFieldWidget(textRenderer, 5, 245, 200, 20, Text.of("Chat ...")) {
45+
this.addressField = new TextFieldWidget(this.textRenderer, 5, 245, 200, 20, Text.of("Chat ...")) {
4646
@Override
4747
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
4848
if (keyCode == GLFW.GLFW_KEY_ENTER) {
@@ -95,12 +95,10 @@ public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoRet
9595
}
9696

9797
// inject at the end of the render method
98-
@Inject(at = @At("HEAD"), method = "render")
98+
@Inject(at = @At("TAIL"), method = "render")
9999
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
100-
super.render(context, mouseX, mouseY, delta);
101-
100+
// display sync id, revision, and credit if ui utils is enabled
102101
if (SharedVariables.enabled) {
103-
// display sync id and revision
104102
MainClient.createText(mc, context, this.textRenderer);
105103
}
106104
}

src/main/java/org/uiutils/mixin/ScreenMixin.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public abstract class ScreenMixin {
3333
private boolean initialized = false;
3434

3535
// inject at the end of the render method (if instanceof LecternScreen)
36-
@Inject(at = @At("TAIL"), method = "render")
37-
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
36+
@Inject(at = @At("TAIL"), method = "init(Lnet/minecraft/client/MinecraftClient;II)V")
37+
public void init(MinecraftClient client, int width, int height, CallbackInfo ci) {
3838
// check if the current gui is a lectern gui and if ui-utils is enabled
39-
if ((Object) this instanceof LecternScreen screen && SharedVariables.enabled) {
39+
if (mc.currentScreen instanceof LecternScreen screen && SharedVariables.enabled) {
4040
// setup widgets
41-
if (!this.initialized) {
41+
if (/*!this.initialized*/ true) {
4242
// check if the current gui is a lectern gui and ui-utils is enabled
4343
TextRenderer textRenderer = ((ScreenAccessor) this).getTextRenderer();
44-
MainClient.createWidgets(mc, screen, textRenderer);
44+
MainClient.createWidgets(mc, screen);
4545

4646
// create chat box
4747
this.addressField = new TextFieldWidget(textRenderer, 5, 245, 200, 20, Text.of("Chat ...")) {
@@ -73,8 +73,13 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
7373
this.addDrawableChild(this.addressField);
7474
this.initialized = true;
7575
}
76+
}
77+
}
7678

77-
// display sync id, revision, and credit
79+
@Inject(at = @At("TAIL"), method = "render")
80+
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
81+
// display sync id, revision, and credit if ui utils is enabled
82+
if (SharedVariables.enabled && mc.player != null && mc.currentScreen instanceof LecternScreen) {
7883
MainClient.createText(mc, context, ((ScreenAccessor) this).getTextRenderer());
7984
}
8085
}

src/main/java/org/uiutils/mixin/SignEditScreenMixin.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ protected SignEditScreenMixin(Text title) {
2323
@Inject(at = @At("TAIL"), method = "init")
2424
public void init(CallbackInfo ci) {
2525

26-
// register "close without packet" button for SignEditScreen
27-
addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> {
28-
// disables sign editing and closes the current gui without sending a packet
29-
SharedVariables.shouldEditSign = false;
30-
mc.setScreen(null);
31-
}).width(160).position(5, 5).build());
26+
// register "close without packet" button for SignEditScreen if ui utils is enabled
27+
if (SharedVariables.enabled) {
28+
addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> {
29+
// disables sign editing and closes the current gui without sending a packet
30+
SharedVariables.shouldEditSign = false;
31+
mc.setScreen(null);
32+
}).width(115).position(5, 5).build());
33+
addDrawableChild(ButtonWidget.builder(Text.of("Disconnect"), (button) -> {
34+
if (mc.getNetworkHandler() != null) {
35+
mc.getNetworkHandler().getConnection().disconnect(Text.of("Disconnecting (UI-UTILS)"));
36+
}
37+
}).width(115).position(5, 35).build());
38+
}
3239
}
3340
}

src/main/java/org/uiutils/mixin/SleepingChatScreenMixin.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.spongepowered.asm.mixin.injection.At;
99
import org.spongepowered.asm.mixin.injection.Inject;
1010
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import org.uiutils.SharedVariables;
1112

1213
@Mixin(SleepingChatScreen.class)
1314
public class SleepingChatScreenMixin extends Screen {
@@ -16,14 +17,17 @@ protected SleepingChatScreenMixin(Text title) {
1617
}
1718

1819
// called when SleepingChatScreen is created
19-
// FIXME: check if ui utils is enabled before rendering
2020
@Inject(at = @At("TAIL"), method = "init")
2121
public void init(CallbackInfo ci) {
22-
// register "client wake up" button for SleepingChatScreen
23-
addDrawableChild(ButtonWidget.builder(Text.of("Client wake up"), (button) -> {
24-
// wakes the player up client-side
25-
client.player.wakeUp();
26-
client.setScreen(null);
27-
}).width(160).position(5, 5).build());
22+
// register "client wake up" button for SleepingChatScreen if ui utils is enabled
23+
if (SharedVariables.enabled) {
24+
addDrawableChild(ButtonWidget.builder(Text.of("Client wake up"), (button) -> {
25+
// wakes the player up client-side
26+
if (this.client != null && this.client.player != null) {
27+
this.client.player.wakeUp();
28+
this.client.setScreen(null);
29+
}
30+
}).width(115).position(5, 5).build());
31+
}
2832
}
2933
}

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"Coderx_Gamer"
1010
],
1111
"contact": {
12-
"homepage": "https://github.com/Coderx-Gamer/ui-utils/releases/latest/",
12+
"homepage": "https://ui-utils.com/",
1313
"sources": "https://github.com/Coderx-Gamer/ui-utils/"
1414
},
1515

0 commit comments

Comments
 (0)