本文整理汇总了Java中li.cil.oc.api.machine.Arguments.count方法的典型用法代码示例。如果您正苦于以下问题:Java Arguments.count方法的具体用法?Java Arguments.count怎么用?Java Arguments.count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类li.cil.oc.api.machine.Arguments
的用法示例。
在下文中一共展示了Arguments.count方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@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 };
}
示例2: toggleFluidLock
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@Callback(doc = "function([boolean:state]):boolean; (Un-)locks the fluid in the tank. Returns the new state.")
public Object[] toggleFluidLock(Context c, Arguments a) throws Exception
{
if(a.count() == 0) {
if(tile.getMasterValve().getFluid() == null) {
throw new Exception("can't lock tank to fluid, no fluid in tank");
}
tile.getMasterValve().toggleFluidLock(!tile.getMasterValve().getTankConfig().isFluidLocked());
return new Object[]{tile.getMasterValve().getTankConfig().isFluidLocked()};
}
else if(a.count() == 1) {
if(!a.isBoolean(1)) {
throw new LuaException("expected argument 1 to be of type \"Boolean\", found \"" + a.checkAny(1).getClass().getSimpleName() + "\"");
}
boolean state = a.checkBoolean(1);
if(state && tile.getMasterValve().getFluid() == null) {
throw new LuaException("can't lock tank to fluid, no fluid in tank");
}
tile.getMasterValve().toggleFluidLock(state);
return new Object[]{tile.getMasterValve().getTankConfig().isFluidLocked()};
}
else {
throw new Exception("insufficient number of arguments found - expected 1, got " + a.count());
}
}
示例3: toggleFluidLock
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@Callback(doc = "function([boolean:state]):boolean; (Un-)locks the fluid in the tank. Returns the new state.")
public Object[] toggleFluidLock(Context c, Arguments a) throws Exception {
if(a.count() == 0) {
if(tile.getMasterValve().getTankConfig().getFluidStack() == null) {
throw new Exception("can't lock tank to fluid, no fluid in tank");
}
tile.getMasterValve().toggleFluidLock(!tile.getMasterValve().getTankConfig().isFluidLocked());
return new Object[]{tile.getMasterValve().getTankConfig().isFluidLocked()};
}
else if(a.count() == 1) {
if(!a.isBoolean(1)) {
throw new Exception("expected argument 1 to be of type \"Boolean\", found \"" + a.checkAny(1).getClass().getSimpleName() + "\"");
}
boolean state = a.checkBoolean(1);
if(state && tile.getMasterValve().getTankConfig().getFluidStack() == null) {
throw new Exception("can't lock tank to fluid, no fluid in tank");
}
tile.getMasterValve().toggleFluidLock(state);
return new Object[]{tile.getMasterValve().getTankConfig().isFluidLocked()};
}
else {
throw new Exception("insufficient number of arguments found - expected 1, got " + a.count());
}
}
示例4: invoke
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@Optional.Method(modid = "OpenComputers")
@Override
public Object[] invoke(String method, Context context, Arguments arguments) throws Exception
{
if (("setActive".equals(method) && arguments.count() == 1 && arguments.isBoolean(0)) || ("setMode".equals(method) && arguments.count() == 1 && arguments.isString(0)) || ("getActive".equals(method) && arguments.count() == 0) || ("getMode".equals(method) && arguments.count() == 0))
{
Object[] result = call(method, arguments.checkAny(0));
if (result[0] != null && result[0].equals("Throw!"))
{
throw new NoSuchMethodException("Wrong argument!");
}
return result;
}
throw new NoSuchMethodException("Wrong argument!");
}
示例5: invoke
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@Optional.Method(modid = "OpenComputers")
@Override
public Object[] invoke(String method, Context context, Arguments arguments) throws Exception
{
if (("setActive".equals(method) && arguments.count() == 1 && arguments.isBoolean(0)) || "getActive".equals(method))
{
return call(method, arguments.checkBoolean(0));
}
throw new Exception("Wrong argument");
}
示例6: invoke
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@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);
}
示例7: dial
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@Callback(doc = "function(uid:string):boolean -- Attempts to create a connection to the specified portal. UID must be given as a single string in the format of numbers separated by spaces.")
@Method(modid = OpenComputers.MOD_ID)
public Object[] dial(Context context, Arguments args) throws Exception {
if (args.count() < 1)
return null;
return comp_Dial(ComputerUtils.argsToArray(args));
}
示例8: argsToArray
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
public static Object[] argsToArray(Arguments args) {
Object[] data = new Object[args.count()];
for (int i = 0; i < data.length; i++)
if (args.isString(i))
data[i] = args.checkString(i);
else
data[i] = args.checkAny(i);
return data;
}
示例9: setFace
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@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))) };
}
示例10: setDirection
import li.cil.oc.api.machine.Arguments; //导入方法依赖的package包/类
@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))) */};
}