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


Java IInventory.getStackInSlot方法代碼示例

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


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

示例1: findStack

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
@Nullable
public BeltGetter findStack(EntityPlayer player)
{
    IInventory playerInv = player.inventory;
    for (int i = 0; i < playerInv.getSizeInventory(); i++)
    {
        ItemStack inSlot = playerInv.getStackInSlot(i);
        if (inSlot.getCount() > 0)
        {
            if (inSlot.getItem() instanceof ItemToolBelt)
            {
                return new InventoryBeltGetter(player, i);
            }
        }
    }

    return null;
}
 
開發者ID:gigaherz,項目名稱:ToolBelt,代碼行數:19,代碼來源:BeltFinder.java

示例2: getStackWithInventory

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
public static ItemStack getStackWithInventory(IInventory inventory, IBlockState state) {
	if (inventory != null && inventory.getSizeInventory() > 0 && state != null) {
		ItemStack stack = new ItemStack(Item.getItemFromBlock(state.getBlock()));
		NBTTagCompound stackNBT = new NBTTagCompound();//stack.getSubCompound("BlockEntityTag", true);
		NBTTagList stackList = new NBTTagList();
		for (int i = 0; i < inventory.getSizeInventory(); i++) {
			if (inventory.getStackInSlot(i) == null) {
				continue;
			}
			NBTTagCompound slotNBT = new NBTTagCompound();
			slotNBT.setByte("Slot", (byte) i);
			inventory.getStackInSlot(i).writeToNBT(slotNBT);
			stackList.appendTag(slotNBT);
		}
		stackNBT.setTag("Items", stackList);
		stack.setTagInfo("BlockEntityTag", stackNBT);
		return stack;
	}
	return null;
}
 
開發者ID:p455w0rd,項目名稱:EndermanEvolution,代碼行數:21,代碼來源:ChestUtils.java

示例3: arrowNock

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
@SubscribeEvent
public void arrowNock(ArrowNockEvent event) {
	if (event.result == null)
		return;
	IInventory invt = event.entityPlayer.inventory;
	for (int i = 0; i < invt.getSizeInventory(); i++) {
		ItemStack stack = invt.getStackInSlot(i);
		if (stack == null || stack.stackSize <= 0)
			continue;
		if (stack.getItem() == Items.arrow)
			return;
		if (stack.getItem() == ModItems.tipped_arrow) {
			event.setCanceled(true);
			event.entityPlayer.setItemInUse(event.result, event.result.getItem().getMaxItemUseDuration(event.result));
			return;
		}
	}
}
 
開發者ID:jm-organization,項目名稱:connor41-etfuturum2,代碼行數:19,代碼來源:ServerEventHandler.java

示例4: pullItemFromSlot

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
/**
 * Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
 * the entire stack was moved
 */
private static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, EnumFacing direction)
{
    ItemStack itemstack = inventoryIn.getStackInSlot(index);

    if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
    {
        ItemStack itemstack1 = itemstack.copy();
        ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (EnumFacing)null);

        if (itemstack2 == null || itemstack2.stackSize == 0)
        {
            inventoryIn.markDirty();
            return true;
        }

        inventoryIn.setInventorySlotContents(index, itemstack1);
    }

    return false;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:25,代碼來源:TileEntityHopper.java

示例5: pushItemIInventory

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
protected boolean pushItemIInventory(IInventory inventory, int slot) {
	if(blockItemStack.stackSize > 1) {
		ItemStack oldStack = blockItemStack.copy();
		ItemStack newStack = blockItemStack.splitStack(1);
		
		if(inventory.getStackInSlot(slot) == null) {
			if(debug)
				FMLLog.log(Level.INFO, "fF");
			inventory.setInventorySlotContents(slot, newStack.copy());
			newStack = null;
			markDirty = true;
		} else if(inventory.getStackInSlot(slot).getItem() == newStack.getItem() && inventory.getStackInSlot(slot).stackSize < inventory.getInventoryStackLimit() && inventory.getStackInSlot(slot).stackSize < inventory.getStackInSlot(slot).getMaxStackSize()) {
			if(debug)
				FMLLog.log(Level.INFO, "fG");
			newStack.stackSize += inventory.getStackInSlot(slot).stackSize;
			inventory.setInventorySlotContents(slot, newStack.copy());
			newStack = null;
			markDirty = true;
		} else {
			if(debug)
				FMLLog.log(Level.INFO, "fGa");
		}
		
		if(newStack == null || newStack.stackSize == 0) {
			if(debug)
				FMLLog.log(Level.INFO, "fDa");
			markDirty = true;
		} else {
			blockItemStack = oldStack;
		}
	}
	return markDirty;
}
 
開發者ID:viddeno,項目名稱:Technical,代碼行數:34,代碼來源:TileEntityGrabberFiltering.java

示例6: getItemStack

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
private static ItemStack getItemStack(IInventory inventory, Item item)
{
	for (int index = 0; index < inventory.getSizeInventory(); index++)
	{
		if(inventory.getStackInSlot(index) == null)
			continue;
		
		if(inventory.getStackInSlot(index).getItem() == item)
			return inventory.getStackInSlot(index);
	}
	
	return null;
}
 
開發者ID:Wahazar,項目名稱:TFCPrimitiveTech,代碼行數:14,代碼來源:CraftingHandler.java

示例7: isSimilar

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
private boolean isSimilar(IInventory handler, ItemStack stack) {
    Set<Integer> ores = getOres(stack);
    for (int i = 0 ; i < handler.getSizeInventory() ; i++) {
        ItemStack s = handler.getStackInSlot(i);
        if (matchStack(stack, ores, s)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:McJty,項目名稱:interactionwheel,代碼行數:11,代碼來源:DumpSimilarInventoryAction.java

示例8: getFirstItem

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
public static ItemStack getFirstItem(IInventory inventory, Predicate<ItemStack> pred) {
	
		for (int i = 0; i<inventory.getSizeInventory(); i++) {
			ItemStack stack=inventory.getStackInSlot(i);
			if (!stack.isEmpty() && pred.apply(stack))
				return stack;
		}
		return ItemStack.EMPTY;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:10,代碼來源:TF2Util.java

示例9: isInventoryFull

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
/**
 * Returns false if the inventory has any room to place items in
 */
private boolean isInventoryFull(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int k = 0; k < aint.length; ++k)
        {
            ItemStack itemstack1 = isidedinventory.getStackInSlot(aint[k]);

            if (itemstack1 == null || itemstack1.stackSize != itemstack1.getMaxStackSize())
            {
                return false;
            }
        }
    }
    else
    {
        int i = inventoryIn.getSizeInventory();

        for (int j = 0; j < i; ++j)
        {
            ItemStack itemstack = inventoryIn.getStackInSlot(j);

            if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
            {
                return false;
            }
        }
    }

    return true;
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:38,代碼來源:TileEntityHopper.java

示例10: copyProps

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
public static void copyProps(IInventory craftMatrix, ItemStack newItem)
{
	// Step 1, find the actual item (It's possible that this is not a reloading action, meaning there is no weapon to copy the name from)
	
	int slot = 0;
	
	while (slot < 9)
	{
		ItemStack stack = craftMatrix.getStackInSlot(slot);
		
		if (stack != null && stack.getItem() instanceof _WeaponBase)	// Found it. Does it have a name tag?
		{
			if (stack.hasDisplayName() && !newItem.hasDisplayName()) { newItem.setStackDisplayName(stack.getDisplayName()); }
			// else, has no custom display name or the new item already has one. Fine with me either way.
			
			// Upgrades
			if (stack.hasTagCompound() && stack.getTagCompound().getBoolean("hasEmeraldMuzzle"))
			{
				if (!newItem.hasTagCompound()) { newItem.setTagCompound(new NBTTagCompound()); }	// Init
				newItem.getTagCompound().setBoolean("hasEmeraldMuzzle", true);						// Keeping the upgrade
			}
			
			return;	// Either way, we're done here
		}
		// else, either doesn't exist or not what I'm looking for
		
		slot += 1;
	}
}
 
開發者ID:Domochevsky,項目名稱:minecraft-quiverbow,代碼行數:30,代碼來源:Helper.java

示例11: isInventoryEmpty

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
/**
 * Returns false if the specified IInventory contains any items
 */
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i : aint)
        {
            if (isidedinventory.getStackInSlot(i) != null)
            {
                return false;
            }
        }
    }
    else
    {
        int j = inventoryIn.getSizeInventory();

        for (int k = 0; k < j; ++k)
        {
            if (inventoryIn.getStackInSlot(k) != null)
            {
                return false;
            }
        }
    }

    return true;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:34,代碼來源:TileEntityHopper.java

示例12: pushItemIInventory

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
protected boolean pushItemIInventory(IInventory inventory, int slot) {
	if(inventory.getStackInSlot(slot) == null) {
		if(debug)
			FMLLog.log(Level.INFO, "gF");
		inventory.setInventorySlotContents(slot, blockItemStack.copy());
		blockItemStack = null;
		markDirty = true;
	} else {
		if(debug)
			FMLLog.log(Level.INFO, "gGa");
	}
	return markDirty;
}
 
開發者ID:viddeno,項目名稱:Technical,代碼行數:14,代碼來源:TileEntityGrabberGreedy.java

示例13: isInventoryEmpty

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
/**
 * Returns false if the specified IInventory contains any items
 */
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i = 0; i < aint.length; ++i)
        {
            if (isidedinventory.getStackInSlot(aint[i]) != null)
            {
                return false;
            }
        }
    }
    else
    {
        int j = inventoryIn.getSizeInventory();

        for (int k = 0; k < j; ++k)
        {
            if (inventoryIn.getStackInSlot(k) != null)
            {
                return false;
            }
        }
    }

    return true;
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:34,代碼來源:TileEntityHopper.java

示例14: extract

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
public static Pair<ItemStack, Integer> extract(TileEntity tile, EnumFacing from, int[] col, IInventory inv, boolean fullStack) {

		if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from)) {
			IItemHandlerModifiable handler = (IItemHandlerModifiable) tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, from);
			if (handler != null) {
				int invSize = handler.getSlots();

				for (int i = 0; i < invSize; i++) {
					ItemStack current = handler.getStackInSlot(i);

					for (int j = 0; j < inv.getSizeInventory(); j++) {
						ItemStack stack = inv.getStackInSlot(j);
						int color = -1;
						if (stack != null && stack != ItemStack.EMPTY && stack.getItem() != Items.AIR) {
							if (areItemStacksEqual(stack, current)) {
								int column = j >= 0 && j <= 3 ? 0 : j >= 4 && j <= 7 ? 1 : j >= 8 && j <= 11 ? 2 : j >= 12 && j <= 15 ? 3 : j >= 16 || j <= 19 ? 4 : -1;

								if (column == -1)
									return null;

								color = col[column];

								if (current != null && !current.isEmpty() && current.getItem() != Items.AIR) {
									ItemStack extracted = handler.extractItem(i, !fullStack ? 1 : current.getCount(), false);
									return Pair.of(extracted, color);
								}
							}
						}
					}

				}
			}
		} // TODO: TileEntities that don't have capabilities - needs testing

		return Pair.of(ItemStack.EMPTY, -1);
	}
 
開發者ID:oMilkyy,項目名稱:SimpleTubes,代碼行數:37,代碼來源:TubeUtil.java

示例15: insertStack

import net.minecraft.inventory.IInventory; //導入方法依賴的package包/類
/**
 * Insert the specified stack to the specified inventory and return any leftover items
 */
private static ItemStack insertStack(IInventory inventoryIn, ItemStack stack, int index, EnumFacing side)
{
    ItemStack itemstack = inventoryIn.getStackInSlot(index);

    if (canInsertItemInSlot(inventoryIn, stack, index, side))
    {
        boolean flag = false;

        if (itemstack == null)
        {
            inventoryIn.setInventorySlotContents(index, stack);
            stack = null;
            flag = true;
        }
        else if (canCombine(itemstack, stack))
        {
            int i = stack.getMaxStackSize() - itemstack.stackSize;
            int j = Math.min(stack.stackSize, i);
            stack.stackSize -= j;
            itemstack.stackSize += j;
            flag = j > 0;
        }

        if (flag)
        {
            if (inventoryIn instanceof TileEntityHopper)
            {
                TileEntityHopper tileentityhopper = (TileEntityHopper)inventoryIn;

                if (tileentityhopper.mayTransfer())
                {
                    tileentityhopper.setTransferCooldown(8);
                }

                inventoryIn.markDirty();
            }

            inventoryIn.markDirty();
        }
    }

    return stack;
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:47,代碼來源:TileEntityHopper.java


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