当前位置: 首页>>代码示例>>Java>>正文


Java IAEItemStack.setStackSize方法代码示例

本文整理汇总了Java中appeng.api.storage.data.IAEItemStack.setStackSize方法的典型用法代码示例。如果您正苦于以下问题:Java IAEItemStack.setStackSize方法的具体用法?Java IAEItemStack.setStackSize怎么用?Java IAEItemStack.setStackSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appeng.api.storage.data.IAEItemStack的用法示例。


在下文中一共展示了IAEItemStack.setStackSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractStack

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
/**
 * Extracts items from the network.
 *
 * @param target
 * @return Extracted stack.
 */
public ItemStack extractStack( final ItemStack target )
{
	// Get the item monitor
	IMEMonitor<IAEItemStack> monitor = this.getItemInventory();
	if( monitor == null )
	{
		return null;
	}

	// Create the AE stack
	IAEItemStack aeRequest = AEApi.instance().storage().createItemStack( target );

	// Set size
	aeRequest.setStackSize( Math.min( target.stackSize, this.maxItemRate ) );

	// Extract
	IAEItemStack extracted = AEApi.instance().storage().poweredExtraction( this.getEnergyGrid(), monitor, aeRequest, this.actionSource );
	if( extracted == null )
	{
		return null;
	}

	return extracted.getItemStack();
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:31,代码来源:AIAENetworkGolem.java

示例2: requestCrafting

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
@ScriptCallable(description = "Requests the specified item to get crafted.")
public void requestCrafting(IActionHost host,
		@Env(Constants.ARG_ACCESS) IArchitectureAccess access,
		@Env(Constants.ARG_CONVERTER) IConverter converter,
		@Arg(name = "fingerprint", description = "Details of the item you want to craft. Can be found with .getStackInSlot on inventory and .getAvailableItems on AE network") ItemFingerprint needle,
		@Optionals @Arg(name = "qty", description = "The quantity of items you want to craft") Long quantity,
		@Arg(name = "cpu", description = "The name of the CPU you want to use") String wantedCpuName) {
	ICraftingGrid craftingGrid = getCraftingGrid(host);
	if (quantity == null) quantity = 1L;

	ICraftingCPU wantedCpu = findCpu(craftingGrid, wantedCpuName);

	IStorageGrid storageGrid = getStorageGrid(host);
	IMEMonitor<IAEItemStack> monitor = storageGrid.getItemInventory();

	IAEItemStack stack = findCraftableStack(storageGrid.getItemInventory().getStorageList(), needle);
	Preconditions.checkArgument(stack != null, "Can't find craftable item fingerprint %s", needle);

	final IAEItemStack toCraft = stack.copy();
	toCraft.setStackSize(quantity);

	// Create a new CraftingCallback. This callback is called when
	// the network finished calculating the required items. It can do two things for us:
	// a) It sends an event when items are missing to complete the request
	// b) Otherwise it starts the crafting job, which itself is a CraftingRequester OSsending more events to the computer.
	final CraftingCallback craftingCallback = new CraftingCallback(access, converter, craftingGrid, monitor, host, wantedCpu, toCraft);

	// We will need access to the worldObj of the ME Interface -> cast to TileEntity
	final TileEntity tileEntity = (TileEntity)host;

	// Tell the craftingGrid to begin calculating and to report everything to the CraftingCallback
	craftingGrid.beginCraftingJob(tileEntity.getWorldObj(), getGrid(host), new MachineSource(host), toCraft, craftingCallback);

}
 
开发者ID:OpenMods,项目名称:OpenPeripheral-Integration,代码行数:35,代码来源:AdapterInterface.java

示例3: depositStack

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
/**
 * Attempts to deposit the itemstack into the AE system.
 * The {@code stack.stacksize} will change according to how many items were left over after the deposit.
 *
 * @param stack
 */
public void depositStack( final ItemStack stack )
{
	// Get the item monitor
	IMEMonitor<IAEItemStack> monitor = this.getItemInventory();
	if( monitor == null )
	{
		return;
	}

	// Create the AE stack
	IAEItemStack aeStack = AEApi.instance().storage().createItemStack( stack );

	// Set size
	int depositSize = Math.min( stack.stackSize, this.maxItemRate );
	aeStack.setStackSize( depositSize );

	// Deposit
	IAEItemStack rejected = AEApi.instance().storage().poweredInsert( this.getEnergyGrid(), monitor, aeStack, this.actionSource );
	if( rejected != null )
	{
		depositSize -= (int)rejected.getStackSize();
	}

	// Reduce stack by number of items deposited
	stack.stackSize -= depositSize;
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:33,代码来源:AIAENetworkGolem.java

示例4: postChange

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
/**
 * Called when the amount of an item on the network changes.
 */
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> changes, final BaseActionSource actionSource )
{
	if( this.monitor == null )
	{
		return;
	}

	for( IAEItemStack change : changes )
	{
		// Get the total amount of the item in the network
		IAEItemStack newAmount = this.monitor.getStorageList().findPrecise( change );

		// Is there no more?
		if( newAmount == null )
		{
			// Copy the item type from the change
			newAmount = change.copy();

			// Set amount to 0
			newAmount.setStackSize( 0 );
		}

		// Send the change to the client
		Packet_C_ArcaneCraftingTerminal.stackAmountChanged( this.player, newAmount );
	}
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:31,代码来源:ContainerPartArcaneCraftingTerminal.java

示例5: exportItem

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
@ScriptCallable(description = "Exports the specified item into the target inventory.", returnTypes = ReturnType.TABLE)
public IAEItemStack exportItem(Object tileEntityInterface,
		@Arg(name = "fingerprint", description = "Details of the item you want to export (can be result of .getStackInSlot() or .getAvailableItems())") ItemFingerprint needle,
		@Arg(name = "direction", description = "Location of target inventory") ForgeDirection direction,
		@Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to export") Integer maxAmount,
		@Arg(name = "intoSlot", description = "The slot in the other inventory that you want to export into") Index intoSlot) {

	final IActionHost host = (IActionHost)tileEntityInterface;
	final IInventory neighbor = getNeighborInventory(tileEntityInterface, direction);
	Preconditions.checkArgument(neighbor != null, "No neighbour attached");

	if (intoSlot == null) intoSlot = Index.fromJava(-1, 0);

	IStorageGrid storageGrid = getStorageGrid(host);
	IMEMonitor<IAEItemStack> monitor = storageGrid.getItemInventory();

	IAEItemStack stack = findStack(monitor.getStorageList(), needle);
	Preconditions.checkArgument(stack != null, "Can't find item fingerprint %s", needle);

	IAEItemStack toExtract = stack.copy();
	if (maxAmount == null || maxAmount < 1 || maxAmount > toExtract.getItemStack().getMaxStackSize()) {
		toExtract.setStackSize(toExtract.getItemStack().getMaxStackSize());
	} else {
		toExtract.setStackSize(maxAmount);
	}

	// Actually export the items from the ME system.
	MachineSource machineSource = new MachineSource(host);
	IAEItemStack extracted = monitor.extractItems(toExtract, Actionable.MODULATE, machineSource);
	if (extracted == null) return null;

	ItemStack toInsert = extracted.getItemStack().copy();

	// Put the item in the neighbor inventory
	if (ItemDistribution.insertItemIntoInventory(neighbor, toInsert, direction.getOpposite(), intoSlot.value)) {
		neighbor.markDirty();
	}

	// If we've moved some items, but others are still remaining.
	// Insert them back into the ME system.
	if (toInsert.stackSize > 0) {
		final IAEItemStack toReturn = AEApi.instance().storage().createItemStack(toInsert);
		monitor.injectItems(toReturn, Actionable.MODULATE, machineSource);
		extracted.decStackSize(toInsert.stackSize);
	}

	// Return what we've actually extracted
	return extracted;
}
 
开发者ID:OpenMods,项目名称:OpenPeripheral-Integration,代码行数:50,代码来源:AdapterInterface.java

示例6: sendSimulationInfo

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
private void sendSimulationInfo(ICraftingJob job) {
	// Grab the list of items from the job (this is basically the same
	// list the ME Terminal shows when crafting an item).
	IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
	job.populatePlan(plan);

	// This procedure to determine whether an item is missing is
	// basically the same as
	// the one used by AE2. Taken from here:
	// https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/rv2/src/main/java/appeng/container/implementations/ContainerCraftConfirm.java
	List<IAEItemStack> missingItems = Lists.newArrayList();
	for (IAEItemStack needed : plan) {
		IAEItemStack toExtract = needed.copy();

		// Not sure why this is needed, but AE2 does it itself.
		toExtract.reset();
		toExtract.setStackSize(needed.getStackSize());

		// Simulate the extraction, this is basically a "fast" way to
		// check whether an item exists in the first place.
		// The idea is: if we can extract it, we can use it for crafting.
		IAEItemStack extracted = monitor.extractItems(toExtract, Actionable.SIMULATE, source);

		// If we could not extract the item, we are missing all of the
		// quantity that's required.
		// Otherwise we are only missing the difference between the two.
		// This can be 0 if we were able to extract all of the required items.
		long missing = needed.getStackSize();
		if (extracted != null) missing -= extracted.getStackSize();

		if (missing > 0) {
			IAEItemStack missingStack = needed.copy();
			missingItems.add(missingStack);
		}
	}

	// At this point missingItems should always have at least one
	// element, because isSimulation would return false.
	// But even if it's empty, we need to send event to unblock process

	access.signal(ModuleAppEng.CC_EVENT_STATE_CHANGED,
			converter.fromJava(this.requestedStack),
			"missing_items",
			converter.fromJava(missingItems));
}
 
开发者ID:OpenMods,项目名称:OpenPeripheral-Integration,代码行数:46,代码来源:CraftingCallback.java

示例7: injectEssentia

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
@Override
public long injectEssentia( final Aspect aspect, final long amount, final Actionable mode, final BaseActionSource source, final boolean powered )
{
	// Call super
	long amountRejected = super.injectEssentia( aspect, amount, mode, source, powered );

	if( ( mode == Actionable.MODULATE ) && ( amountRejected < amount ) )
	{
		// Get the crafting grid
		ICraftingGrid craftingGrid = this.internalGrid.getCache( ICraftingGrid.class );

		// Get the CPU list
		ImmutableSet<ICraftingCPU> cpus = craftingGrid.getCpus();

		// Are there any crafting CPU's?
		if( cpus.size() > 0 )
		{
			// Set the aspect
			ItemCraftingAspect.setAspect( this.craftingAspectItem, aspect );

			// Delay creating this as long as possible
			IAEItemStack aspectAEItem = null;

			// Set the amounts
			long amountToInject = amount - amountRejected;

			// Are any CPU's waiting for this?
			for( ICraftingCPU cpu : cpus )
			{
				// Is the cpu crafting, and is it a cluster?
				if( cpu.isBusy() && ( cpu instanceof CraftingCPUCluster ) )
				{
					if( aspectAEItem == null )
					{
						// Create AE version
						aspectAEItem = AEApi.instance().storage().createItemStack( this.craftingAspectItem );
						aspectAEItem.setStackSize( 1 );
					}

					// Cast
					CraftingCPUCluster cluster = (CraftingCPUCluster)cpu;

					// Is the cluster waiting for an aspect item?
					if( cluster.isMaking( aspectAEItem ) )
					{
						// Not a fan of the loop, but inject items doesn't return anything useful
						for( ; ( amountToInject > 0 ) && ( cluster.isBusy() ); --amountToInject )
						{
							// Inject the aspect item
							cluster.injectItems( aspectAEItem, mode, source );
						}

						// Has everything been accounted for?
						if( amountToInject == 0 )
						{
							// All done
							break;
						}
					}
				}
			}
		}
	}

	return amountRejected;
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:67,代码来源:GridEssentiaCache.java

示例8: onClientRequestDeposit

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
/**
 * A client player is requesting to deposit their held item
 * into the ME network.
 */
public void onClientRequestDeposit( final EntityPlayer player, final int mouseButton )
{
	// Ensure there is a player & monitor
	if( ( player == null ) || ( this.monitor == null ) )
	{
		return;
	}

	// Get what the player is holding
	ItemStack playerHolding = player.inventory.getItemStack();

	// Is the player holding anything?
	if( playerHolding == null )
	{
		return;
	}

	// Create the AE itemstack representation of the itemstack
	IAEItemStack toInjectStack = AEApi.instance().storage().createItemStack( playerHolding );

	// Was it a right click or wheel movement?
	boolean depositOne = ( mouseButton == ThEGuiHelper.MOUSE_BUTTON_RIGHT ) || ( mouseButton == ThEGuiHelper.MOUSE_WHEEL_MOTION );

	if( depositOne )
	{
		// Set stack size to 1
		toInjectStack.setStackSize( 1 );
	}

	// Attempt to inject
	IAEItemStack leftOverStack = this.monitor.injectItems( toInjectStack, Actionable.MODULATE, this.playerSource );

	// Was there anything left over?
	if( ( leftOverStack != null ) && ( leftOverStack.getStackSize() > 0 ) )
	{
		// Were we only trying to inject one?
		if( toInjectStack.getStackSize() == 1 )
		{
			// No changes made
			return;
		}

		// Set what was left over as the itemstack being held
		player.inventory.setItemStack( leftOverStack.getItemStack() );
	}
	else
	{
		// Are we only depositing one, and there was more than 1 item?
		if( ( depositOne ) && ( playerHolding.stackSize > 1 ) )
		{
			// Set the player holding one less
			playerHolding.stackSize-- ;
			player.inventory.setItemStack( playerHolding );

			// Set the leftover stack to match
			leftOverStack = AEApi.instance().storage().createItemStack( playerHolding );
		}
		else
		{
			// Set the player as holding nothing
			player.inventory.setItemStack( null );
		}
	}

	// Send the update to the client
	Packet_C_Sync.sendPlayerHeldItem( player, ( leftOverStack == null ? null : leftOverStack.getItemStack() ) );
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:72,代码来源:ContainerPartArcaneCraftingTerminal.java

示例9: requestCraftingReplenishment

import appeng.api.storage.data.IAEItemStack; //导入方法依赖的package包/类
/**
 * Attempts to extract an item from the network.
 * Used when crafting to replenish the crafting grid.
 *
 * @param itemStack
 * @return
 */
public ItemStack requestCraftingReplenishment( final ItemStack itemStack )
{
	if( this.monitor == null )
	{
		return null;
	}

	// Search the players inventory
	ItemStack replenishmentPlayer = this.takeItemFromPlayer( itemStack, 1 );
	if( replenishmentPlayer != null )
	{
		return replenishmentPlayer;
	}

	// Create the AE request stack
	IAEItemStack requestStack = AEApi.instance().storage().createItemStack( itemStack );

	// Set the request amount to one
	requestStack.setStackSize( 1 );

	// Attempt an extraction
	IAEItemStack replenishmentAE = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );

	// Did we get a replenishment?
	if( replenishmentAE != null )
	{
		return replenishmentAE.getItemStack();
	}

	// Did not get a replenishment, search for items that match.

	// Get a list of all items in the ME network
	IItemList<IAEItemStack> networkItems = this.monitor.getStorageList();

	// Search all items
	for( IAEItemStack potentialMatch : networkItems )
	{
		// Does the request match?
		if( this.doStacksMatch( requestStack, potentialMatch ) )
		{
			// Found a match
			requestStack = potentialMatch.copy();

			// Set the request amount to one
			requestStack.setStackSize( 1 );

			// Attempt an extraction
			replenishmentAE = this.monitor.extractItems( requestStack, Actionable.MODULATE, this.playerSource );

			// Did we get a replenishment?
			if( ( replenishmentAE != null ) && ( replenishmentAE.getStackSize() > 0 ) )
			{
				return replenishmentAE.getItemStack();
			}
		}

	}

	// No matches at all :(
	return null;
}
 
开发者ID:Nividica,项目名称:ThaumicEnergistics,代码行数:69,代码来源:ContainerPartArcaneCraftingTerminal.java


注:本文中的appeng.api.storage.data.IAEItemStack.setStackSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。