openperipheral.api.adapter.method.ReturnType Java Examples

The following examples show how to use openperipheral.api.adapter.method.ReturnType. 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: 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 #2
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 results in given bee")
public List<Map<String, Object>> getBeeParents(IBeeHousing housing, @Arg(name = "childType", description = "The type of bee you want the parents 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;
		final IAlleleSpecies species = getOffspringSpecies(mutation);

		if (alleleNameMatches(species, childType)) {
			result.add(serializeMutation(mutation, false));
		}
	}
	return result;
}
 
Example #3
Source File: AdapterSensor.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get the usernames of all the players in range")
public List<GameProfile> getPlayers(ISensorEnvironment env) {
	List<EntityPlayer> players = WorldUtils.getEntitiesWithinAABB(env.getWorld(), EntityPlayer.class, getBoundingBox(env));

	List<GameProfile> names = Lists.newArrayList();
	for (EntityPlayer player : players)
		names.add(player.getGameProfile());

	return names;
}
 
Example #4
Source File: AdapterNoteBlock.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Set the note on the noteblock", returnTypes = { ReturnType.BOOLEAN })
public boolean setPitch(TileEntityNote noteblock,
		@Arg(name = "note", description = "The note you want. From 0 to 25") int newNote) {
	final byte oldNote = noteblock.note;
	noteblock.note = (byte)(newNote % 25);
	if (!net.minecraftforge.common.ForgeHooks.onNoteChange(noteblock, oldNote)) return false;
	noteblock.markDirty();
	return true;
}
 
Example #5
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 #6
Source File: AdapterArcaneBore.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous(false)
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Is the Arcane bore active?")
public boolean isWorking(Object target) {
	ItemStack pick = getPick(target);
	Boolean hasPower = GETTING_POWER.call(target);
	return hasPower && hasFocus(target) && hasPickaxe(target) && pick.isItemStackDamageable() && !isPickaxeBroken(target);
}
 
Example #7
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 #8
Source File: NotebookWrapper.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.STRING)
public String getName() {
	return FakePlayerPool.instance.executeOnPlayer(ownerWorld, new PlayerUserReturning<String>() {
		@Override
		public String usePlayer(OpenModsFakePlayer fakePlayer) {
			return item.getDisplayName(fakePlayer, stack);
		}
	});
}
 
Example #9
Source File: AdapterAspectContainer.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the map of aspects stored in the block (summed, if there are multiple entries)")
public Map<String, Integer> getAspectsSum(IAspectContainer container) {
	AspectList aspectList = container.getAspects();
	if (aspectList == null) return null;
	Map<String, Integer> result = Maps.newHashMap();
	for (Aspect aspect : aspectList.getAspects()) {
		if (aspect == null) continue;
		String name = aspect.getName();
		int amount = Objects.firstNonNull(result.get(name), 0);
		result.put(name, amount + aspectList.getAmount(aspect));
	}
	return result;
}
 
Example #10
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Retrieves details about the specified item from the ME Network.", returnTypes = ReturnType.OBJECT)
public Object getItemDetail(IGridHost host,
		@Arg(name = "item", description = "Details of the item you are looking for") ItemFingerprint needle,
		@Optionals @Arg(name = "proxy", description = "If false, method will compute whole table, instead of returning proxy") Boolean proxy) {
	final IItemList<IAEItemStack> items = getStorageGrid(host).getItemInventory().getStorageList();
	final IAEItemStack stack = findStack(items, needle);
	if (stack == null) return null;
	ItemStack vanillaStack = stack.getItemStack();
	return proxy != Boolean.FALSE? OpcAccess.itemStackMetaBuilder.createProxy(vanillaStack) : vanillaStack;
}
 
Example #11
Source File: TileEntityGlassesBridge.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get the surface of a user to draw privately on their screen")
public SurfaceServer getSurfaceByUUID(@Arg(name = "uuid", description = "The uuid of the user to get the draw surface for") UUID uuid) {
	SurfaceServer playerSurface = getSurface(uuid);
	Preconditions.checkNotNull(playerSurface, "Invalid player");
	return playerSurface;
}
 
Example #12
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from the target inventory into any slot in the current one. Returns the amount of items moved")
public int pullNotebookPage(TileEntity desk,
		@Arg(name = "deskSlot") Index deskSlot,
		@Arg(name = "direction", description = "The direction of the other inventory)") ForgeDirection direction,
		@Arg(name = "fromSlot", description = "The slot in the other inventory that you're pulling from") int notebookSlot) {
	IInventory source = getTargetTile(desk, direction);
	IInventory target = createInventoryWrapper(desk, deskSlot);
	final int amount = ItemDistribution.moveItemInto(source, notebookSlot - 1, target, -1, 1, direction.getOpposite(), true, false);
	if (amount > 0) source.markDirty();
	return amount;
}
 
Example #13
Source File: IDrawableFactory.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Add a new box to the screen")
public Drawable addBox(
		@Arg(name = "x", description = "The x position from the top left") float x,
		@Arg(name = "y", description = "The y position from the top left") float y,
		@Arg(name = "width", description = "The width of the box") float width,
		@Arg(name = "height", description = "The height of the box") float height,
		@Optionals @Arg(name = "color", description = "The color of the box") Integer color,
		@Arg(name = "opacity", description = "The opacity of the box (from 0 to 1)") Float opacity);
 
Example #14
Source File: IDrawableFactory.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Add a quad")
public Drawable addQuad(
		@Arg(name = "p1", description = "Coordinates of first point") Point2d p1,
		@Arg(name = "p2", description = "Coordinates of second point") Point2d p2,
		@Arg(name = "p3", description = "Coordinates of third point") Point2d p3,
		@Arg(name = "p4", description = "Coordinates of fourth point") Point2d p4,
		@Optionals @Arg(name = "color", description = "The color of the line") Integer color,
		@Arg(name = "opacity", description = "The opacity of the line (from 0 to 1)") Float opacity);
 
Example #15
Source File: AdapterSkull.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@MultipleReturn
@ScriptCallable(returnTypes = { ReturnType.STRING, ReturnType.STRING })
public Object[] getPlayer(TileEntitySkull skull) {
	if (skull.func_145904_a() != 3) return new Object[] { null, null };

	GameProfile profile = skull.func_152108_a();
	if (profile == null) return new Object[] { null, null };

	return new Object[] { profile.getId(), profile.getName() };
}
 
Example #16
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 #17
Source File: LuaReflectionHelper.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.STRING)
public String getClass(@Env("target") Object owner) {
	return owner.getClass().toString();
}
 
Example #18
Source File: AdapterReconfigurableFacing.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Set the facing of the block. Returns true if rotation was successful")
public boolean setFacing(IReconfigurableFacing target,
		@Arg(name = "side") int side) {
	SecurityUtils.checkAccess(target);
	return target.setFacing(side);
}
 
Example #19
Source File: LuaReflectionHelper.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.STRING)
public String getSuperclass(@Env("target") Object owner) {
	return owner.getClass().getSuperclass().toString();
}
 
Example #20
Source File: AdapterSensor.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get the ids of all the mobs in range. Deprecated, please use getEntityIds('mob')")
public List<Integer> getMobIds(ISensorEnvironment env) {
	return listEntityIds(env, EntityLiving.class);
}
 
Example #21
Source File: AdapterReactorChamber.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the EU output of this reactor", returnTypes = ReturnType.NUMBER)
public float getEUOutput(IReactorChamber chamber) {
	return getReactor(chamber).getReactorEnergyOutput();
}
 
Example #22
Source File: AdapterSecureTile.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Gets the owner of the machine.", returnTypes = ReturnType.STRING)
public String getOwnerName(ISecurable tile) {
	return tile.getOwnerName();
}
 
Example #23
Source File: IDrawableFactory.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Add a point")
public Drawable addPoint(
		@Arg(name = "coord", description = "Coordinates of point") Point2d p,
		@Optionals @Arg(name = "color", description = "The color of the point") Integer color,
		@Arg(name = "opacity", description = "The opacity of the point (from 0 to 1)") Float opacity);
 
Example #24
Source File: AdapterEnderEnergyAttuned.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Can the machine input energy via the ender net.", returnTypes = ReturnType.BOOLEAN)
public boolean canReceiveEnergy(IEnderEnergyHandler tileEntity) {
	return tileEntity.canReceiveEnergy();
}
 
Example #25
Source File: AdapterChunkLoader.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get chunk loader radius", returnTypes = ReturnType.NUMBER)
public short getRadius(Object tileEntityChunkLoader) {
	return GET_RADIUS.call(tileEntityChunkLoader);
}
 
Example #26
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the maximum stored power in the network.", returnTypes = ReturnType.NUMBER)
public double getMaxStoredPower(IGridHost host) {
	return getEnergyGrid(host).getMaxStoredPower();
}
 
Example #27
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 #28
Source File: AdapterEnergySource.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the EU output", returnTypes = ReturnType.NUMBER)
public double getOfferedEnergy(IEnergySource source) {
	return source.getOfferedEnergy();
}
 
Example #29
Source File: AdapterReconfigurableSides.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Increment the config for a given side. Returns true if config was changed")
public boolean incrSide(IReconfigurableSides target,
		@Arg(name = "side") int side) {
	SecurityUtils.checkAccess(target);
	return target.incrSide(side);
}
 
Example #30
Source File: AdapterSensor.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get the ids of all the minecarts in range. Deprecated, please use getEntityIds('minecart')")
public List<Integer> getMinecartIds(ISensorEnvironment env) {
	return listEntityIds(env, EntityMinecart.class);
}