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


Java ItemHandlerHelper.copyStackWithSize方法代碼示例

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


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

示例1: extractItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (storage.getStackInSlot(slot).isEmpty() || amount == 0) return ItemStack.EMPTY;
    ItemStack existing = blackHoleUnitBlock.getItemStack(storage.getStackInSlot(slot)).copy();
    if (existing.isEmpty()) return ItemStack.EMPTY;
    int visualAmount = blackHoleUnitBlock.getAmount(storage.getStackInSlot(slot)) + output.getStackInSlot(slot).getCount();
    if (visualAmount <= amount) {
        if (!simulate) {
            blackHoleUnitBlock.setAmount(storage.getStackInSlot(slot), 0);
            output.setStackInSlot(slot, ItemStack.EMPTY);
        }
        return ItemHandlerHelper.copyStackWithSize(existing, visualAmount);
    } else {
        if (!simulate) {
            blackHoleUnitBlock.setAmount(storage.getStackInSlot(slot), Math.max(0, blackHoleUnitBlock.getAmount(storage.getStackInSlot(slot)) - amount));
            output.setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(existing, Math.min(64, visualAmount - amount)));
        }
        return ItemHandlerHelper.copyStackWithSize(existing, amount);
    }
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:22,代碼來源:BlackHoleControllerTile.java

示例2: extractItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (amount == 0) return ItemStack.EMPTY;
    ItemStack existing = tile.getItemStack().copy();
    if (existing.isEmpty()) return ItemStack.EMPTY;
    if (tile.getAmount() <= amount) {
        int newAmount = tile.getAmount();
        if (!simulate) {
            tile.setAmount(0);
            outItems.setStackInSlot(0, ItemStack.EMPTY);
        }
        return ItemHandlerHelper.copyStackWithSize(existing, newAmount);
    } else {
        if (!simulate) {
            tile.setAmount(tile.amount - amount);
        }
        return ItemHandlerHelper.copyStackWithSize(existing, amount);
    }
}
 
開發者ID:Buuz135,項目名稱:Industrial-Foregoing,代碼行數:21,代碼來源:BlackHoleUnitTile.java

示例3: 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

示例4: extractItem

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

示例5: extractItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
    if (slot == rows * columns)
    {
        ItemStack result = getCraftResult();
        if (result.isEmpty() || amount < result.getCount())
            return ItemStack.EMPTY;

        amount = result.getCount();

        if (!simulate)
        {
            removeItems();

            setStackInSlot(rows * columns, ItemStack.EMPTY);
            return ItemHandlerHelper.copyStackWithSize(result, amount);
        }
    }

    return super.extractItem(slot, amount, simulate);
}
 
開發者ID:cubex2,項目名稱:customstuff4,代碼行數:24,代碼來源:ItemHandlerCrafting.java

示例6: insertItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack insertItem(EStorageNetwork network, ItemStack stack, int amount, boolean sim) {
	ItemStack remaining = ItemHandlerHelper.copyStackWithSize(stack, amount);
	for(int i = 0; i < array.getSizeInventory(); i++){
		ItemStack hdd = array.getStackInSlot(i);
		if(ItemStackTools.isValid(hdd) && hdd.getItem() instanceof IItemProvider){
			IItemProvider provider = (IItemProvider)hdd.getItem();
			final int preSize = ItemStackTools.getStackSize(remaining);
			remaining = provider.insert(hdd, remaining, ItemStackTools.getStackSize(remaining), sim);
			if(!sim && (ItemStackTools.getStackSize(remaining) !=preSize)){
				array.markDirty();
				BlockUtil.markBlockForUpdate(array.getWorld(), array.getPos());
			}
			
			if (!ItemStackTools.isValid(remaining)) {
                break;
			}
		}
	}
	return remaining;
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:22,代碼來源:NetworkInventoryHDDArray.java

示例7: extract

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Override
public ItemStack extract(ItemStack container, ItemStack remove, int amount, ExtractFilter filter, boolean sim) {
	ItemStack received = ItemStackTools.getEmptyStack();
	if (ItemStackTools.isValid(container)) {
		int index = getIndex(container, remove, filter);
		if (index > -1) {
			ItemStack stored = getItem(container, index);
			if(ItemStackTools.isValid(stored)){
				int realCount = Math.min(amount, ItemStackTools.getStackSize(stored));
				if(ItemStackTools.isNullStack(received)){
					received = ItemHandlerHelper.copyStackWithSize(stored, realCount);
				}
				if(!sim){
					ItemStackTools.incStackSize(stored, -realCount);
					if (ItemStackTools.isEmpty(stored)) {
						stored = ItemStackTools.getEmptyStack();
					}
					setItem(container, index,	stored);
				}
			}
		}
	}
	return received;
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:25,代碼來源:ItemHDD.java

示例8: doExtract

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
private ItemStack doExtract(int slot, int amount, boolean simulate) {
	if (amount == 0) {
		return ItemStack.EMPTY;
	}

	validateSlotIndex(slot);

	ItemStack existing = stacks.get(slot);

	if (existing.isEmpty()) {
		return ItemStack.EMPTY;
	}

	int toExtract = Math.min(amount, existing.getMaxStackSize());

	if (existing.getCount() <= toExtract) {
		if (!simulate) {
			stacks.set(slot, ItemStack.EMPTY);
			onContentsChanged(slot);
		}
		return existing;
	}
	else {
		if (!simulate) {
			stacks.set(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
			onContentsChanged(slot);
		}

		return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
	}
}
 
開發者ID:p455w0rd,項目名稱:DankNull,代碼行數:32,代碼來源:DankNullItemHandler.java

示例9: extractItem

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

    validateSlotIndex(slot);

    ItemStack existing = getStackInSlot(slot);

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

    int toExtract = Math.min(amount, existing.getMaxStackSize());

    if (existing.getCount() <= toExtract)
    {
        if (!simulate)
        {
            setStackInSlot(slot, ItemStack.EMPTY);
        }
        return existing;
    }
    else
    {
        if (!simulate)
        {
            setStackInSlot(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
        }
        return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
    }
}
 
開發者ID:gigaherz,項目名稱:ToolBelt,代碼行數:33,代碼來源:ToolBeltInventory.java

示例10: insertItem

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

    boolean reachedLimit = stack.getCount() > limit;

    if (!simulate)
    {
        this.stacks.add(reachedLimit ? ItemHandlerHelper.copyStackWithSize(stack, limit) : stack);
        onContentsChanged(stacks.size()-1);
    }

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

示例11: extractItem

import net.minecraftforge.items.ItemHandlerHelper; //導入方法依賴的package包/類
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    if (amount == 0 || stacks.size() == 0)
        return ItemStack.EMPTY;

    ItemStack existing = stacks.get(0);

    if (existing.isEmpty())
        return ItemStack.EMPTY;

    int toExtract = Math.min(amount, existing.getMaxStackSize());

    if (existing.getCount() <= toExtract)
    {
        if (!simulate)
        {
            this.stacks.remove(0);
            onContentsChanged(0);
        }
        return existing;
    }
    else
    {
        if (!simulate)
        {
            this.stacks.set(0, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract));
            onContentsChanged(0);
        }

        return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
    }
}
 
開發者ID:DaedalusGame,項目名稱:BetterWithAddons,代碼行數:34,代碼來源:QueueItemStackHandler.java

示例12: 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

示例13: extractItem

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

       validateSlotIndex(slot);

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

       if (ItemStackTools.isNullStack(existing))
           return ItemStackTools.getEmptyStack();

       int toExtract = Math.min(amount, existing.getMaxStackSize());

       if (ItemStackTools.getStackSize(existing) <= toExtract)
       {
           if (!simulate)
           {
               this.items.set(slot, ItemStackTools.getEmptyStack());
               onContentsChanged(slot);
           }
           return existing;
       }
       else
       {
           if (!simulate)
           {
               this.items.set(slot, ItemHandlerHelper.copyStackWithSize(existing, ItemStackTools.getStackSize(existing) - toExtract));
               onContentsChanged(slot);
           }

           return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
       }
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:35,代碼來源:WrapperInventory.java

示例14: 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

示例15: extractItem

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

       ItemStack existing = crate.getStack();
       
       if (ItemStackTools.isEmpty(existing) || ItemStackTools.getStackSize(existing) == 1 && Config.crates_leaveOneItem)
           return ItemStackTools.getEmptyStack();

       int toExtract = Math.min(amount, existing.getMaxStackSize());

       int offset = Config.crates_leaveOneItem ? 1 : 0;
       
       if (ItemStackTools.getStackSize(existing) <= toExtract-offset)
       {
           if (!simulate)
           {
               crate.setStack(ItemStackTools.getEmptyStack());
           }
           return existing;
       }
       else
       {
           if (!simulate)
           {
           	crate.setStack(ItemHandlerHelper.copyStackWithSize(existing, ItemStackTools.getStackSize(existing) - toExtract));
           }

           return ItemHandlerHelper.copyStackWithSize(existing, toExtract);
       }
   }
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:34,代碼來源:ItemHandlerCrate.java


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