|
1 | 1 | package com.ui_utils; |
2 | 2 |
|
3 | 3 | import com.google.common.collect.ImmutableList; |
| 4 | +import com.google.gson.Gson; |
| 5 | +import com.mojang.serialization.JsonOps; |
4 | 6 | import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; |
5 | 7 | import net.fabricmc.api.ClientModInitializer; |
6 | 8 | import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; |
|
14 | 16 | import net.minecraft.client.gui.widget.ButtonWidget; |
15 | 17 | import net.minecraft.client.option.KeyBinding; |
16 | 18 | import net.minecraft.client.util.InputUtil; |
17 | | -import net.minecraft.item.ItemStack; |
18 | 19 | import net.minecraft.network.packet.Packet; |
19 | 20 | import net.minecraft.network.packet.c2s.play.ButtonClickC2SPacket; |
20 | 21 | import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket; |
21 | 22 | import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket; |
22 | 23 | import net.minecraft.screen.slot.SlotActionType; |
| 24 | +import net.minecraft.screen.sync.ItemStackHash; |
23 | 25 | import net.minecraft.text.Text; |
| 26 | +import net.minecraft.text.TextCodecs; |
24 | 27 | import org.jetbrains.annotations.NotNull; |
25 | 28 | import org.lwjgl.glfw.GLFW; |
26 | 29 | import org.slf4j.Logger; |
|
29 | 32 |
|
30 | 33 | import javax.swing.*; |
31 | 34 | import java.awt.*; |
32 | | -import java.util.Objects; |
33 | 35 | import java.util.Timer; |
34 | 36 | import java.util.TimerTask; |
35 | 37 | import java.util.Vector; |
@@ -258,13 +260,13 @@ public static void createWidgets(MinecraftClient mc, Screen screen) { |
258 | 260 | actionField.getSelectedItem() != null) { |
259 | 261 | int syncId = Integer.parseInt(syncIdField.getText()); |
260 | 262 | int revision = Integer.parseInt(revisionField.getText()); |
261 | | - int slot = Integer.parseInt(slotField.getText()); |
262 | | - int button0 = Integer.parseInt(buttonField.getText()); |
| 263 | + short slot = Short.parseShort(slotField.getText()); |
| 264 | + byte button0 = Byte.parseByte(buttonField.getText()); |
263 | 265 | SlotActionType action = MainClient.stringToSlotActionType(actionField.getSelectedItem().toString()); |
264 | 266 | int timesToSend = Integer.parseInt(timesToSendField.getText()); |
265 | 267 |
|
266 | 268 | if (action != null) { |
267 | | - ClickSlotC2SPacket packet = new ClickSlotC2SPacket(syncId, revision, slot, button0, action, ItemStack.EMPTY, new Int2ObjectArrayMap<>()); |
| 269 | + ClickSlotC2SPacket packet = new ClickSlotC2SPacket(syncId, revision, slot, button0, action, new Int2ObjectArrayMap<>(), ItemStackHash.EMPTY); |
268 | 270 | try { |
269 | 271 | Runnable toRun = getFabricatePacketRunnable(mc, delayBox.isSelected(), packet); |
270 | 272 | for (int i = 0; i < timesToSend; i++) { |
@@ -448,7 +450,8 @@ public static void createWidgets(MinecraftClient mc, Screen screen) { |
448 | 450 | throw new IllegalStateException("The current minecraft screen (mc.currentScreen) is null"); |
449 | 451 | } |
450 | 452 | // fixes #137 |
451 | | - mc.keyboard.setClipboard(Text.Serialization.toJsonString(mc.currentScreen.getTitle(), Objects.requireNonNull(MinecraftClient.getInstance().getServer()).getRegistryManager())); |
| 453 | + // From fabric wiki https://docs.fabricmc.net/develop/text-and-translations#serializing-text |
| 454 | + mc.keyboard.setClipboard(new Gson().toJson(TextCodecs.CODEC.encodeStart(JsonOps.INSTANCE, mc.currentScreen.getTitle()).getOrThrow())); |
452 | 455 | } catch (IllegalStateException e) { |
453 | 456 | LOGGER.error("Error while copying title JSON to clipboard", e); |
454 | 457 | } |
|
0 commit comments