Java Code Examples for li.cil.oc.api.machine.Arguments#count()

The following examples show how to use li.cil.oc.api.machine.Arguments#count() . 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: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Callback(doc = "function(face, direction):boolean -- Sets the motor's face and direction. Returns true if it succeeded, false if it didn't.")
public Object[] set(Context context, Arguments args) {

    if (args.count() < 2)
        throw new RuntimeException("At least 2 arguments are required (face, direction)");

    ForgeDirection face = toFD(args.checkAny(0));
    ForgeDirection direction = toFD(args.checkAny(1));

    if (face == null || direction == null)
        throw new RuntimeException("Invalid directions!");
    if (face == direction || face == direction.getOpposite())
        throw new RuntimeException("Motors cannot push or pull blocks!");

    // te.setFace(face, true);
    // te.setDirection(direction, true);

    return new Object[] { true };
}
 
Example 2
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Callback(doc = "function(face):boolean -- Sets the motor's face. Returns true if it succeeded, false if it didn't.")
public Object[] setFace(Context context, Arguments args) {

    if (args.count() == 0)
        throw new RuntimeException("At least 1 argument is required (direction)");
    return new Object[] { te.setFace(toFD(args.checkAny(0))) };
}
 
Example 3
Source File: EnvironmentMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Callback(doc = "function(direction):boolean -- Sets the motor's direction. Returns true if it succeeded, false if it didn't.")
public Object[] setDirection(Context context, Arguments args) {

    if (args.count() == 0)
        throw new RuntimeException("At least 1 argument is required (direction)");
    return new Object[] { /* te.setDirection(toFD(args.checkAny(0))) */};
}
 
Example 4
Source File: TileEntityReactorComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(final String method, final Context context,
					   final Arguments args) throws Exception {
	final Object[] arguments = new Object[args.count()];
	for (int i = 0; i < args.count(); ++i) {
		arguments[i] = args.checkAny(i);
	}
	final Integer methodId = methodIds.get(method);
	if (methodId == null) {
		throw new NoSuchMethodError();
	}
	return callMethod(methodId, arguments);
}
 
Example 5
Source File: TileEntityTurbineComputerPort.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
@Optional.Method(modid = "OpenComputers")
public Object[] invoke(final String method, final Context context,
					   final Arguments args) throws Exception {
	final Object[] arguments = new Object[args.count()];
	for (int i = 0; i < args.count(); ++i) {
		arguments[i] = args.checkAny(i);
	}
	final Integer methodId = methodIds.get(method);
	if (methodId == null) {
		throw new NoSuchMethodError();
	}
	return callMethod(methodId, arguments);
}