openperipheral.api.adapter.method.Alias Java Examples

The following examples show how to use openperipheral.api.adapter.method.Alias. 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: AdapterFrequencyOwner.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@MultipleReturn
@Alias("getColours")
@ScriptCallable(returnTypes = { ReturnType.NUMBER, ReturnType.NUMBER, ReturnType.NUMBER },
		description = "Get the colours active on this chest or tank")
public int[] getColors(TileEntity frequencyOwner) {
	int frequency = FREQ.get(frequencyOwner);
	// return a map of the frequency in ComputerCraft colour format
	return new int[] {
			1 << (frequency >> 8 & 0xF),
			1 << (frequency >> 4 & 0xF),
			1 << (frequency >> 0 & 0xF)
	};
}
 
Example #2
Source File: AdapterFrequencyOwner.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Alias("setColours")
@ScriptCallable(description = "Set the frequency of this chest or tank")
public void setColors(TileEntity frequencyOwner,
		@Arg(name = "color_left", description = "The first color") int colorLeft,
		@Arg(name = "color_middle", description = "The second color") int colorMiddle,
		@Arg(name = "color_right", description = "The third color") int colorRight) {
	// transform the ComputerCraft colours (2^n) into the range 0-15 And
	int high = parseComputerCraftColor(colorLeft);
	int med = parseComputerCraftColor(colorMiddle);
	int low = parseComputerCraftColor(colorRight);

	int frequency = ((high & 0xF) << 8) + ((med & 0xF) << 4) + (low & 0xF);
	setFreq(frequencyOwner, frequency);
}
 
Example #3
Source File: AdapterTileLamp.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@Alias("setColour")
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Sets the colour of the lamp")
public boolean setColor(TileEntity tile,
		@Arg(description = "The colour you want to set to (in RGB hexadecimal 0xRRGGBB)", name = "color") int colour) {
	return SET_COLOR.call(tile, colour);
}
 
Example #4
Source File: AdapterWorldInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Alias("pullItemIntoSlot")
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from a slot in another inventory into a slot in this one. Returns the amount of items moved")
public int pullItem(IInventory target,
		@Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction,
		@Arg(name = "slot", description = "The slot in the OTHER inventory that you're pulling from") Index fromSlot,
		@Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to pull") Integer maxAmount,
		@Arg(name = "intoSlot", description = "The slot in the current inventory that you want to pull into") Index intoSlot) {

	final TileEntity otherTarget = getNeighborTarget(target, direction);
	if (otherTarget == null) throw new IllegalArgumentException("Other block not found");
	if (!(otherTarget instanceof IInventory)) throw new IllegalArgumentException("Other block is not inventory");

	final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget);
	final IInventory thisInventory = InventoryUtils.getInventory(target);

	if (otherTarget == target) return 0;
	if (maxAmount == null) maxAmount = 64;
	if (intoSlot == null) intoSlot = ANY_SLOT_INDEX;

	checkSlotId(otherInventory, fromSlot, "input");
	checkSlotId(thisInventory, intoSlot, "output");

	final int amount = ItemDistribution.moveItemInto(otherInventory, fromSlot.value, thisInventory, intoSlot.value, maxAmount, direction.getOpposite(), true);
	if (amount > 0) {
		thisInventory.markDirty();
		otherInventory.markDirty();
	}
	return amount;

}
 
Example #5
Source File: AdapterWorldInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Alias("pushItemIntoSlot")
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Push an item from the current inventory into pipe or slot on the other inventory. Returns the amount of items moved")
public int pushItem(IInventory target,
		@Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction,
		@Arg(name = "slot", description = "The slot in the current inventory that you're pushing from") Index fromSlot,
		@Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to push") Integer maxAmount,
		@Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into (ignored when target is pipe") Index intoSlot) {

	final TileEntity otherTarget = getNeighborTarget(target, direction);
	Preconditions.checkNotNull(otherTarget, "Other target not found");
	final IInventory thisInventory = InventoryUtils.getInventory(target);

	if (maxAmount == null) maxAmount = 64;
	if (intoSlot == null) intoSlot = ANY_SLOT_INDEX;

	checkSlotId(thisInventory, fromSlot, "input");

	final int amount;
	if (otherTarget instanceof IInventory) {
		final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget);
		checkSlotId(otherInventory, intoSlot, "output");
		amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, otherInventory, intoSlot.value, maxAmount, direction, true);
		if (amount > 0) otherInventory.markDirty();
	} else {
		final CustomSinks.ICustomSink adapter = CustomSinks.createSink(otherTarget);
		if (adapter == null) throw new IllegalArgumentException("Invalid target");
		amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, adapter, maxAmount, direction, true);
	}

	if (amount > 0) thisInventory.markDirty();
	return amount;
}
 
Example #6
Source File: IDrawableFactory.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Alias("addFluid")
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Add a box textured like a liquid to the screen")
public Drawable addLiquid(
		@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 liquid box") float width,
		@Arg(name = "height", description = "The height of the liquid box") float height,
		@Arg(name = "liquid", description = "The name of the fluid to render") String id);
 
Example #7
Source File: MethodDeclaration.java    From OpenPeripheral with MIT License 5 votes vote down vote up
private static List<String> getNames(Method method, ScriptCallable meta) {
	ImmutableList.Builder<String> names = ImmutableList.builder();

	String mainName = meta.name();

	if (ScriptCallable.USE_METHOD_NAME.equals(mainName)) names.add(method.getName());
	else names.add(mainName);

	Alias alias = method.getAnnotation(Alias.class);
	if (alias != null) names.add(alias.value());
	return names.build();
}
 
Example #8
Source File: IContainer.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Alias("getObjectById")
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get object by id")
public E getById(@Arg(name = "id", description = "Id of drawed object") Index id);
 
Example #9
Source File: MethodDescriptionTest.java    From OpenPeripheral with MIT License 4 votes vote down vote up
@Alias({ "aliasA", "aliasB" })
@ScriptCallable(returnTypes = ReturnType.BOOLEAN)
public boolean test(B target) {
	return true;
}