package net.radsteve.islanders.mixin; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.EnderChestInventory; import net.minecraft.item.ItemStack; import net.minecraft.registry.tag.ItemTags; import net.minecraft.screen.CraftingScreenHandler; import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.util.collection.DefaultedList; import net.radsteve.islanders.SpecialItem; import org.spongepowered.asm.mixin.Final; 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; @Mixin(ScreenHandler.class) public abstract class ScreenHandlerMixin { @Final @Shadow public DefaultedList slots; @Shadow public abstract ItemStack getCursorStack(); @Inject(method = "internalOnSlotClick", at = @At("HEAD"), cancellable = true) private void islanders$internalOnSlotClick$shulkerBoxes(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { if (!(ScreenHandler.class.cast(this) instanceof GenericContainerScreenHandler handler)) { return; } if (!(handler.getInventory() instanceof EnderChestInventory)) { return; } if (actionType == SlotActionType.QUICK_MOVE) { final Slot slot = slots.get(slotIndex); if (slot.getStack().getRegistryEntry().isIn(ItemTags.SHULKER_BOXES)) { ci.cancel(); } return; } final int actualScreenSlots = slots.size() - player.playerScreenHandler.slots.size() + 9 /* hotbar */; if (actionType == SlotActionType.SWAP) { final ItemStack stack = player.getInventory().getStack(button); if (stack.getRegistryEntry().isIn(ItemTags.SHULKER_BOXES)) { ci.cancel(); } return; } if (slotIndex < 0 || slotIndex > actualScreenSlots) { return; } if (getCursorStack().getRegistryEntry().isIn(ItemTags.SHULKER_BOXES)) { ci.cancel(); } } @Inject(method = "internalOnSlotClick", at = @At("HEAD"), cancellable = true) private void islanders$internalOnSlotClick$specialItems(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { if ((Object) this instanceof PlayerScreenHandler) { return; } if ((Object) this instanceof CraftingScreenHandler) { return; } if (actionType == SlotActionType.QUICK_MOVE) { final Slot slot = slots.get(slotIndex); if (SpecialItem.Companion.find(slot.getStack()) != null) { ci.cancel(); } return; } final int actualScreenSlots = slots.size() - player.playerScreenHandler.slots.size() + 9 /* hotbar */; if (actionType == SlotActionType.SWAP) { final ItemStack stack = player.getInventory().getStack(button); if (SpecialItem.Companion.find(stack) != null) { ci.cancel(); } return; } if (slotIndex < 0 || slotIndex > actualScreenSlots) { return; } if (SpecialItem.Companion.find(getCursorStack()) != null) { ci.cancel(); } } }