openperipheral.api.adapter.Asynchronous Java Examples

The following examples show how to use openperipheral.api.adapter.Asynchronous. 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: 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 #2
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 #3
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 #4
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 getSurfaceByName(@Arg(name = "username", description = "The username of the user to get the draw surface for") String username) {
	SurfaceServer playerSurface = getSurface(username);
	Preconditions.checkNotNull(playerSurface, "Invalid player");
	return playerSurface;
}
 
Example #5
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 #6
Source File: TileEntityGlassesBridge.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the names of all the users linked up to this bridge")
public List<GameProfile> getUsers() {
	List<GameProfile> result = Lists.newArrayList();
	for (PlayerInfo info : knownPlayersByUUID.values())
		result.add(info.profile);

	return result;
}
 
Example #7
Source File: TileEntitySelector.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(description = "Gets all slots", returnTypes = ReturnType.TABLE)
public List<ItemStack> getSlots() {
	List<ItemStack> result = Lists.newArrayList();

	for (SyncableItemStack slot : slots)
		result.add(slot.get());

	return result;
}
 
Example #8
Source File: TileEntitySelector.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(description = "Get the item currently being displayed in a specific slot", returnTypes = ReturnType.TABLE, name = "getSlot")
public ItemStack getSlotOneBased(@Arg(name = "slot", description = "The slot you want to get details about") Index slot) {

	slot.checkElementIndex("slot id", 10);
	return slots[slot.value].get();
}
 
Example #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: AdapterFrequencyOwner.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@MultipleReturn
@ScriptCallable(returnTypes = { ReturnType.STRING, ReturnType.STRING, ReturnType.STRING },
		description = "Get the colours active on this chest or tank")
public String[] getColorNames(TileEntity frequencyOwner) {
	int frequency = FREQ.get(frequencyOwner);
	return new String[] {
			colorToName(frequency >> 8 & 0xF),
			colorToName(frequency >> 4 & 0xF),
			colorToName(frequency >> 0 & 0xF)
	};
}
 
Example #15
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 #16
Source File: AnnotationMetaExtractor.java    From OpenPeripheral with MIT License 4 votes vote down vote up
private static boolean isAsynchronous(AnnotatedElement element, boolean defaultValue) {
	if (element == null) return defaultValue;
	Asynchronous async = element.getAnnotation(Asynchronous.class);
	return async != null? async.value() : defaultValue;
}
 
Example #17
Source File: TileEntityTicketMachine.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, description = "Returns owner of this machine")
public String getOwner() {
	return owner.getValue();
}
 
Example #18
Source File: TileEntityGlassesBridge.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Returns object used for controlling player capture mode")
public GuiCaptureControl getCaptureControl(@Arg(name = "uuid") UUID uuid) {
	PlayerInfo info = knownPlayersByUUID.get(uuid);
	return info != null? new GuiCaptureControl(getOrCreateGuid(), info.player) : null;
}
 
Example #19
Source File: AdapterDrawbridgeLogicBase.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(description = "Checks if the drawbridge is extended or not", returnTypes = ReturnType.BOOLEAN)
public boolean hasExtended(IDrawbridgeLogicBase drawbridge) {
	return drawbridge.hasExtended();
}
 
Example #20
Source File: TileEntityGlassesBridge.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, name = "getGuid", description = "Get the Guid of this bridge")
public String getGuidString() {
	return TerminalUtils.formatTerminalId(getOrCreateGuid());
}
 
Example #21
Source File: AdapterNoteBlock.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Get the note currently set on this noteblock")
public byte getNote(TileEntityNote noteblock) {
	return noteblock.note;
}
 
Example #22
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, description = "Gets the text on the sign")
public String getText(TileEntitySign sign) {
	return StringUtils.join(sign.signText, '\n');
}
 
Example #23
Source File: AdapterFrequencyOwner.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Get the frequency of this chest or tank")
public int getFrequency(TileEntity frequencyOwner) {
	return FREQ.get(frequencyOwner);
}