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


Java ItemHandlerHelper.canItemStacksStack方法代碼示例

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


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

示例1: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
	if(stack.isEmpty()) return ItemStack.EMPTY;
	if(!getKey().isPresent() || isEntangled(stack)) return stack;
	ItemStack existing = getStackInSlot(slot);
	int limit = stack.getMaxStackSize();
	if(!existing.isEmpty()) {
		if(!ItemHandlerHelper.canItemStacksStack(stack, existing)) {
			return stack;
		}
		limit -= existing.getCount();
	}
	if(limit <= 0) return stack;
	boolean reachedLimit = stack.getCount() > limit;
	if(!simulate) {
		if(existing.isEmpty()) {
			setStackInSlot(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
		} else {
			existing.grow(reachedLimit ? limit : stack.getCount());
			setStackInSlot(slot, existing);
		}
		onChange(slot);
	}
	return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:26,代碼來源:QuantumDataHandler.java

示例2: dropItems

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private void dropItems() {
	if(world.getTotalWorldTime() % 10 != 0) return;
	applyGravity(repulse, false);
	IItemHandler handler = from.getKey();
	ISidedInventory sidedInv = from.getValue();
	Vector3 spawn = Vector3.create(getPos()).add(0.5D).offset(getFacingLazy(), 1);
	for(int slot = 0; slot < handler.getSlots(); slot++) {
		ItemStack inSlot = handler.getStackInSlot(slot);
		if(!inSlot.isEmpty()
				&& (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot))
				&& (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
			ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
			EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x, spawn.y, spawn.z, out);
			impulseEntityItem(spawn, entity);
			world.spawnEntity(entity);
			break;
		}
	}
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:20,代碼來源:TileVacuumConveyor.java

示例3: transferIn

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private boolean transferIn(BlockPos pos, ItemStack inserted, boolean test) {
	EnumFacing facing = getFacing();
	Pair<IItemHandler, ISidedInventory> inv = getInventory(pos, facing);
	if(inv.getKey() != null) {
		IItemHandler handler = inv.getKey();
		ISidedInventory tile = inv.getValue();

		for(int slot = 0; slot < handler.getSlots(); slot++) {
			ItemStack inSlot = handler.getStackInSlot(slot);
			if(tile != null && !tile.canInsertItem(slot, inserted, facing)) return false;
			if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, inserted) && (inSlot.getCount() < inSlot.getMaxStackSize() && inSlot.getCount() < handler.getSlotLimit(slot)))) {
				return handler.insertItem(slot, inserted, test) != inserted;
			}
		}
	}
	return false;
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:18,代碼來源:TileGravityHopper.java

示例4: getItemStackLimit

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public int getItemStackLimit(ItemStack stack) 
{
	ItemStack currentStack = getStack();
	int maxAdd = stack.getMaxStackSize();
	if(currentStack == null ) return 64;
	if(!ItemHandlerHelper.canItemStacksStack(stack, currentStack))  return 64;
	int stackSize = currentStack.getCount() + stack.getCount();
	if(stackSize > maxAdd) stackSize = maxAdd;
	return stackSize;
}
 
開發者ID:einsteinsci,項目名稱:BetterBeginningsReborn,代碼行數:12,代碼來源:SlotConfigurableAccess.java

示例5: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
	if (!ItemStackTools.isValid(stack))
           return ItemStackTools.getEmptyStack();

       validateSlotIndex(slot);

       ItemStack existing = this.items.get(slot);

       int limit = getStackLimit(slot, stack);

       if (!ItemStackTools.isNullStack(existing))
       {
           if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
               return stack;

           limit -= ItemStackTools.getStackSize(existing);
       }

       if (limit <= 0)
           return stack;

       boolean reachedLimit = ItemStackTools.getStackSize(stack) > limit;

       if (!simulate)
       {
           if (ItemStackTools.isNullStack(existing))
           {
               this.items.set(slot, reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
           }
           else
           {
           	ItemStackTools.incStackSize(existing, reachedLimit ? limit : ItemStackTools.getStackSize(stack));
           }
           onContentsChanged(slot);
       }

       return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, ItemStackTools.getStackSize(stack) - limit) : null;
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:40,代碼來源:WrapperInventory.java

示例6: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
    if (ItemStackTools.isEmpty(stack))
        return ItemStackTools.getEmptyStack();

    ItemStack existing = crate.getStack();

    int limit = getStackLimit(slot, stack);

    if (ItemStackTools.isValid(existing))
    {
        if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
            return stack;

        limit -= ItemStackTools.getStackSize(existing);
    }

    if (limit <= 0)
        return stack;

    boolean reachedLimit = ItemStackTools.getStackSize(stack) > limit;

    if (!simulate)
    {
        if (ItemStackTools.isEmpty(existing))
        {
            crate.setStack(reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
        }
        else
        {
        	ItemStackTools.incStackSize(existing, reachedLimit ? limit : ItemStackTools.getStackSize(stack));
        	crate.setStack(existing);
        }
    }

    return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, ItemStackTools.getStackSize(stack) - limit) : ItemStackTools.getEmptyStack();
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:39,代碼來源:ItemHandlerCrate.java

示例7: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
	if (stack.isEmpty()) return ItemStack.EMPTY;

	validateSlotIndex(slot);

	if (!canInsert(slot, stack)) return stack;

	ItemStack existing = slots[slot];
	int limit = getStackLimit(slot, stack);

	if (!existing.isEmpty())
	{
		if (!ItemHandlerHelper.canItemStacksStack(stack, existing)) return stack;
		limit -= existing.getCount();
	}

	if (limit <= 0) return stack;

	boolean reachedLimit = stack.getCount() > limit;

	if (!simulate)
	{
		if (existing.isEmpty())
			slots[slot] = reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack;
		else existing.grow(reachedLimit ? limit : stack.getCount());
		onSlotChanged();
	}
	
	return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
 
開發者ID:murapix,項目名稱:Inhuman-Resources,代碼行數:33,代碼來源:FilteredItemHandler.java

示例8: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack is, boolean sim) {
	if (is.isEmpty())
		return ItemStack.EMPTY;
	checkSlot(slot);
	if ((slot == 0 && TileEntityFurnace.getItemBurnTime(is) == 0) || (slot == 1 && !FluxGenRecipes.isCatalyst(is)))
		return is;
	int l = is.getMaxStackSize();
	if (l > 64) l = 64;
	int sc = is.getCount();
	ItemStack xis = items[slot];
	if (!xis.isEmpty()) {
		if (!ItemHandlerHelper.canItemStacksStack(is, xis))
			return is;
		l -= xis.getCount();
	}
	if (0 >= l)
		return is;
	boolean rl = sc > l;
	if (!sim) {
		if (xis.isEmpty())
			items[slot] = rl ? ItemHandlerHelper.copyStackWithSize(is, l) : is;
		else
			xis.grow(rl ? l : sc);
		isDirty = true;
	}
	return rl ? ItemHandlerHelper.copyStackWithSize(is, sc - l) : ItemStack.EMPTY;
}
 
開發者ID:Szewek,項目名稱:Minecraft-Flux,代碼行數:28,代碼來源:TileEntityFluxGen.java

示例9: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int index, ItemStack stack, boolean simulate)
{
    if (index >= inventorySlots.size())
    {
        if (!simulate)
        {
            inventorySlots.add(stack.copy());
            onContentsChanged();
        }
        return ItemStack.EMPTY;
    }

    ItemStack remaining = stack.copy();
    ItemStack slot = inventorySlots.get(index);
    if (slot.getCount() > 0)
    {
        int max = Math.min(remaining.getMaxStackSize(), 64);
        int transfer = Math.min(remaining.getCount(), max - slot.getCount());
        if (transfer > 0 && ItemHandlerHelper.canItemStacksStack(remaining, slot))
        {
            if (!simulate) slot.grow(transfer);
            remaining.shrink(transfer);
            if (remaining.getCount() <= 0)
                remaining = ItemStack.EMPTY;
        }
    }

    if (!simulate) onContentsChanged();

    return remaining;
}
 
開發者ID:gigaherz,項目名稱:Ender-Rift,代碼行數:33,代碼來源:RiftInventory.java

示例10: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
    if (!Config.isItemStackAllowed(stack))
        return stack;

    if (stack.getCount() <= 0)
        return ItemStack.EMPTY;

    validateSlotIndex(slot);

    ItemStack existing = getStackInSlot(slot);

    int limit = stack.getMaxStackSize();

    if (existing.getCount() > 0)
    {
        if (!ItemHandlerHelper.canItemStacksStack(stack, existing))
            return stack;

        limit -= existing.getCount();
    }

    if (limit <= 0)
        return stack;

    boolean reachedLimit = stack.getCount() > limit;

    if (!simulate)
    {
        if (existing.getCount() <= 0)
        {
            existing = reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack;
        }
        else
        {
            existing.grow(reachedLimit ? limit : stack.getCount());
        }
        setStackInSlot(slot, existing);
    }

    return reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, stack.getCount() - limit) : ItemStack.EMPTY;
}
 
開發者ID:gigaherz,項目名稱:ToolBelt,代碼行數:44,代碼來源:ToolBeltInventory.java

示例11: tryAbsorbDroppedItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private boolean tryAbsorbDroppedItem(EntityItem item, IBlockState state)
   {
ItemStack newStack = Prep1_11.getEmptyStack();
ItemStack stack = item.getItem();
switch(mode)
{
case DIFFUSION:
    if(isIngredientPresent(stack)) return false;
    if(stack.getItem() == Items.BOOK || stack.isItemEnchanted())
    {
	newStack = stack.copy();
	newStack.setCount(1);
	if(!world.isRemote) stack.shrink(1);
    }
    break;
case REPAIR:
    if(pendingIngredients.isEmpty()) return false;
    RecipeElement currentIngredient = pendingIngredients.peek();
    if(currentIngredient.matches(stack))
    {
	newStack = stack.copy();
	newStack.setCount(Math.min(currentIngredient.getStackSize(), stack.getCount()));
	currentIngredient.setStackSize(currentIngredient.getStackSize() - Math.min(currentIngredient.getStackSize(), stack.getCount()));

	if(currentIngredient.getStackSize() <= 0)
	{
	    pendingIngredients.pop();
	}
	if(!world.isRemote) stack.shrink(newStack.getCount());
	markDirty();
    }
    break;
default:
    break;
}	
if(newStack == null) return false;
boolean slotFound = false;
if(newStack.isItemEnchanted())
{
    mainHandler.setStackInSlot(SLOT_ENCH_ITEM, newStack);
    slotFound = true;
}
else
{
    //attempt to insert stacks into inv
    for(int s = SLOT_ENCH_ITEM + 1; s < mainHandler.getSlots(); s++)
    {
	ItemStack slotStack = mainHandler.getStackInSlot(s);
	if (ItemHandlerHelper.canItemStacksStack(newStack, slotStack))
	{
	    CapUtils.incrementStack(mainHandler, s, newStack.getCount());
	    slotFound = true;
	    break;
	}
	if(Prep1_11.isEmpty(slotStack))
	{
	    mainHandler.setStackInSlot(s, newStack);
	    slotFound = true;
	    break;
	}
    }
}
return slotFound;
   }
 
開發者ID:einsteinsci,項目名稱:BetterBeginningsReborn,代碼行數:65,代碼來源:TileEntityInfusionRepair.java

示例12: exportItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
/**
 * Attempt to export the given stack (usually a custom recipe result) to the given slots.
 * @return Leftover items that weren't added to the slots, or null if all found a home.
 */
public ItemStack exportItem(ItemStack export, int[] slots, boolean simulate)
{
    int simulatedExportStackSize = export.getCount();
    for(int i : slots)
    {
        ItemStack stackInSlot = getStackInSlot(i);
        if(stackInSlot.isEmpty())
        {
            if(!simulate)
                setInventorySlotContents(i, export);
            return ItemStack.EMPTY;
        }
        else if(ItemHandlerHelper.canItemStacksStack(stackInSlot, export))
        {
            int maxStack = Math.min(this.getInventoryStackLimit(), stackInSlot.getMaxStackSize());
            int amountToMove = Math.min(maxStack - stackInSlot.getCount(), export.getCount());
            if(!simulate)
            {
                stackInSlot.grow(amountToMove);
                export.shrink(amountToMove);
                if(export.getCount() <= 0)
                    return ItemStack.EMPTY;
            }
            else
            {
                simulatedExportStackSize -= amountToMove;
                if(simulatedExportStackSize <= 0)
                    return ItemStack.EMPTY;
            }
        }
    }

    if(simulate)
    {
        ItemStack ret = export.copy();
        ret.setCount(simulatedExportStackSize);
        return ret;
    }
    else
    {
        markDirty();
    }
    return export;
}
 
開發者ID:Lumaceon,項目名稱:ClockworkPhase2,代碼行數:49,代碼來源:TileClockworkMachine.java


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