(MinecraftClient client, int width, int height, CallbackInfo ci)
| 35 | |
| 36 | // inject at the end of the render method (if instanceof LecternScreen) |
| 37 | @Inject(at = @At("TAIL"), method = "init(Lnet/minecraft/client/MinecraftClient;II)V") |
| 38 | public void init(MinecraftClient client, int width, int height, CallbackInfo ci) { |
| 39 | // check if the current gui is a lectern gui and if ui-utils is enabled |
| 40 | if (mc.currentScreen instanceof LecternScreen screen && SharedVariables.enabled) { |
| 41 | // setup widgets |
| 42 | if (/*!this.initialized*/ true) { // bro why did you do this cxg :skull: |
| 43 | // check if the current gui is a lectern gui and ui-utils is enabled |
| 44 | // if you do not message me about this @coderx-gamer you are not reading my commits |
| 45 | // why would you read them anyway tbh |
| 46 | // ill clean this up later if you dont fix it |
| 47 | |
| 48 | TextRenderer textRenderer = ((ScreenAccessor) this).getTextRenderer(); |
| 49 | MainClient.createWidgets(mc, screen); |
| 50 | |
| 51 | // create chat box |
| 52 | this.addressField = new TextFieldWidget(textRenderer, 5, 245, 160, 20, Text.of("Chat ...")) { |
| 53 | @Override |
| 54 | public boolean keyPressed(int keyCode, int scanCode, int modifiers) { |
| 55 | if (keyCode == GLFW.GLFW_KEY_ENTER) { |
| 56 | if (this.getText().equals("^toggleuiutils")) { |
| 57 | SharedVariables.enabled = !SharedVariables.enabled; |
| 58 | if (mc.player != null) { |
| 59 | mc.player.sendMessage(Text.of("UI-Utils is now " + (SharedVariables.enabled ? "enabled" : "disabled") + "."), false); |
| 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | if (mc.getNetworkHandler() != null) { |
| 65 | if (this.getText().startsWith("/")) { |
| 66 | mc.getNetworkHandler().sendChatCommand(this.getText().replaceFirst(Pattern.quote("/"), "")); |
| 67 | } else { |
| 68 | mc.getNetworkHandler().sendChatMessage(this.getText()); |
| 69 | } |
| 70 | } else { |
| 71 | MainClient.LOGGER.warn("Minecraft network handler (mc.getNetworkHandler()) was null while trying to send chat message from UI Utils."); |
| 72 | } |
| 73 | |
| 74 | this.setText(""); |
| 75 | } |
| 76 | return super.keyPressed(keyCode, scanCode, modifiers); |
| 77 | } |
| 78 | }; |
| 79 | this.addressField.setText(""); |
| 80 | this.addressField.setMaxLength(255); |
| 81 | |
| 82 | this.addDrawableChild(this.addressField); |
| 83 | this.initialized = true; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | @Inject(at = @At("TAIL"), method = "render") |
| 89 | public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) { |
nothing calls this directly
no test coverage detected