(MinecraftClient mc, Screen screen)
| 81 | // this code is very messy, ill clean it up if you dont |
| 82 | // -- MrBreakNFix |
| 83 | public static void createWidgets(MinecraftClient mc, Screen screen) { |
| 84 | // register "close without packet" button in all HandledScreens |
| 85 | screen.addDrawableChild(ButtonWidget.builder(Text.of("Close without packet"), (button) -> { |
| 86 | // closes the current gui without sending a packet to the current server |
| 87 | mc.setScreen(null); |
| 88 | }).width(115).position(5, 5).build()); |
| 89 | |
| 90 | // register "de-sync" button in all HandledScreens |
| 91 | screen.addDrawableChild(ButtonWidget.builder(Text.of("De-sync"), (button) -> { |
| 92 | // keeps the current gui open client-side and closed server-side |
| 93 | if (mc.getNetworkHandler() != null && mc.player != null) { |
| 94 | mc.getNetworkHandler().sendPacket(new CloseHandledScreenC2SPacket(mc.player.currentScreenHandler.syncId)); |
| 95 | } else { |
| 96 | LOGGER.warn("Minecraft network handler or player was null while using 'De-sync' in UI Utils."); |
| 97 | } |
| 98 | }).width(115).position(5, 35).build()); |
| 99 | |
| 100 | // register "send packets" button in all HandledScreens |
| 101 | screen.addDrawableChild(ButtonWidget.builder(Text.of("Send packets: " + SharedVariables.sendUIPackets), (button) -> { |
| 102 | // tells the client if it should send any gui related packets |
| 103 | SharedVariables.sendUIPackets = !SharedVariables.sendUIPackets; |
| 104 | button.setMessage(Text.of("Send packets: " + SharedVariables.sendUIPackets)); |
| 105 | }).width(115).position(5, 65).build()); |
| 106 | |
| 107 | // register "delay packets" button in all HandledScreens |
| 108 | screen.addDrawableChild(ButtonWidget.builder(Text.of("Delay packets: " + SharedVariables.delayUIPackets), (button) -> { |
| 109 | // toggles a setting to delay all gui related packets to be used later when turning this setting off |
| 110 | SharedVariables.delayUIPackets = !SharedVariables.delayUIPackets; |
| 111 | button.setMessage(Text.of("Delay packets: " + SharedVariables.delayUIPackets)); |
| 112 | if (!SharedVariables.delayUIPackets && !SharedVariables.delayedUIPackets.isEmpty() && mc.getNetworkHandler() != null) { |
| 113 | for (Packet<?> packet : SharedVariables.delayedUIPackets) { |
| 114 | mc.getNetworkHandler().sendPacket(packet); |
| 115 | } |
| 116 | if (mc.player != null) { |
| 117 | mc.player.sendMessage(Text.of("Sent " + SharedVariables.delayedUIPackets.size() + " packets."), false); |
| 118 | } |
| 119 | SharedVariables.delayedUIPackets.clear(); |
| 120 | } |
| 121 | }).width(115).position(5, 95).build()); |
| 122 | |
| 123 | // register "save gui" button in all HandledScreens |
| 124 | screen.addDrawableChild(ButtonWidget.builder(Text.of("Save GUI"), (button) -> { |
| 125 | // saves the current gui to a variable to be accessed later |
| 126 | if (mc.player != null) { |
| 127 | SharedVariables.storedScreen = mc.currentScreen; |
| 128 | SharedVariables.storedScreenHandler = mc.player.currentScreenHandler; |
| 129 | } |
| 130 | }).width(115).position(5, 125).build()); |
| 131 | |
| 132 | // register "disconnect and send packets" button in all HandledScreens |
| 133 | screen.addDrawableChild(ButtonWidget.builder(Text.of("Disconnect and send packets"), (button) -> { |
| 134 | // sends all "delayed" gui related packets before disconnecting, use: potential race conditions on non-vanilla servers |
| 135 | SharedVariables.delayUIPackets = false; |
| 136 | if (mc.getNetworkHandler() != null) { |
| 137 | for (Packet<?> packet : SharedVariables.delayedUIPackets) { |
| 138 | mc.getNetworkHandler().sendPacket(packet); |
| 139 | } |
| 140 | mc.getNetworkHandler().getConnection().disconnect(Text.of("Disconnecting (UI-UTILS)")); |
no test coverage detected