Java Code Examples for openperipheral.api.adapter.method.ReturnType#TABLE

The following examples show how to use openperipheral.api.adapter.method.ReturnType#TABLE . 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: AdapterBeeHousing.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get possible mutations that can be created with given bee")
public List<Map<String, Object>> getBeeChildren(IBeeHousing housing, @Arg(name = "parentYpe", description = "The type of bee you want the children for") String childType) {
	ISpeciesRoot beeRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
	if (beeRoot == null) return null;

	List<Map<String, Object>> result = Lists.newArrayList();
	childType = childType.toLowerCase(Locale.ENGLISH);

	for (IMutation mutation : beeRoot.getMutations(false)) {
		if (mutation.isSecret() && !Config.showHiddenMutations) continue;

		if (alleleNameMatches(mutation.getAllele0(), childType) || alleleNameMatches(mutation.getAllele1(), childType)) {
			result.add(serializeMutation(mutation, true));
		}
	}
	return result;
}
 
Example 2
Source File: AdapterSensor.java    From OpenPeripheral-Addons with MIT License 6 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a table of information about a single block in the surrounding area. Includes map color and whether each block is UNKNOWN, AIR, LIQUID, or SOLID.")
public Map<String, Object> sonicScanTarget(ISensorEnvironment env,
		@Arg(name = "xOffset", description = "The target's offset from the sensor on the X-Axis.") int dx,
		@Arg(name = "yOffset", description = "The target's offset from the sensor on the Y-Axis.") int dy,
		@Arg(name = "zOffset", description = "The target's offset from the sensor on the Z-Axis.") int dz) {
	int range = 1 + env.getSensorRange() / 2;
	int rangeSq = range * range;
	if (checkRange(dx, dy, dz, rangeSq)) return null;

	Vec3 sensorPos = env.getLocation();
	int sx = MathHelper.floor_double(sensorPos.xCoord);
	int sy = MathHelper.floor_double(sensorPos.yCoord);
	int sz = MathHelper.floor_double(sensorPos.zCoord);

	return describeBlock(env.getWorld(), sx, sy, sz, dx, dy, dz);
}
 
Example 3
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(description = "Get a list of the stored and craftable items in the network.", returnTypes = ReturnType.TABLE)
public List<?> getAvailableItems(IGridHost host,
		@Env(Constants.ARG_CONVERTER) IConverter converter,
		@Optionals @Arg(name = "details", description = "Format of stored items details (defalt: none)") ItemDetails format) {
	IStorageGrid storageGrid = getStorageGrid(host);
	final IItemList<IAEItemStack> storageList = storageGrid.getItemInventory().getStorageList();

	List<Object> result = Lists.newArrayList();
	for (IAEItemStack stack : storageList) {
		@SuppressWarnings("unchecked")
		Map<String, Object> map = (Map<String, Object>)converter.fromJava(stack);
		if (format != null && format != ItemDetails.NONE) {
			final ItemStack itemStack = stack.getItemStack();
			if (format == ItemDetails.PROXY) map.put("item", OpcAccess.itemStackMetaBuilder.createProxy(itemStack));
			else if (format == ItemDetails.ALL) map.put("item", itemStack);
		}
		result.add(map);
	}

	return result;
}
 
Example 4
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(description = "Get a list of tables representing the available CPUs in the network.", returnTypes = ReturnType.TABLE)
public List<Map<String, Object>> getCraftingCPUs(IGridHost host) {
	ICraftingGrid craftingGrid = getCraftingGrid(host);

	List<Map<String, Object>> cpus = Lists.newArrayList();
	for (ICraftingCPU cpu : craftingGrid.getCpus()) {
		Map<String, Object> cpuDetails = Maps.newHashMap();
		cpuDetails.put("name", cpu.getName());
		cpuDetails.put("storage", cpu.getAvailableStorage());
		cpuDetails.put("coprocessors", cpu.getCoProcessors());
		cpuDetails.put("busy", cpu.isBusy());
		cpus.add(cpuDetails);
	}

	return cpus;
}
 
Example 5
Source File: AdapterFlowerPot.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE)
public ItemStack getContents(TileEntityFlowerPot pot) {
	Item item = pot.getFlowerPotItem();

	if (item == null) return null;
	int data = pot.getFlowerPotData();
	return new ItemStack(item, 1, data);
}
 
Example 6
Source File: MethodsListerHelper.java    From OpenPeripheral with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a complete table of information about all available methods")
public Map<?, ?> getAdvancedMethodsData(@Optionals @Arg(name = "method") String methodName) {
	if (methodName != null) {
		IMethodExecutor method = methods.get(methodName);
		Preconditions.checkArgument(method != null, "Method not found");
		return DocUtils.describe(method.description());
	} else {
		Map<String, Object> info = Maps.newHashMap();
		for (Map.Entry<String, IMethodExecutor> e : methods.entrySet()) {
			final IMethodDescription desc = e.getValue().description();
			info.put(e.getKey(), DocUtils.describe(desc));
		}
		return info;
	}
}
 
Example 7
Source File: LuaReflectionHelper.java    From OpenPeripheral with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE)
public List<String> getInterfaces(@Env("target") Object owner) {
	List<String> results = Lists.newArrayList();
	for (Class<?> cls : owner.getClass().getInterfaces())
		results.add(cls.toString());
	return results;
}
 
Example 8
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a table with all the items of the chest")
public Map<Index, Object> getAllStacks(IInventory target,
		@Env(Constants.ARG_ARCHITECTURE) IArchitecture access,
		@Optionals @Arg(name = "proxy", description = "If false, method will compute whole table, instead of returning proxy") Boolean proxy) {
	final IInventory inventory = InventoryUtils.getInventory(target);
	Map<Index, Object> result = Maps.newHashMap();

	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		ItemStack stack = inventory.getStackInSlot(i);
		if (stack != null) result.put(access.createIndex(i), (proxy != Boolean.FALSE)? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack);
	}
	return result;
}
 
Example 9
Source File: AdapterJar.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the Aspects stored in the block")
public List<Map<String, Object>> getAspects(IAspectContainer container) {
	List<Map<String, Object>> result = ConverterAspectList.aspectsToMap(container.getAspects());
	if (result.isEmpty()) {
		Aspect filter = ASPECT_FILTER.get(container);
		if (filter != null) ConverterAspectList.appendAspectEntry(result, filter, 0);
	}

	return result;
}
 
Example 10
Source File: AdapterRecordPlayer.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the record currently being played")
public ItemStack getRecord(TileEntityJukebox recordPlayer) {
	return recordPlayer.func_145856_a();
}
 
Example 11
Source File: IContainer.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get all objects")
public Map<Index, E> getAllObjects(@Env(Constants.ARG_ARCHITECTURE) IArchitecture access);
 
Example 12
Source File: AdapterDeepStorage.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE)
public ItemStack getStoredItems(IDeepStorageUnit target) {
	return target.getStoredItemType();
}
 
Example 13
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 14
Source File: AdapterJar.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the aspect filtered by this block block")
public String getAspectFilter(Object target) {
	Aspect aspect = ASPECT_FILTER.get(target);
	return aspect != null? aspect.getName() : "";
}
 
Example 15
Source File: AdapterFluidTank.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Returns info containing the capacity of the tank and the FluidStack it holds.")
public FluidTankInfo getInfo(IFluidTank tank) {
	return tank.getInfo();
}
 
Example 16
Source File: LuaReflectionHelper.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE)
public Map<String, Map<String, Object>> getMethods(@Env("target") Object owner) {
	return describe(owner.getClass().getMethods());
}
 
Example 17
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Gets all text as table")
public String[] getLines(TileEntitySign sign) {
	return sign.signText;
}
 
Example 18
Source File: AdapterAugumentable.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Returns an array of the Augment slots.", returnTypes = ReturnType.TABLE)
public ItemStack[] getAugumentSlots(IAugmentable tile) {
	return tile.getAugmentSlots();
}
 
Example 19
Source File: AdapterInventoryHandler.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the contents of the IInventoryHandler's inventory")
List<ItemStack> getInventoryContents(IInventoryHandler target,
		@Arg(name = "from") ForgeDirection from) {
	return target.getInventoryContents(from);
}
 
Example 20
Source File: NotebookWrapper.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE)
public ItemStack getPageFromSlot(@Arg(name = "slot") Index slot) {
	List<ItemStack> pages = getPages();
	slot.checkElementIndex("slot", pages.size());
	return pages.get(slot.value);
}