From f89135db7e500571231721ac8d5b0ffff63469df Mon Sep 17 00:00:00 2001 From: nea Date: Fri, 29 Sep 2023 22:44:13 +0200 Subject: Add UUID Locking (per unique item locking that allows movement) --- .../moe/nea/firmament/mixins/MixinClientPlayerEntity.java | 3 ++- .../java/moe/nea/firmament/mixins/MixinHandledScreen.java | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/main/java/moe/nea/firmament/mixins') diff --git a/src/main/java/moe/nea/firmament/mixins/MixinClientPlayerEntity.java b/src/main/java/moe/nea/firmament/mixins/MixinClientPlayerEntity.java index 21e3308..16e8fc3 100644 --- a/src/main/java/moe/nea/firmament/mixins/MixinClientPlayerEntity.java +++ b/src/main/java/moe/nea/firmament/mixins/MixinClientPlayerEntity.java @@ -10,6 +10,7 @@ import moe.nea.firmament.events.IsSlotProtectedEvent; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.slot.Slot; +import net.minecraft.screen.slot.SlotActionType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -24,7 +25,7 @@ public abstract class MixinClientPlayerEntity extends PlayerEntity { @Inject(method = "dropSelectedItem", at = @At("HEAD"), cancellable = true) public void onDropSelectedItem(boolean entireStack, CallbackInfoReturnable cir) { Slot fakeSlot = new Slot(getInventory(), getInventory().selectedSlot, 0, 0); - if (IsSlotProtectedEvent.shouldBlockInteraction(fakeSlot)) { + if (IsSlotProtectedEvent.shouldBlockInteraction(fakeSlot, SlotActionType.THROW)) { cir.setReturnValue(false); } } diff --git a/src/main/java/moe/nea/firmament/mixins/MixinHandledScreen.java b/src/main/java/moe/nea/firmament/mixins/MixinHandledScreen.java index 84c47cb..3972ffc 100644 --- a/src/main/java/moe/nea/firmament/mixins/MixinHandledScreen.java +++ b/src/main/java/moe/nea/firmament/mixins/MixinHandledScreen.java @@ -10,6 +10,7 @@ import moe.nea.firmament.events.*; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; @@ -63,11 +64,19 @@ public abstract class MixinHandledScreen { @Inject(method = "onMouseClick(Lnet/minecraft/screen/slot/Slot;IILnet/minecraft/screen/slot/SlotActionType;)V", at = @At("HEAD"), cancellable = true) public void onMouseClickedSlot(Slot slot, int slotId, int button, SlotActionType actionType, CallbackInfo ci) { - if (IsSlotProtectedEvent.shouldBlockInteraction(slot)) { + if (slotId == -999 && getScreenHandler() != null && actionType == SlotActionType.PICKUP) { // -999 is code for "clicked outside the main window" + ItemStack cursorStack = getScreenHandler().getCursorStack(); + if (cursorStack != null && IsSlotProtectedEvent.shouldBlockInteraction(slot, SlotActionType.THROW, cursorStack)) { + ci.cancel(); + return; + } + } + if (IsSlotProtectedEvent.shouldBlockInteraction(slot, actionType)) { ci.cancel(); + return; } if (actionType == SlotActionType.SWAP && 0 <= button && button < 9) { - if (IsSlotProtectedEvent.shouldBlockInteraction(new Slot(playerInventory, button, 0, 0))) { + if (IsSlotProtectedEvent.shouldBlockInteraction(new Slot(playerInventory, button, 0, 0), actionType)) { ci.cancel(); } } -- cgit