-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathScreenMixin.java
More file actions
96 lines (84 loc) · 4.49 KB
/
ScreenMixin.java
File metadata and controls
96 lines (84 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ui_utils.mixin;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.LecternScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.input.KeyInput;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.ui_utils.MainClient;
import com.ui_utils.SharedVariables;
import com.ui_utils.mixin.accessor.ScreenAccessor;
import java.util.regex.Pattern;
@SuppressWarnings("all")
@Mixin(Screen.class)
public abstract class ScreenMixin {
@Shadow
public abstract <T extends Element & Drawable & Selectable> T addDrawableChild(T drawableElement);
private static final MinecraftClient mc = MinecraftClient.getInstance();
private TextFieldWidget addressField;
private boolean initialized = false;
// inject at the end of the render method (if instanceof LecternScreen)
@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 (mc.currentScreen instanceof LecternScreen screen && SharedVariables.enabled) {
// setup widgets
if (/*!this.initialized*/ true) { // bro why did you do this cxg :skull:
// check if the current gui is a lectern gui and ui-utils is enabled
// if you do not message me about this @coderx-gamer you are not reading my commits
// why would you read them anyway tbh
// ill clean this up later if you dont fix it
TextRenderer textRenderer = ((ScreenAccessor) this).getTextRenderer();
MainClient.createWidgets(mc, screen);
// create chat box
this.addressField = new TextFieldWidget(textRenderer, 5, 245, 160, 20, Text.of("Chat ...")) {
@Override
public boolean keyPressed(KeyInput input) {
if (input.getKeycode() == GLFW.GLFW_KEY_ENTER) {
if (this.getText().equals("^toggleuiutils")) {
SharedVariables.enabled = !SharedVariables.enabled;
if (mc.player != null) {
mc.player.sendMessage(Text.of("UI-Utils is now " + (SharedVariables.enabled ? "enabled" : "disabled") + "."), false);
}
return false;
}
if (mc.getNetworkHandler() != null) {
if (this.getText().startsWith("/")) {
mc.getNetworkHandler().sendChatCommand(this.getText().replaceFirst(Pattern.quote("/"), ""));
} else {
mc.getNetworkHandler().sendChatMessage(this.getText());
}
} else {
MainClient.LOGGER.warn("Minecraft network handler (mc.getNetworkHandler()) was null while trying to send chat message from UI Utils.");
}
this.setText("");
}
return super.keyPressed(input);
}
};
this.addressField.setText("");
this.addressField.setMaxLength(255);
this.addDrawableChild(this.addressField);
this.initialized = true;
}
}
}
@Inject(at = @At("TAIL"), method = "render")
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
// display sync id, revision, if ui utils is enabled
if (SharedVariables.enabled && mc.player != null && mc.currentScreen instanceof LecternScreen) {
MainClient.createText(mc, context, ((ScreenAccessor) this).getTextRenderer());
}
}
}