本文整理汇总了Java中appeng.api.storage.data.IAEItemStack.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IAEItemStack.copy方法的具体用法?Java IAEItemStack.copy怎么用?Java IAEItemStack.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appeng.api.storage.data.IAEItemStack
的用法示例。
在下文中一共展示了IAEItemStack.copy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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 );
}
}
示例3: 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;
}
示例4: 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));
}
示例5: 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;
}