Java Code Examples for net.minecraft.inventory.ClickType#CLONE

The following examples show how to use net.minecraft.inventory.ClickType#CLONE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerQuickStacker.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack slotClick(int slotNum, int dragType, ClickType clickType, EntityPlayer player)
{
    ItemStack stack = ItemQuickStacker.getEnabledItem(player);

    // Middle click
    if (clickType == ClickType.CLONE && dragType == 2 && stack.isEmpty() == false)
    {
        int invSlotNum = this.getSlot(slotNum) != null ? this.getSlot(slotNum).getSlotIndex() : -1;

        if (invSlotNum != -1)
        {
            byte selected = NBTUtils.getByte(stack, ItemQuickStacker.TAG_NAME_CONTAINER, ItemQuickStacker.TAG_NAME_PRESET_SELECTION);
            long mask = NBTUtils.getLong(stack, ItemQuickStacker.TAG_NAME_CONTAINER, ItemQuickStacker.TAG_NAME_PRESET + selected);
            mask ^= (0x1L << invSlotNum);
            NBTUtils.setLong(stack, ItemQuickStacker.TAG_NAME_CONTAINER, ItemQuickStacker.TAG_NAME_PRESET + selected, mask);
        }

        return ItemStack.EMPTY;
    }

    return super.slotClick(slotNum, dragType, clickType, player);
}
 
Example 2
Source File: GuiEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type)
{
    // Custom: middle click on a slot, with a modifier key active
    if (type == ClickType.CLONE && (isShiftKeyDown() || isCtrlKeyDown() || isAltKeyDown()))
    {
        if (slotIn != null)
        {
            slotId = slotIn.slotNumber;
        }

        int action = HotKeys.KEYCODE_MIDDLE_CLICK | HotKeys.getActiveModifierMask();

        // Send a packet to the server
        PacketHandler.INSTANCE.sendToServer(new MessageGuiAction(0, BlockPos.ORIGIN,
                ReferenceGuiIds.GUI_ID_CONTAINER_GENERIC, action, slotId));
    }
    else
    {
        super.handleMouseClick(slotIn, slotId, mouseButton, type);
    }
}
 
Example 3
Source File: FakeSlot.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Override
public ItemStack onClick(EntityPlayer player, int dragType, ClickType clickType) {
	if (clickType == ClickType.CLONE && player.capabilities.isCreativeMode) {
		ItemStack contents = getStack();
		if (!contents.isEmpty()) {
			ItemStack tmp = contents.copy();
			tmp.setCount(tmp.getMaxStackSize());
			player.inventory.setItemStack(tmp);
			return tmp;
		}
	}

	ItemStack held = player.inventory.getItemStack();

	ItemStack place = ItemStack.EMPTY;

	if (!held.isEmpty()) {
		place = held.copy();
		if (!keepSize) place.setCount(1);
	}

	inventory.setInventorySlotContents(slotNumber, place);
	onSlotChanged();
	return place;
}
 
Example 4
Source File: ContainerInventorySwapper.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack slotClick(int slotNum, int dragType, ClickType clickType, EntityPlayer player)
{
    ItemStack stack = this.getContainerItem();

    // Middle click
    if (clickType == ClickType.CLONE && dragType == 2 && stack.isEmpty() == false &&
        (this.playerMainSlotsIncHotbar.contains(slotNum) ||
         this.playerArmorSlots.contains(slotNum) ||
         this.playerOffhandSlots.contains(slotNum) ||
         this.playerBaublesSlots.contains(slotNum)))
    {
        int invSlotNum = this.getSlot(slotNum) != null ? this.getSlot(slotNum).getSlotIndex() : -1;

        if (this.playerBaublesSlots.contains(slotNum))
        {
            invSlotNum += 41;
        }

        if (invSlotNum == -1)
        {
            return ItemStack.EMPTY;
        }

        byte selected = NBTUtils.getByte(stack, ItemInventorySwapper.TAG_NAME_CONTAINER, ItemInventorySwapper.TAG_NAME_PRESET_SELECTION);
        long mask = NBTUtils.getLong(stack, ItemInventorySwapper.TAG_NAME_CONTAINER, ItemInventorySwapper.TAG_NAME_PRESET + selected);
        mask ^= (0x1L << invSlotNum);
        NBTUtils.setLong(stack, ItemInventorySwapper.TAG_NAME_CONTAINER, ItemInventorySwapper.TAG_NAME_PRESET + selected, mask);

        return ItemStack.EMPTY;
    }

    stack = super.slotClick(slotNum, dragType, clickType, player);
    this.detectAndSendChanges();

    return stack;
}
 
Example 5
Source File: ContainerUpgrades.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
	if (clickTypeIn == ClickType.CLONE) {
		Slot slot = getSlot(slotId);
		if (slot.inventory == inventory) {
			ItemStack stack = slot.getStack();
			if (stack.getItem() instanceof IUpgrade && ((IUpgrade) stack.getItem()).canBeDisabled(stack)) {
				inventory.getUpgradePart().setUpgradeDisabled(slot.getStack(), !inventory.getUpgradePart().isUpgradeDisabled(slot.getStack()));
			}
			return ItemStack.EMPTY;
		}
	}
	return super.slotClick(slotId, dragType, clickTypeIn, player);
}
 
Example 6
Source File: ContainerQuickStackerAdvanced.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack slotClick(int slotNum, int dragType, ClickType clickType, EntityPlayer player)
{
    if (this.filterSlots.contains(slotNum))
    {
        this.fakeSlotClick(slotNum, dragType, clickType, player);
        return ItemStack.EMPTY;
    }

    // (Starting) or ending a drag and the dragged slots include at least one of our fake slots
    if (clickType == ClickType.QUICK_CRAFT && slotNum == -999)
    {
        for (int i : this.draggedSlots)
        {
            if (this.filterSlots.contains(i))
            {
                this.fakeSlotClick(i, dragType, clickType, player);
                return ItemStack.EMPTY;
            }
        }
    }
    // Middle click
    else if (clickType == ClickType.CLONE && dragType == 2)
    {
        int invSlotNum = this.getSlot(slotNum) != null ? this.getSlot(slotNum).getSlotIndex() : -1;

        if (invSlotNum == -1 || (invSlotNum >= 36 && invSlotNum != 40))
        {
            return ItemStack.EMPTY;
        }

        long mask = this.teqsa.getEnabledSlotsMask();
        mask ^= (0x1L << invSlotNum);
        this.teqsa.setEnabledSlotsMask(mask);

        return ItemStack.EMPTY;
    }

    ItemStack stack = super.slotClick(slotNum, dragType, clickType, player);

    if (player instanceof EntityPlayerMP)
    {
        this.detectAndSendChanges();
    }

    return stack;
}