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

The following examples show how to use net.minecraft.inventory.ClickType#QUICK_MOVE . 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: SlotUtil.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void adjustPhantomSlot(Slot slot, int mouseButton, ClickType clickTypeIn) {
    ItemStack stackSlot = slot.getStack();
    int stackSize;
    if (clickTypeIn == ClickType.QUICK_MOVE) {
        stackSize = mouseButton == 0 ? (stackSlot.getCount() + 1) / 2 : stackSlot.getCount() * 2;
    } else {
        stackSize = mouseButton == 0 ? stackSlot.getCount() - 1 : stackSlot.getCount() + 1;
    }

    if (stackSize > slot.getSlotStackLimit()) {
        stackSize = slot.getSlotStackLimit();
    }

    stackSlot.setCount(stackSize);

    slot.putStack(stackSlot);
}
 
Example 2
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public ItemStack slotClick(ContainerExtended container, EntityPlayer player, int button, ClickType clickType) {
    ItemStack held = player.inventory.getItemStack();
    if (button == 0 && clickType == ClickType.QUICK_MOVE) {
        NEIClientUtils.cheatItem(getStack(), button, -1);
    } else if (button == 1) {
        putStack(ItemStack.EMPTY);
    } else if (!held.isEmpty()) {
        if (isItemValid(held)) {
            putStack(ItemUtils.copyStack(held, 1));
            player.inventory.setItemStack(ItemStack.EMPTY);
        }
    } else if (getHasStack()) {
        player.inventory.setItemStack(getStack());
    }

    return ItemStack.EMPTY;
}
 
Example 3
Source File: PhantomSlotWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == 1) {
        ItemStack stackHeld;
        try {
            stackHeld = buffer.readItemStack();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        int mouseButton = buffer.readVarInt();
        boolean shiftKeyDown = buffer.readBoolean();
        ClickType clickType = shiftKeyDown ? ClickType.QUICK_MOVE : ClickType.PICKUP;
        SlotUtil.slotClickPhantom(slotReference, mouseButton, clickType, stackHeld);
    }
}
 
Example 4
Source File: MemorizedRecipeWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack slotClick(int dragType, ClickType clickTypeIn, EntityPlayer player) {
    if (!player.world.isRemote) {
        MemorizedRecipe recipe = recipeMemory.getRecipeAtIndex(recipeIndex);
        if (recipe != null && !recipe.getRecipeResult().isEmpty()) {
            if (clickTypeIn == ClickType.PICKUP) {
                recipeMemory.loadRecipe(recipeIndex, craftingGrid);
                player.openContainer.detectAndSendChanges();
            } else if (clickTypeIn == ClickType.QUICK_MOVE) {
                recipe.setRecipeLocked(!recipe.isRecipeLocked());
            }
        }
    }
    return ItemStack.EMPTY;
}
 
Example 5
Source File: GuiContainer.java    From NotEnoughItems with MIT License 4 votes vote down vote up
/**
 * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
 */
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {

    if (manager.mouseClicked(mouseX, mouseY, mouseButton)) {
        return;
    }

    super.mouseClicked(mouseX, mouseY, mouseButton);
    boolean flag = this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100);
    Slot slot = this.getSlotAtPosition(mouseX, mouseY);
    long i = Minecraft.getSystemTime();
    this.doubleClick = this.lastClickSlot == slot && i - this.lastClickTime < 250L && this.lastClickButton == mouseButton;
    this.ignoreMouseUp = false;

    if (mouseButton == 0 || mouseButton == 1 || flag) {
        int j = this.guiLeft;
        int k = this.guiTop;
        boolean flag1 = mouseX < j || mouseY < k || mouseX >= j + this.xSize || mouseY >= k + this.ySize;
        if (slot != null) {
            flag1 = false; // Forge, prevent dropping of items through slots outside of GUI boundaries
        }
        int l = -1;

        if (slot != null) {
            l = slot.slotNumber;
        }

        if (flag1) {
            l = -999;
        }

        if (this.mc.gameSettings.touchscreen && flag1 && this.mc.thePlayer.inventory.getItemStack() == null) {
            this.mc.displayGuiScreen(null);
            return;
        }

        if (l != -1) {
            if (this.mc.gameSettings.touchscreen) {
                if (slot != null && slot.getHasStack()) {
                    this.clickedSlot = slot;
                    this.draggedStack = null;
                    this.isRightMouseClick = mouseButton == 1;
                } else {
                    this.clickedSlot = null;
                }
            } else if (!this.dragSplitting) {
                if (this.mc.thePlayer.inventory.getItemStack() == null) {
                    if (this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100)) {
                        managerHandleMouseClick(slot, l, mouseButton, ClickType.CLONE);
                    } else {
                        boolean flag2 = l != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54));
                        ClickType clicktype = ClickType.PICKUP;

                        if (flag2) {
                            this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
                            clicktype = ClickType.QUICK_MOVE;
                        } else if (l == -999) {
                            clicktype = ClickType.THROW;
                        }

                        managerHandleMouseClick(slot, l, mouseButton, clicktype);
                    }

                    this.ignoreMouseUp = true;
                } else {
                    this.dragSplitting = true;
                    this.dragSplittingButton = mouseButton;
                    this.dragSplittingSlots.clear();

                    if (mouseButton == 0) {
                        this.dragSplittingLimit = 0;
                    } else if (mouseButton == 1) {
                        this.dragSplittingLimit = 1;
                    } else if (this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100)) {
                        this.dragSplittingLimit = 2;
                    }
                }
            }
        }
    }

    this.lastClickSlot = slot;
    this.lastClickTime = i;
    this.lastClickButton = mouseButton;
}
 
Example 6
Source File: ContainerTFC.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
/**
 * Handles slot click.
 *  
 * @param mode 0 = basic click, 1 = shift click, 2 = hotbar, 3 = pick block, 4 = drop, 5 = ?, 6 = double click
 */
public ItemStack slotClick(int slotID, int dragType, ClickType clickTypeIn, EntityPlayer p)
{
	if (slotID >= 0 && slotID < this.inventorySlots.size())
	{
		Slot sourceSlot = (Slot) this.inventorySlots.get(slotID);
		ItemStack slotStack = sourceSlot.getStack();

		//This section is for merging foods with differing expirations.
		if(clickTypeIn == ClickType.SWAP && slotStack != null && p.inventory.getItemStack() != null)
		{
			ItemStack itemstack4 = p.inventory.getItemStack();
			if (slotStack.getItem() == itemstack4.getItem() && slotStack.getMetadata() == itemstack4.getMetadata() && ContainerTFC.areCompoundsEqual(slotStack, itemstack4))
			{
				if(slotStack.getItem() instanceof IFood && itemstack4.getItem() instanceof IFood)
				{
					long ex1 = Food.getDecayTimer(slotStack);
					long ex2 = Food.getDecayTimer(itemstack4);
					if(ex2 < ex1)
						Food.setDecayTimer(slotStack, ex2);
				}

				//int l1 = clickedButton == 0 ? itemstack4.getMaxStackSize() : 1;
				int l1 = itemstack4.getMaxStackSize();

				if (l1 > sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize())
				{
					l1 = sourceSlot.getItemStackLimit(itemstack4) - slotStack.getMaxStackSize();
				}

				if (l1 > itemstack4.getMaxStackSize() - slotStack.getMaxStackSize())
				{
					l1 = itemstack4.getMaxStackSize() - slotStack.getMaxStackSize();
				}

				itemstack4.splitStack(l1);

				if (itemstack4.getMaxStackSize() == 0)
				{
					p.inventory.setItemStack(ItemStack.EMPTY);
				}

				slotStack.grow(l1);
				return ItemStack.EMPTY;
			}
			else if (itemstack4.getMaxStackSize() <= sourceSlot.getItemStackLimit(itemstack4))
			{
				sourceSlot.putStack(itemstack4);
				p.inventory.setItemStack(slotStack);
			}
		}

		// Hotbar press to remove from crafting output
		if (clickTypeIn == ClickType.QUICK_MOVE && slotID == 0 && slotStack != null)
		{
			//Removed During Port
			//CraftingHandler.preCraft(p, slotStack, craftMatrix);
		}
		// S and D hotkeys for trimming/combining food
		/*else if (mode == 7 && slotID >= 9 && slotID < 45)
		{
			if (sourceSlot.canTakeStack(p))
			{
				Slot destSlot = (Slot) this.inventorySlots.get(clickedButton);
				destSlot.putStack(slotStack);
				sourceSlot.putStack(null);
				return null;
			}
		}*/
	}

	ItemStack is = super.slotClick(slotID, dragType, clickTypeIn, p);
	//saveContents(is);
	return is;
}