openperipheral.api.adapter.method.Arg Java Examples

The following examples show how to use openperipheral.api.adapter.method.Arg. 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: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(
		returnTypes = ReturnType.NUMBER,
		description = "Push a page from the notebook into a specific slot in external inventory. Returns the amount of items moved")
public int pushNotebookPage(
		TileEntity desk,
		@Arg(name = "deskSlot") Index deskSlot,
		@Arg(name = "direction", description = "The direction of the other inventory. (north, south, east, west, up or down)") ForgeDirection direction,
		@Arg(name = "fromSlot", description = "The page slot in inventory that you're pushing from") Index fromSlot,
		@Optionals @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into") Index intoSlot) {
	IInventory source = createInventoryWrapper(desk, deskSlot);
	IInventory target = getTargetTile(desk, direction);

	if (intoSlot == null) intoSlot = Index.fromJava(-1, 0);

	final int amount = ItemDistribution.moveItemInto(source, fromSlot.value, target, intoSlot.value, 64, direction.getOpposite(), true);
	if (amount > 0) target.markDirty();
	return amount;
}
 
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: 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 #4
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(description = "Create a symbol page from the target symbol")
public void writeSymbol(final TileEntity desk,
		@Arg(name = "deskSlot") Index deskSlot,
		@Arg(name = "notebookSlot", description = "The source symbol to copy") Index notebookSlot) {
	Preconditions.checkNotNull(MystcraftAccess.pageApi, "Functionality not available");

	final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot);
	ItemStack page = wrapper.getPageFromSlot(notebookSlot);
	final String symbol = MystcraftAccess.pageApi.getPageSymbol(page);
	if (symbol != null) {
		FakePlayerPool.instance.executeOnPlayer((WorldServer)desk.getWorldObj(), new PlayerUser() {
			@Override
			public void usePlayer(OpenModsFakePlayer fakePlayer) {
				WRITE_SYMBOL.call(desk, fakePlayer, symbol);
			}
		});
	}
}
 
Example #5
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Pull an item from the target inventory into any slot in the current one. Returns true if item was consumed")
public boolean 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") Index fromSlot) {

	IInventory inv = getTargetTile(desk, direction);

	fromSlot.checkElementIndex("input slot", inv.getSizeInventory());

	ItemStack stack = inv.getStackInSlot(fromSlot.value);
	Preconditions.checkNotNull(stack, "Other inventory empty");

	final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot);

	ItemStack added = wrapper.addPage(stack);
	inv.setInventorySlotContents(fromSlot.value, added);
	inv.markDirty();
	return added == null;
}
 
Example #6
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 #7
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@Asynchronous(false)
@ScriptCallable(description = "Swap two slots in the inventory")
public void swapStacks(IInventory target,
		@Arg(name = "from", description = "The first slot") Index fromSlot,
		@Arg(name = "to", description = "The other slot") Index intoSlot,
		@Optionals @Arg(name = "fromDirection") ForgeDirection fromDirection,
		@Arg(name = "fromDirection") ForgeDirection toDirection) {
	IInventory inventory = InventoryUtils.getInventory(target);
	Preconditions.checkNotNull(inventory, "Invalid target!");
	final int size = inventory.getSizeInventory();
	fromSlot.checkElementIndex("first slot id", size);
	intoSlot.checkElementIndex("second slot id", size);
	if (inventory instanceof ISidedInventory) {
		InventoryUtils.swapStacks((ISidedInventory)inventory,
				fromSlot.value, Objects.firstNonNull(fromDirection, ForgeDirection.UNKNOWN),
				intoSlot.value, Objects.firstNonNull(toDirection, ForgeDirection.UNKNOWN));
	} else InventoryUtils.swapStacks(inventory, fromSlot.value, intoSlot.value);

	inventory.markDirty();
}
 
Example #8
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 #9
Source File: AdapterInterface.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@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);

}
 
Example #10
Source File: AdapterNoteBlock.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(description = "Plays a minecraft sound")
public void playSound(TileEntityNote noteblock,
		@Arg(name = "sound", description = "The identifier for the sound") String name,
		@Arg(name = "pitch", description = "The pitch from 0 to 1") float pitch,
		@Arg(name = "volume", description = "The volume from 0 to 1") float volume,
		@Optionals @Arg(name = "x", description = "X coordinate od sound (relative to block)") Double dx,
		@Arg(name = "y", description = "Y coordinate of sound (relative to block)") Double dy,
		@Arg(name = "z", description = "Z coordinate of sound (relative to block)") Double dz) {
	noteblock.getWorldObj().playSoundEffect(
			noteblock.xCoord + 0.5 + Objects.firstNonNull(dx, 0.0),
			noteblock.yCoord + 0.5 + Objects.firstNonNull(dy, 0.0),
			noteblock.zCoord + 0.5 + Objects.firstNonNull(dz, 0.0),
			name, volume, pitch);
}
 
Example #11
Source File: AdapterStorage.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = { ReturnType.NUMBER, ReturnType.STRING })
public IMultiReturn getCellStatus(IChestOrDrive target, @Arg(name = "slot") Index slot) {
	try {
		int status = target.getCellStatus(slot.value);
		return MultiReturn.wrap(status, intToState(status));
	} catch (IndexOutOfBoundsException e) {
		throw new IllegalArgumentException("Invalid cell index: " + slot);
	}
}
 
Example #12
Source File: AdapterFrequencyOwner.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Set the frequency of this chest or tank")
public void setColorNames(TileEntity frequencyOwner,
		@Arg(name = "color_left") String colorLeft,
		@Arg(name = "color_middle") String colorMiddle,
		@Arg(name = "color_right") String colorRight) {

	int high = parseColorName(colorLeft);
	int med = parseColorName(colorMiddle);
	int low = parseColorName(colorRight);
	// convert the three colours into a single colour
	int frequency = ((high & 0xF) << 8) + ((med & 0xF) << 4) + (low & 0xF);
	setFreq(frequencyOwner, frequency);
}
 
Example #13
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 #14
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 #15
Source File: AdapterReconfigurableSides.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Set the config for a given side. Returns true if config was changed")
public boolean setSide(IReconfigurableSides target,
		@Arg(name = "side") int side,
		@Arg(name = "config") int config) {
	SecurityUtils.checkAccess(target);
	return target.setSide(side, config);
}
 
Example #16
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(
		returnTypes = ReturnType.NUMBER,
		description = "Push a page from the notebook into a specific slot in external inventory. Returns the amount of items moved")
public int pushNotebookPage(
		TileEntity desk,
		@Arg(name = "deskSlot") Index deskSlot,
		@Arg(name = "direction", description = "The direction of the other inventory. (north, south, east, west, up or down)") ForgeDirection direction,
		@Arg(name = "fromSlot", description = "The page slot in inventory that you're pushing from") Index fromSlot,
		@Optionals @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into") Index intoSlot) {
	final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot);

	ItemStack page = wrapper.getPageFromSlot(fromSlot);

	ItemStack removedPage = wrapper.removePage(page);
	Preconditions.checkNotNull(removedPage, "No page in notebook");

	GenericInventory tmp = new GenericInventory("tmp", false, 1);
	tmp.setInventorySlotContents(0, removedPage.copy());

	final IInventory target = getTargetTile(desk, direction);

	if (intoSlot == null) intoSlot = Index.fromJava(-1, 0);

	int result = ItemDistribution.moveItemInto(tmp, 0, target, intoSlot.value, removedPage.stackSize, direction, true);

	int remains = removedPage.stackSize - result;
	if (remains >= 0) {
		ItemStack returns = removedPage.copy();
		returns.stackSize = remains;
		wrapper.addPage(returns);
	}

	return result;
}
 
Example #17
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 #18
Source File: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Create a symbol page from the target symbol")
public void writeSymbol(final TileEntity desk,
		@Arg(name = "deskSlot") Index deskSlot,
		@Arg(name = "notebookSlot", description = "The source symbol to copy") Index notebookSlot) {
	final String symbol = getSymbolFromPage(getNotebookStackInSlot(desk, deskSlot, notebookSlot));
	if (symbol != null) {
		FakePlayerPool.instance.executeOnPlayer((WorldServer)desk.getWorldObj(), new PlayerUser() {
			@Override
			public void usePlayer(OpenModsFakePlayer fakePlayer) {
				WRITE_SYMBOL.call(desk, fakePlayer, symbol);
			}
		});
	}
}
 
Example #19
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 #20
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 #21
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get details of an item in a particular slot")
public Object getStackInSlot(IInventory target,
		@Arg(name = "slotNumber", description = "Slot number") Index slot,
		@Optionals @Arg(name = "proxy", description = "If true, method will return proxy instead of computing whole table") Boolean proxy) {
	IInventory inventory = InventoryUtils.getInventory(target);
	slot.checkElementIndex("slot id", inventory.getSizeInventory());
	ItemStack stack = inventory.getStackInSlot(slot.value);
	return proxy == Boolean.TRUE? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack;
}
 
Example #22
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 #23
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous(false)
@ScriptCallable(description = "Destroy a stack")
public void destroyStack(IInventory target,
		@Arg(name = "slotNumber", description = "The slot number") Index slot) {
	IInventory inventory = InventoryUtils.getInventory(target);
	slot.checkElementIndex("slot id", inventory.getSizeInventory());
	inventory.setInventorySlotContents(slot.value, null);
	inventory.markDirty();
}
 
Example #24
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets the text on the sign")
public void setLine(TileEntitySign sign,
		@Arg(name = "line", description = "The line number to set the text on the sign") Index line,
		@Arg(name = "text", description = "The text to display on the sign") String text) {
	line.checkElementIndex("line", sign.signText.length);
	setLine(sign, line.value, text);
	updateSign(sign);
}
 
Example #25
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, description = "Gets the text from the supplied line of the sign")
public String getLine(TileEntitySign sign,
		@Arg(name = "line", description = "The line number to get from the sign") Index line) {
	line.checkElementIndex("line", sign.signText.length);
	return sign.signText[line.value];
}
 
Example #26
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets all text from table")
public void setLines(TileEntitySign sign, @Arg(name = "lines") String[] lines) {
	final String[] signText = sign.signText;
	for (int i = 0; i < signText.length; i++) {
		final String line = (i < lines.length? Strings.nullToEmpty(lines[i]) : "");
		signText[i] = line;
	}

	updateSign(sign);
}
 
Example #27
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets the text on the sign")
public void setText(TileEntitySign sign,
		@Arg(name = "text", description = "The text to display on the sign") String text) {
	String[] lines = text.split("\n");

	final int newLength = lines.length;
	final int maxLength = sign.signText.length;

	Preconditions.checkArgument(newLength >= 0 && newLength < maxLength, "Value must be in range [1,%s]", maxLength);

	for (int i = 0; i < maxLength; ++i)
		setLine(sign, i, i < newLength? lines[i] : "");

	updateSign(sign);
}
 
Example #28
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 #29
Source File: AdapterAspectContainer.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Get amount of specific aspect stored in this block")
public int getAspectCount(IAspectContainer container,
		@Arg(name = "aspect", description = "Aspect to be checked") String aspectName) {

	Aspect aspect = Aspect.getAspect(aspectName.toLowerCase(Locale.ENGLISH));
	Preconditions.checkNotNull(aspect, "Invalid aspect name");
	AspectList list = container.getAspects();
	if (list == null) return 0;
	return list.getAmount(aspect);
}
 
Example #30
Source File: AdapterAutoSpawner.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Set the value of spawn exact copy")
public void setSpawnExact(Object tileEntityAutoSpawner, @Arg(name = "spawnExact") boolean spawnExact) {
	SET_SPAWN_EXACT.call(tileEntityAutoSpawner, spawnExact);
}