Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/mixin/MixinSendPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package fi.dy.masa.tweakeroo.mixin;

import fi.dy.masa.tweakeroo.util.PendingPackets;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.Packet;
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 java.util.List;

@Mixin(ClientCommonNetworkHandler.class)
public class MixinSendPacket {
@Shadow
protected ClientConnection connection;

@Inject(method = "sendPacket(Lnet/minecraft/network/packet/Packet;)V", at = @At("TAIL"))
private void afterSendPacket(Packet<?> packet, CallbackInfo ci) {
List<Packet<?>> pendingPackets = PendingPackets.getPackets(packet.getClass());
if (pendingPackets == null) return;
pendingPackets.forEach(p -> this.connection.send(p));
}
}
4 changes: 3 additions & 1 deletion src/main/java/fi/dy/masa/tweakeroo/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.item.SwordItem;
import net.minecraft.item.ToolItem;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket;
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket;
import net.minecraft.registry.Registries;
import net.minecraft.screen.PlayerScreenHandler;
Expand Down Expand Up @@ -806,7 +807,8 @@ private static void swapItemToHand(PlayerEntity player, Hand hand, int slotNumbe
if (isHotbarSlot(slotNumber))
{
inventory.selectedSlot = slotNumber - 36;
mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot));
PendingPackets.addPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot), PlayerInteractItemC2SPacket.class);
// mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(inventory.selectedSlot));
}
else
{
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/fi/dy/masa/tweakeroo/util/PendingPackets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fi.dy.masa.tweakeroo.util;

import net.minecraft.network.packet.Packet;
import org.jetbrains.annotations.Nullable;

import java.util.*;

public class PendingPackets {
private static final Map<Class<?>, List<Packet<?>>> packets = new HashMap<>();

public static void addPacket(Packet<?> packet, Class<?> after) {
if (packets.containsKey(after)) {
packets.get(after).add(packet);
} else {
LinkedList<Packet<?>> p = new LinkedList<>();
p.add(packet);
packets.put(after, p);
}
}

@Nullable
public static List<Packet<?>> getPackets(Class<?> currentPacketClass) {
if (packets.containsKey(currentPacketClass)) {
return packets.remove(currentPacketClass);
} else {
return null;
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/mixins.tweakeroo.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"MixinUpdateStructureBlockC2SPacket",
"MixinWindow",
"MixinWorld",
"MixinWorldRenderer"
"MixinWorldRenderer",
"MixinSendPacket"
],
"mixinPriority": 990,
"injectors": {
Expand Down