openperipheral.api.adapter.method.ScriptCallable Java Examples

The following examples show how to use openperipheral.api.adapter.method.ScriptCallable. 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: AdapterSkull.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.STRING)
public String getType(TileEntitySkull skull) {
	int skullType = skull.func_145904_a();

	switch (skullType) {
		case 0:
			return "skeleton";
		case 1:
			return "wither_skeleton";
		case 2:
			return "zombie";
		case 3:
			return "player";
		case 4:
			return "creeper";
	}

	return "unknown";
}
 
Example #2
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 #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: 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 #5
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@Asynchronous(false)
@ScriptCallable(description = "Condense and tidy the stacks in an inventory")
public void condenseItems(IInventory target) {
	IInventory inventory = InventoryUtils.getInventory(target);
	List<ItemStack> stacks = Lists.newArrayList();
	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		ItemStack sta = inventory.getStackInSlot(i);
		if (sta != null) stacks.add(sta.copy());
		inventory.setInventorySlotContents(i, null);
	}

	for (ItemStack stack : stacks)
		ItemDistribution.insertItemIntoInventory(inventory, stack, ForgeDirection.UNKNOWN, ANY_SLOT);

	target.markDirty();
}
 
Example #6
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 #7
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 #8
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 #9
Source File: AdapterBeeHousing.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the full breeding list thingy. Experimental!")
public List<Map<String, Object>> getBeeBreedingData(IBeeHousing housing) {
	ISpeciesRoot beeRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
	if (beeRoot == null) return null;

	List<Map<String, Object>> result = Lists.newArrayList();

	for (IMutation mutation : beeRoot.getMutations(false)) {
		if (mutation.isSecret() && !Config.showHiddenMutations) continue;
		final Map<String, Object> mutationMap = Maps.newHashMap();
		try {
			IAlleleSpecies allele1 = mutation.getAllele0();
			if (allele1 != null) mutationMap.put(ALLELE_1, allele1.getName());
			IAlleleSpecies allele2 = mutation.getAllele1();
			if (allele2 != null) mutationMap.put(ALLELE_2, allele2.getName());

			final IAlleleSpecies offspringSpecies = getOffspringSpecies(mutation);
			mutationMap.put(MUTATION_RESULT, offspringSpecies.getName());

			mutationMap.put(MUTATION_CHANCE, mutation.getBaseChance());
			mutationMap.put(MUTATION_CONDITIONS, mutation.getSpecialConditions());

			result.add(mutationMap);
		} catch (Exception e) {
			throw new RuntimeException(String.format("Failed to get bee breeding information from %s, collected data: %s", mutation, mutationMap), e);
		}
	}
	return result;
}
 
Example #10
Source File: AdapterBeeHousing.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get all known bees species")
public List<Map<String, String>> listAllSpecies(IBeeHousing housing) {
	ISpeciesRoot beeRoot = AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
	if (beeRoot == null) return null;

	final Set<IAlleleSpecies> allSpecies = Sets.newTreeSet(alleleCompatator);

	// approach 1: parents and children of all mutations
	for (IMutation mutation : beeRoot.getMutations(false)) {
		allSpecies.add(mutation.getAllele0());
		allSpecies.add(mutation.getAllele1());
		allSpecies.add(getOffspringSpecies(mutation));
	}

	// approach 2: template bees
	for (IIndividual individual : beeRoot.getIndividualTemplates()) {
		final IGenome genome = individual.getGenome();
		allSpecies.add(genome.getPrimary()); // secondary is same as primary
	}

	// TODO approach 3
	// beeRoot.getRegisteredAlleles(EnumBeeChromosome.SPECIES) (Forestry 4.2 API)

	final List<Map<String, String>> result = Lists.newArrayList();

	for (IAlleleSpecies allele : allSpecies)
		if (!allele.isSecret() || Config.showHiddenBees) result.add(serializeAllele(allele));

	return result;
}
 
Example #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: AdapterReconfigurableSides.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Reset configs on all sides to their base values. Returns true if reset was successful")
public boolean resetSides(IReconfigurableSides target) {
	SecurityUtils.checkAccess(target);
	return target.resetSides();
}
 
Example #20
Source File: AdapterArcaneBore.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Does the Bore mine with silk touch")
public boolean hasSilkTouch(Object target) {
	ItemStack pick = getPick(target);
	return EnchantmentHelper.getEnchantmentLevel(Enchantment.silkTouch.effectId, pick) > 0;
}
 
Example #21
Source File: AdapterEjector.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Is NBT Match enabled?", returnTypes = ReturnType.BOOLEAN)
public boolean getMatchNBT(Object tileEntityEjector) {
	return GET_MATCH_NBT.call(tileEntityEjector);
}
 
Example #22
Source File: AdapterAutoJukebox.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Can a disc be copied?", returnTypes = ReturnType.BOOLEAN)
public boolean getCanCopy(Object tileEntityAutoJukebox) {
	return GET_CAN_COPY.call(tileEntityAutoJukebox);
}
 
Example #23
Source File: AdapterEnergyInfo.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Gets the EnergyPerTick of the machine.", returnTypes = ReturnType.NUMBER)
public int getEnergyPerTickInfo(IEnergyInfo tileEntity) {
	return tileEntity.getInfoEnergyPerTick();
}
 
Example #24
Source File: AdapterEjector.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Set the value of NBT Match toggle")
public void setMatchNBT(Object tileEntityEjector, @Arg(name = "matchNBT") boolean matchNBT) {
	SET_MATCH_NBT.call(tileEntityEjector, matchNBT);
}
 
Example #25
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the stored power in the network.", returnTypes = ReturnType.NUMBER)
public double getStoredPower(IGridHost host) {
	return getEnergyGrid(host).getStoredPower();
}
 
Example #26
Source File: AdapterDeconstructor.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Does the Table have an aspect in it")
public boolean hasAspect(Object target) throws Exception {
	return ASPECT.get(target) != null;
}
 
Example #27
Source File: AdapterBeeHousing.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the queen")
public IIndividual getQueen(IBeeHousing beeHousing) {
	ItemStack queen = beeHousing.getBeeInventory().getQueen();
	return (queen != null)? AlleleManager.alleleRegistry.getIndividual(queen) : null;
}
 
Example #28
Source File: AdapterAugumentable.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Returns a status array for the installed Augmentations.", returnTypes = ReturnType.TABLE)
public boolean[] getAccess(IAugmentable tile) {
	return tile.getAugmentStatus();
}
 
Example #29
Source File: AdapterNetwork.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the average power usage of the network.", returnTypes = ReturnType.NUMBER)
public double getAvgPowerUsage(IGridHost host) {
	return getEnergyGrid(host).getAvgPowerUsage();
}
 
Example #30
Source File: AdapterAutoEnchanter.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get target level of enchantment", returnTypes = ReturnType.NUMBER)
public int getTargetLevel(Object tileEntityAutoEnchanter) {
	return GET_TARGET_LEVEL.call(tileEntityAutoEnchanter);
}