diff options
author | Linnea Gräf <nea@nea.moe> | 2024-10-01 18:00:43 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-10-01 18:00:43 +0200 |
commit | a4eac70118fc25334c9352712fe3c7944b8bed1d (patch) | |
tree | e0faedfca323e243a64a427d13b4fb31bcea9256 /src/main/java/moe | |
parent | beb14d73bd2d0d48513e540ff629b48f89b95ed9 (diff) | |
download | Firmament-a4eac70118fc25334c9352712fe3c7944b8bed1d.tar.gz Firmament-a4eac70118fc25334c9352712fe3c7944b8bed1d.tar.bz2 Firmament-a4eac70118fc25334c9352712fe3c7944b8bed1d.zip |
Add basic sack util
[no changelog]
Diffstat (limited to 'src/main/java/moe')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/SlotUpdateListener.java | 67 | ||||
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/accessor/AccessorChatHud.java | 14 |
2 files changed, 49 insertions, 32 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/SlotUpdateListener.java b/src/main/java/moe/nea/firmament/mixins/SlotUpdateListener.java index f1d4a80..6c854d4 100644 --- a/src/main/java/moe/nea/firmament/mixins/SlotUpdateListener.java +++ b/src/main/java/moe/nea/firmament/mixins/SlotUpdateListener.java @@ -1,13 +1,12 @@ package moe.nea.firmament.mixins; -import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.events.ChestInventoryUpdateEvent; import moe.nea.firmament.events.PlayerInventoryUpdate; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientCommonNetworkHandler; import net.minecraft.client.network.ClientConnectionState; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.InventoryS2CPacket; import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; @@ -18,36 +17,40 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPlayNetworkHandler.class) public abstract class SlotUpdateListener extends ClientCommonNetworkHandler { - protected SlotUpdateListener(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { - super(client, connection, connectionState); - } + protected SlotUpdateListener(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { + super(client, connection, connectionState); + } - @Inject( - method = "onScreenHandlerSlotUpdate", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/tutorial/TutorialManager;onSlotUpdate(Lnet/minecraft/item/ItemStack;)V")) - private void onSingleSlotUpdate( - ScreenHandlerSlotUpdateS2CPacket packet, - CallbackInfo ci) { - var player = this.client.player; - assert player != null; - if (packet.getSyncId() == ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID - || packet.getSyncId() == 0) { - PlayerInventoryUpdate.Companion.publish(new PlayerInventoryUpdate.Single(packet.getSlot(), packet.getStack())); - } else if (packet.getSyncId() == player.currentScreenHandler.syncId) { - // TODO: dispatch single chest slot - } - } + @Inject( + method = "onScreenHandlerSlotUpdate", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/tutorial/TutorialManager;onSlotUpdate(Lnet/minecraft/item/ItemStack;)V")) + private void onSingleSlotUpdate( + ScreenHandlerSlotUpdateS2CPacket packet, + CallbackInfo ci) { + var player = this.client.player; + assert player != null; + if (packet.getSyncId() == ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID + || packet.getSyncId() == 0) { + PlayerInventoryUpdate.Companion.publish(new PlayerInventoryUpdate.Single(packet.getSlot(), packet.getStack())); + } else if (packet.getSyncId() == player.currentScreenHandler.syncId) { + ChestInventoryUpdateEvent.Companion.publish( + new ChestInventoryUpdateEvent.Single(packet.getSlot(), packet.getStack()) + ); + } + } - @Inject(method = "onInventory", - at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", - shift = At.Shift.AFTER)) - private void onMultiSlotUpdate(InventoryS2CPacket packet, CallbackInfo ci) { - var player = this.client.player; - assert player != null; - if (packet.getSyncId() == 0) { - PlayerInventoryUpdate.Companion.publish(new PlayerInventoryUpdate.Multi(packet.getContents())); - } else if (packet.getSyncId() == player.currentScreenHandler.syncId) { - // TODO: dispatch multi chest - } - } + @Inject(method = "onInventory", + at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/packet/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", + shift = At.Shift.AFTER)) + private void onMultiSlotUpdate(InventoryS2CPacket packet, CallbackInfo ci) { + var player = this.client.player; + assert player != null; + if (packet.getSyncId() == 0) { + PlayerInventoryUpdate.Companion.publish(new PlayerInventoryUpdate.Multi(packet.getContents())); + } else if (packet.getSyncId() == player.currentScreenHandler.syncId) { + ChestInventoryUpdateEvent.Companion.publish( + new ChestInventoryUpdateEvent.Multi(packet.getContents()) + ); + } + } } diff --git a/src/main/java/moe/nea/firmament/mixins/accessor/AccessorChatHud.java b/src/main/java/moe/nea/firmament/mixins/accessor/AccessorChatHud.java new file mode 100644 index 0000000..72a72f0 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/accessor/AccessorChatHud.java @@ -0,0 +1,14 @@ +package moe.nea.firmament.mixins.accessor; + +import net.minecraft.client.gui.hud.ChatHud; +import net.minecraft.client.gui.hud.ChatHudLine; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(ChatHud.class) +public interface AccessorChatHud { + @Accessor("messages") + List<ChatHudLine> getMessages_firmament(); +} |