appeng.api.AEApi Java Examples

The following examples show how to use appeng.api.AEApi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 7 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
private boolean checkForInterface(){
    if(isPlacedOnInterface()) {
        TileEntity te = getTileEntity();
        if(te instanceof IGridHost) {
            if(((IGridHost)te).getGridNode(null) == null) return true;
            if(getGridNode(null) == null) return true;
            try {
                AEApi.instance().createGridConnection(getGridNode(null), ((IGridHost)te).getGridNode(null));
            } catch(FailedConnection e) {
                Log.error("Couldn't connect to an ME Interface!");
                e.printStackTrace();
            }
        }
    }
    return false;
}
 
Example #2
Source File: StorageCellMetaProvider.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@Override
public Object getMeta(Item target, ItemStack stack) {
	IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell().getCellInventory(stack, null, StorageChannel.ITEMS);// get the inventory handler from ae api
	if (inventory instanceof ICellInventoryHandler) {
		ICellInventoryHandler handler = (ICellInventoryHandler)inventory;
		ICellInventory cellInventory = handler.getCellInv();
		if (cellInventory != null) {
			Map<String, Object> ret = Maps.newHashMap();

			ret.put("preformatted", handler.isPreformatted());
			ret.put("fuzzy", handler.isFuzzy());
			ret.put("freeBytes", cellInventory.getFreeBytes());
			ret.put("totalBytes", cellInventory.getTotalBytes());
			ret.put("usedBytes", cellInventory.getUsedBytes());
			ret.put("totalTypes", cellInventory.getTotalItemTypes());
			ret.put("usedTypes", cellInventory.getStoredItemTypes());
			ret.put("freeTypes", cellInventory.getRemainingItemTypes());

			return ret;
		}
	}

	return null;
}
 
Example #3
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public void onStackChange(IItemList arg0, IAEStack arg1, IAEStack arg2, BaseActionSource arg3, StorageChannel arg4){
    if(craftingGrid != null) {
        ICraftingGrid grid = (ICraftingGrid)craftingGrid;
        for(int i = 0; i < getFilters().getSizeInventory(); i++) {
            ItemStack s = getFilters().getStackInSlot(i);
            if(s != null) {
                if(!grid.isRequesting(AEApi.instance().storage().createItemStack(s))) {
                    getFilters().setInventorySlotContents(i, null);
                    notifyNetworkOfCraftingChange();
                }
            }
        }
    }
}
 
Example #4
Source File: MotorModifierAE2.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFirstTick() {

    // FIXME _super.onFirstTick();

    if (getWorld() != null && !getWorld().isRemote) {
        if (node == null)
            node = AEApi.instance().createGridNode(this);
        node.updateState();
    }
}
 
Example #5
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Optional.Method(modid = ModIds.AE2)
public IGridNode getGridNode(ForgeDirection d){
    if(gridNode == null) {
        gridNode = AEApi.instance().createGridNode(this);
    }
    return (IGridNode)gridNode;
}
 
Example #6
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
public List<IAEItemStack> getProvidingItems(){
    List<IAEItemStack> stacks = new ArrayList<IAEItemStack>();
    for(TileEntity te : providingInventories.keySet()) {
        IInventory inv = IOHelper.getInventoryForTE(te);
        if(inv != null) {
            for(int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack stack = inv.getStackInSlot(i);
                if(stack != null) stacks.add(AEApi.instance().storage().createItemStack(stack));
            }
        }
    }
    return stacks;
}
 
Example #7
Source File: AdapterInterface.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@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;
}
 
Example #8
Source File: StorageCellMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public boolean canApply(Item target, ItemStack stack) {
	return AEApi.instance().registries().cell().isCellHandled(stack);
}
 
Example #9
Source File: CraftingCallback.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
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));
}
 
Example #10
Source File: SemiBlockRequester.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Optional.Method(modid = ModIds.AE2)
public boolean isPlacedOnInterface(){
    return getTileEntity() != null && AEApi.instance().definitions().blocks().iface().maybeBlock().get() == getTileEntity().getBlockType();
}