當前位置: 首頁>>代碼示例>>Java>>正文


Java ClickType.SWAP屬性代碼示例

本文整理匯總了Java中net.minecraft.inventory.ClickType.SWAP屬性的典型用法代碼示例。如果您正苦於以下問題:Java ClickType.SWAP屬性的具體用法?Java ClickType.SWAP怎麽用?Java ClickType.SWAP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在net.minecraft.inventory.ClickType的用法示例。


在下文中一共展示了ClickType.SWAP屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: slotClick

@Override
public ItemStack slotClick(int slotId, int clickedButton, ClickType mode, EntityPlayer playerIn)
{
    if (slotId >= 0 && slotId < 9)
    {
        if (mode == ClickType.PICKUP || mode == ClickType.PICKUP_ALL ||
                mode == ClickType.SWAP) // 1 is shift-click
        {
            Slot slot = this.inventorySlots.get(slotId);

            ItemStack dropping = playerIn.inventory.getItemStack();

            if (dropping.getCount() > 0)
            {
                ItemStack copy = dropping.copy();
                copy.setCount(1);
                slot.putStack(copy);
            }
            else if (slot.getStack().getCount() > 0)
            {
                slot.putStack(ItemStack.EMPTY);
            }

            return slot.getStack().copy();
        }

        return ItemStack.EMPTY;
    }

    return super.slotClick(slotId, clickedButton, mode, playerIn);
}
 
開發者ID:gigaherz,項目名稱:Ender-Rift,代碼行數:31,代碼來源:ContainerInterface.java

示例2: slotClick

@Override
@Nonnull
public ItemStack slotClick(int slotId, int dragType, ClickType clickType, EntityPlayer player) {
	if (slotId == protectedSlotNumber) return ItemStack.EMPTY;
	if (clickType == ClickType.SWAP && dragType == protectedSlotIndex) return ItemStack.EMPTY;
	return super.slotClick(slotId, dragType, clickType, player);
}
 
開發者ID:OpenMods,項目名稱:OpenBlocks,代碼行數:7,代碼來源:ContainerDevNull.java

示例3: slotClick

@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;
}
 
開發者ID:Deadrik,項目名稱:TFC2,代碼行數:80,代碼來源:ContainerTFC.java


注:本文中的net.minecraft.inventory.ClickType.SWAP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。