diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-10 04:50:31 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-10 04:52:04 +0200 |
commit | ca17fe502d2ddee6ba0ae62d0b6e8458c6ded2b9 (patch) | |
tree | ea974d1cca165d541b2444e4ed227e45266b12db /src/main/java/moe/nea/firmament/mixins | |
parent | 5a91c407d639cb2224649c2d4875d244321f77f7 (diff) | |
download | Firmament-ca17fe502d2ddee6ba0ae62d0b6e8458c6ded2b9.tar.gz Firmament-ca17fe502d2ddee6ba0ae62d0b6e8458c6ded2b9.tar.bz2 Firmament-ca17fe502d2ddee6ba0ae62d0b6e8458c6ded2b9.zip |
Allow using arrows to navigate in storage overview
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/SlotClickEventPatch.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/SlotClickEventPatch.java b/src/main/java/moe/nea/firmament/mixins/SlotClickEventPatch.java index 4e6d766..d1d05a2 100644 --- a/src/main/java/moe/nea/firmament/mixins/SlotClickEventPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/SlotClickEventPatch.java @@ -7,12 +7,17 @@ package moe.nea.firmament.mixins; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import moe.nea.firmament.events.SlotClickEvent; import net.minecraft.client.network.ClientPlayerInteractionManager; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.SlotActionType; +import org.objectweb.asm.Opcodes; 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; @@ -20,12 +25,19 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPlayerInteractionManager.class) public class SlotClickEventPatch { + @Inject(method = "clickSlot", at = @At(value = "FIELD", target = "Lnet/minecraft/screen/ScreenHandler;slots:Lnet/minecraft/util/collection/DefaultedList;", opcode = Opcodes.GETFIELD)) + private void onSlotClickSaveSlot(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci, @Local ScreenHandler handler, @Share("slotContent") LocalRef<ItemStack> slotContent) { + if (0 <= slotId && slotId < handler.slots.size()) { + slotContent.set(handler.getSlot(slotId).getStack().copy()); + } + } + @Inject(method = "clickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V")) - private void onSlotClick(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci, @Local ScreenHandler handler) { + private void onSlotClick(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci, @Local ScreenHandler handler, @Share("slotContent") LocalRef<ItemStack> slotContent) { if (0 <= slotId && slotId < handler.slots.size()) { SlotClickEvent.Companion.publish(new SlotClickEvent( handler.getSlot(slotId), - handler.getSlot(slotId).getStack(), + slotContent.get(), button, actionType )); |