Posted 03 April 2013 - 12:22 PM
First of all: i am not sure if this topic fits here. Its an additional abstraction layer for CC API and therefore directly related to Peripherals. on the other hand its no actual peripheral. Please move this topic if it doesn't fit here
——————————————————-
When rewriting kilobytesPeripherals i was making a LuaJ like value api and some reflection magic to make coding easier. And now i thought, hey, lets share it. Its not 100% stable yet, but about 98%. Here an example peripheral:
please note, that the includes aren't all right :P/> but otherwise it should work (yes, its an untested example, but its mostly for telling you how it works anyways).
Repo Link: https://bitbucket.or...c-value-api/src
Download Link: https://bitbucket.or...e-api/downloads -> 'Branches' tab -> 'master'
Note: There are no binary distributions. this API is intended to be included in your project. just drop the contents of the src folder on the repo into src/minecraft in MCP
Happy hacking and greets, Kilobyte
——————————————————-
When rewriting kilobytesPeripherals i was making a LuaJ like value api and some reflection magic to make coding easier. And now i thought, hey, lets share it. Its not 100% stable yet, but about 98%. Here an example peripheral:
import dan200.computer.api.IComputerAccess;
import de.kilobyte22.lib.ccvalueapi.tileentity.PeripheralTileEntity;
import de.kilobyte22.lib.ccvalueapi.reflection.PeripheralFunction;
import de.kilobyte22.lib.ccvalueapi.LuaError;
import de.kilobyte22.lib.ccvalueapi.values.Varargs;
public class TileEntityMyPeripheral extends PeripheralTileEntity {
@Override
public String getType() {
return "myPeripheral";
}
@PeripheralFunction("myFirstFunction") // The name this function will be called with ingame
public Varargs function1(IComputerAccess computer, Varargs args) {
// The function must have the param types IComputerAccess, Varargs
// and has to return Varargs
//What it will do: accept 2 strings and combine them (basicly string1..string2 in lua)
return new Varargs(args.checkstring(1) + args.checkstring(2));
}
@PeripheralFunction("getHealth")
public Varargs iwantzhealth(IComputerAccess computer, Varargs args) {
// returns the players health or an error if player is not in current world
EntityPlayer entityPlayer = worldObj.getPlayerEntityByName(args.checkstring(1));
if (entityPlayer == null)
throw new LuaError("Player offline or in different world"); // This will arrive in Lua as if you used error()
return new Varargs(entityPlayer.getHealth());
}
@PeripheralFunction("broadcastAttached")
public Varargs broadcastAttached(IComputerAccess computer, Varargs args) {
// broadcast the event. INFO: it will always pass the side the peripheral is attached to as first param
broadcastEvent("event_broadcast", args); // broadcastEvent() actually has 4 overloadings, check them out in the source
return new Varargs();
}
}
please note, that the includes aren't all right :P/> but otherwise it should work (yes, its an untested example, but its mostly for telling you how it works anyways).
Repo Link: https://bitbucket.or...c-value-api/src
Download Link: https://bitbucket.or...e-api/downloads -> 'Branches' tab -> 'master'
Note: There are no binary distributions. this API is intended to be included in your project. just drop the contents of the src folder on the repo into src/minecraft in MCP
Happy hacking and greets, Kilobyte