Skip to content

Commit

Permalink
Update for v1.4.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Coderx-Gamer authored Nov 6, 2023
1 parent 01febb8 commit 747dd76
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 47 deletions.
18 changes: 9 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
# check these on https://fabricmc.net/develop
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22

# Mod Properties
mod_version = 1.4.0
maven_group = org.uiutils
archives_base_name = uiutils
mod_version = 1.4.1
maven_group = org.uiutils
archives_base_name = uiutils

# Dependencies
fabric_version=0.89.2+1.20.2
fabric_version=0.89.2+1.20.2
21 changes: 9 additions & 12 deletions src/main/java/org/uiutils/MainClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public class MainClient implements ClientModInitializer {
public static Color darkWhite;

public static KeyBinding restoreScreenKey;
public static boolean isMac = false;

@Override
public void onInitializeClient() {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("mac") || os.contains("darwin") || os.contains("osx")) {
isMac = true;
SharedVariables.isMac = true;
}

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

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

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

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

screen.addDrawableChild(ButtonWidget.builder(Text.of("Copy GUI Title JSON"), (button) -> {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/uiutils/SharedVariables.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class SharedVariables {
public static ScreenHandler storedScreenHandler = null;

public static boolean enabled = true;
public static boolean isMac = false;
}
10 changes: 4 additions & 6 deletions src/main/java/org/uiutils/mixin/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ protected HandledScreenMixin(Text title) {
@Inject(at = @At("TAIL"), method = "init")
public void init(CallbackInfo ci) {
if (SharedVariables.enabled) {
MainClient.createWidgets(mc, this, this.textRenderer);
MainClient.createWidgets(mc, this);

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

// inject at the end of the render method
@Inject(at = @At("HEAD"), method = "render")
@Inject(at = @At("TAIL"), method = "render")
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
super.render(context, mouseX, mouseY, delta);

// display sync id, revision, and credit if ui utils is enabled
if (SharedVariables.enabled) {
// display sync id and revision
MainClient.createText(mc, context, this.textRenderer);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/uiutils/mixin/ScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public abstract class ScreenMixin {
private boolean initialized = false;

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

// create chat box
this.addressField = new TextFieldWidget(textRenderer, 5, 245, 200, 20, Text.of("Chat ...")) {
Expand Down Expand Up @@ -73,8 +73,13 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
this.addDrawableChild(this.addressField);
this.initialized = true;
}
}
}

// display sync id, revision, and credit
@Inject(at = @At("TAIL"), method = "render")
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
// display sync id, revision, and credit if ui utils is enabled
if (SharedVariables.enabled && mc.player != null && mc.currentScreen instanceof LecternScreen) {
MainClient.createText(mc, context, ((ScreenAccessor) this).getTextRenderer());
}
}
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/org/uiutils/mixin/SignEditScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ protected SignEditScreenMixin(Text title) {
@Inject(at = @At("TAIL"), method = "init")
public void init(CallbackInfo ci) {

// register "close without packet" button for SignEditScreen
addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> {
// disables sign editing and closes the current gui without sending a packet
SharedVariables.shouldEditSign = false;
mc.setScreen(null);
}).width(160).position(5, 5).build());
// register "close without packet" button for SignEditScreen if ui utils is enabled
if (SharedVariables.enabled) {
addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> {
// disables sign editing and closes the current gui without sending a packet
SharedVariables.shouldEditSign = false;
mc.setScreen(null);
}).width(115).position(5, 5).build());
addDrawableChild(ButtonWidget.builder(Text.of("Disconnect"), (button) -> {
if (mc.getNetworkHandler() != null) {
mc.getNetworkHandler().getConnection().disconnect(Text.of("Disconnecting (UI-UTILS)"));
}
}).width(115).position(5, 35).build());
}
}
}
18 changes: 11 additions & 7 deletions src/main/java/org/uiutils/mixin/SleepingChatScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.uiutils.SharedVariables;

@Mixin(SleepingChatScreen.class)
public class SleepingChatScreenMixin extends Screen {
Expand All @@ -16,14 +17,17 @@ protected SleepingChatScreenMixin(Text title) {
}

// called when SleepingChatScreen is created
// FIXME: check if ui utils is enabled before rendering
@Inject(at = @At("TAIL"), method = "init")
public void init(CallbackInfo ci) {
// register "client wake up" button for SleepingChatScreen
addDrawableChild(ButtonWidget.builder(Text.of("Client wake up"), (button) -> {
// wakes the player up client-side
client.player.wakeUp();
client.setScreen(null);
}).width(160).position(5, 5).build());
// register "client wake up" button for SleepingChatScreen if ui utils is enabled
if (SharedVariables.enabled) {
addDrawableChild(ButtonWidget.builder(Text.of("Client wake up"), (button) -> {
// wakes the player up client-side
if (this.client != null && this.client.player != null) {
this.client.player.wakeUp();
this.client.setScreen(null);
}
}).width(115).position(5, 5).build());
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Coderx_Gamer"
],
"contact": {
"homepage": "https://github.com/Coderx-Gamer/ui-utils/releases/latest/",
"homepage": "https://ui-utils.com/",
"sources": "https://github.com/Coderx-Gamer/ui-utils/"
},

Expand Down

0 comments on commit 747dd76

Please sign in to comment.