Examples of LuaMethod


Examples of pneumaticCraft.common.thirdparty.computercraft.LuaMethod

    @Override
    @Optional.Method(modid = ModIds.COMPUTERCRAFT)
    public void addLuaMethods(){
        super.addLuaMethods();

        luaMethods.add(new LuaMethod("getSensorNames"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return SensorHandler.instance().getSensorNames();
                } else {
                    throw new IllegalArgumentException("getSensorNames doesn't accept any arguments!");
                }
            }
        });

        luaMethods.add(new LuaMethod("setSensor"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    ISensorSetting sensor = null;
                    if(args[0] instanceof String) {
                        sensor = SensorHandler.instance().getSensorForName((String)args[0]);
                    } else {
                        sensor = SensorHandler.instance().getSensorByIndex(((Double)args[0]).intValue() - 1);
                    }
                    if(sensor != null) return new Object[]{setSensorSetting(sensor)};
                    throw new IllegalArgumentException("Invalid sensor name/index: " + args[0]);
                } else if(args.length == 0) {
                    setSensorSetting("");
                    return new Object[]{true};
                } else {
                    throw new IllegalArgumentException("setSensor needs one argument(a number as index, or a sensor name).");
                }
            }
        });

        luaMethods.add(new LuaMethod("getSensor"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    ISensorSetting curSensor = SensorHandler.instance().getSensorFromPath(getSensorSetting());
                    return curSensor == null ? null : new Object[]{getSensorSetting().substring(getSensorSetting().lastIndexOf('/') + 1)};
                } else {
                    throw new IllegalArgumentException("getSensor doesn't take any arguments!");
                }
            }
        });

        luaMethods.add(new LuaMethod("setTextfield"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    setText(0, (String)args[0]);
                    return null;
                } else {
                    throw new IllegalArgumentException("setTextfield takes one argument (string)");
                }
            }
        });

        luaMethods.add(new LuaMethod("getTextfield"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return new Object[]{getText(0)};
                } else {
                    throw new IllegalArgumentException("getTextfield takes no arguments");
                }
            }
        });

        luaMethods.add(new LuaMethod("isSensorEventBased"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return new Object[]{SensorHandler.instance().getSensorFromPath(getSensorSetting()) instanceof IEventSensorSetting};
                } else {
                    throw new IllegalArgumentException("isSensorEventBased takes no arguments");
                }
            }
        });

        luaMethods.add(new LuaMethod("getSensorValue"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    ISensorSetting s = SensorHandler.instance().getSensorFromPath(getSensorSetting());
                    if(s instanceof IPollSensorSetting) {
                        requestPollPullEvent = true;
                        return new Object[]{redstoneStrength};
                    } else if(s != null) {
                        throw new IllegalArgumentException("The selected sensor is pull event based. You can't poll the value.");
                    } else {
                        throw new IllegalArgumentException("There's no sensor selected!");
                    }
                } else {
                    throw new IllegalArgumentException("getSensorValue takes no arguments");
                }
            }
        });
        luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_UNIVERSAL_SENSOR));

        luaMethods.add(new LuaMethod("setGPSToolCoordinate"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 4) {
                    ItemStack stack = getStackInSlot(((Double)args[0]).intValue() - 1); //minus one, as lua is 1-oriented.
                    if(stack != null && stack.getItem() == Itemss.GPSTool) {
View Full Code Here

Examples of pneumaticCraft.common.thirdparty.computercraft.LuaMethod

    @Override
    @Optional.Method(modid = ModIds.COMPUTERCRAFT)
    protected void addLuaMethods(){
        super.addLuaMethods();
        luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_ELEVATOR));
        luaMethods.add(new LuaMethod("setHeight"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    getCoreElevator().targetExtension = Math.min(((Double)args[0]).floatValue(), getCoreElevator().getMaxElevatorHeight());
                    if(getCoreElevator().isControlledByRedstone()) getCoreElevator().handleGUIButtonPress(0, null);
                    getCoreElevator().sendNBTPacket(256D);
                    return null;
                } else {
                    throw new IllegalArgumentException("setHeight does take one argument (height)");
                }
            }
        });

        luaMethods.add(new LuaMethod("setExternalControl"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    if((Boolean)args[0] && getCoreElevator().isControlledByRedstone() || !(Boolean)args[0] && !getCoreElevator().isControlledByRedstone()) {
                        getCoreElevator().handleGUIButtonPress(0, null);
View Full Code Here

Examples of pneumaticCraft.common.thirdparty.computercraft.LuaMethod

    }

    @Override
    @Optional.Method(modid = ModIds.COMPUTERCRAFT)
    protected void addLuaMethods(){
        luaMethods.add(new LuaMethod("getPressure"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return new Object[]{getPressure(ForgeDirection.UNKNOWN)};
                } else if(args.length == 1) {
View Full Code Here

Examples of pneumaticCraft.common.thirdparty.computercraft.LuaMethod

    @Optional.Method(modid = ModIds.COMPUTERCRAFT)
    protected void addLuaMethods(){
        super.addLuaMethods();
        luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_AIR_CANNON));

        luaMethods.add(new LuaMethod("setTargetLocation"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 3) {
                    gpsX = ((Double)args[0]).intValue();
                    gpsY = ((Double)args[1]).intValue();
                    gpsZ = ((Double)args[2]).intValue();
                    updateDestination();
                    return new Object[]{coordWithinReach};
                } else {
                    throw new IllegalArgumentException("setTargetLocation requires 3 parameters (x,y,z)");
                }
            }
        });

        luaMethods.add(new LuaMethod("fire"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return new Object[]{fire()};//returns true if the fire succeeded.
                } else {
                    throw new IllegalArgumentException("fire doesn't take any arguments!");
                }
            }
        });
        luaMethods.add(new LuaMethod("isDoneTurning"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 0) {
                    return new Object[]{doneTurning};
                } else {
                    throw new IllegalArgumentException("isDoneTurning doesn't take any arguments!");
                }
            }
        });

        luaMethods.add(new LuaMethod("setRotationAngle"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    setTargetAngles(((Double)args[0]).floatValue(), targetHeightAngle);
                    return null;
                } else {
                    throw new IllegalArgumentException("setRotationAngle does take one argument!");
                }
            }
        });

        luaMethods.add(new LuaMethod("setHeightAngle"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    setTargetAngles(targetRotationAngle, 90 - ((Double)args[0]).floatValue());
                    return null;
                } else {
                    throw new IllegalArgumentException("setHeightAngle does take one argument!");
                }
            }
        });

        luaMethods.add(new LuaMethod("setExternalControl"){
            @Override
            public Object[] call(IComputerAccess computer, ILuaContext context, Object[] args) throws LuaException, InterruptedException{
                if(args.length == 1) {
                    externalControl = (Boolean)args[0];
                    return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.