Search in sources :

Example 1 with LuaMethod

use of me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod in project pnc-repressurized by TeamPneumatic.

the class TileEntityPneumaticBase method addLuaMethods.

@Override
protected void addLuaMethods() {
    super.addLuaMethods();
    luaMethods.add(new LuaMethod("getPressure") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { airHandler.getPressure() };
            } else if (args.length == 1) {
                IAirHandler handler = getAirHandler(getDirForString((String) args[0]));
                return new Object[] { handler != null ? handler.getPressure() : 0 };
            } else {
                throw new IllegalArgumentException("getPressure method requires 0 or 1 argument (direction: up, down, east, west, north, south)!");
            }
        }
    });
    luaMethods.add(new LuaConstant("getDangerPressure", dangerPressure));
    luaMethods.add(new LuaConstant("getCriticalPressure", criticalPressure));
    luaMethods.add(new LuaConstant("getDefaultVolume", defaultVolume));
}
Also used : IAirHandler(me.desht.pneumaticcraft.api.tileentity.IAirHandler) LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant)

Example 2 with LuaMethod

use of me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod in project pnc-repressurized by TeamPneumatic.

the class TileEntityUniversalSensor method addLuaMethods.

@Override
public void addLuaMethods() {
    super.addLuaMethods();
    luaMethods.add(new LuaMethod("getSensorNames") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return SensorHandler.getInstance().getSensorNames();
            } else {
                throw new IllegalArgumentException("getSensorNames doesn't accept any arguments!");
            }
        }
    });
    luaMethods.add(new LuaMethod("setSensor") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                ISensorSetting sensor;
                if (args[0] instanceof String) {
                    sensor = SensorHandler.getInstance().getSensorForName((String) args[0]);
                } else {
                    sensor = SensorHandler.getInstance().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(Object[] args) throws Exception {
            if (args.length == 0) {
                ISensorSetting curSensor = SensorHandler.getInstance().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(Object[] args) throws Exception {
            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(Object[] args) throws Exception {
            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(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { SensorHandler.getInstance().getSensorFromPath(getSensorSetting()) instanceof IEventSensorSetting };
            } else {
                throw new IllegalArgumentException("isSensorEventBased takes no arguments");
            }
        }
    });
    luaMethods.add(new LuaMethod("getSensorValue") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                ISensorSetting s = SensorHandler.getInstance().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(Object[] args) throws Exception {
            if (args.length == 4) {
                // minus one, as lua is 1-oriented.
                ItemStack stack = upgradeHandler.getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack.getItem() == Itemss.GPS_TOOL) {
                    ItemGPSTool.setGPSLocation(stack, new BlockPos((Double) args[1], (Double) args[2], (Double) args[3]));
                    return new Object[] { true };
                } else {
                    return new Object[] { false };
                }
            } else {
                throw new IllegalArgumentException("setGPSToolCoordinate needs 4 arguments: slot, x, y, z");
            }
        }
    });
    luaMethods.add(new LuaMethod("getGPSToolCoordinate") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                // minus one, as lua is 1-oriented.
                ItemStack stack = upgradeHandler.getStackInSlot(((Double) args[0]).intValue() - 1);
                if (stack.getItem() == Itemss.GPS_TOOL) {
                    BlockPos pos = ItemGPSTool.getGPSLocation(stack);
                    if (pos != null) {
                        return new Object[] { pos.getX(), pos.getY(), pos.getZ() };
                    } else {
                        return new Object[] { 0, 0, 0 };
                    }
                } else {
                    return null;
                }
            } else {
                throw new IllegalArgumentException("setGPSToolCoordinate needs 1 argument: slot");
            }
        }
    });
}
Also used : IEventSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IEventSensorSetting) IPollSensorSetting(me.desht.pneumaticcraft.api.universalSensor.IPollSensorSetting) ISensorSetting(me.desht.pneumaticcraft.api.universalSensor.ISensorSetting) LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with LuaMethod

use of me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod in project pnc-repressurized by TeamPneumatic.

the class TileEntityPlasticMixer method addLuaMethods.

@Override
protected void addLuaMethods() {
    super.addLuaMethods();
    luaMethods.add(new LuaMethod("selectColor") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                int selection = ((Double) args[0]).intValue();
                if (selection >= 0 && selection <= 16) {
                    selectedPlastic = selection - 1;
                    return null;
                } else {
                    throw new IllegalArgumentException("selectColor method only accepts a value ranging from 0-16. The value passed was: " + selection);
                }
            } else {
                throw new IllegalArgumentException("selectColor method requires 1 argument (int color index, with 0 being no color");
            }
        }
    });
}
Also used : LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod)

Example 4 with LuaMethod

use of me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod in project pnc-repressurized by TeamPneumatic.

the class TileEntityBase method addLuaMethods.

protected void addLuaMethods() {
    if (this instanceof IHeatExchanger) {
        final IHeatExchanger exchanger = (IHeatExchanger) this;
        luaMethods.add(new LuaMethod("getTemperature") {

            @Override
            public Object[] call(Object[] args) throws Exception {
                if (args.length == 0) {
                    return new Object[] { exchanger.getHeatExchangerLogic(null).getTemperature() };
                } else if (args.length == 1) {
                    IHeatExchangerLogic logic = exchanger.getHeatExchangerLogic(getDirForString((String) args[0]));
                    return new Object[] { logic != null ? logic.getTemperature() : 0 };
                } else {
                    throw new IllegalArgumentException("getTemperature method requires 0 or 1 argument (direction: up, down, east, west, north, south!");
                }
            }
        });
    }
}
Also used : IHeatExchanger(me.desht.pneumaticcraft.api.tileentity.IHeatExchanger) LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod) ILuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.ILuaMethod) TextComponentString(net.minecraft.util.text.TextComponentString) LuaException(dan200.computercraft.api.lua.LuaException) IHeatExchangerLogic(me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)

Example 5 with LuaMethod

use of me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod in project pnc-repressurized by TeamPneumatic.

the class TileEntityAirCannon method addLuaMethods.

@Override
protected void addLuaMethods() {
    super.addLuaMethods();
    luaMethods.add(new LuaConstant("getMinWorkingPressure", PneumaticValues.MIN_PRESSURE_AIR_CANNON));
    luaMethods.add(new LuaMethod("setTargetLocation") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            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(Object[] args) throws Exception {
            if (args.length == 0) {
                // returns true if the fire succeeded.
                return new Object[] { fire() };
            } else {
                throw new IllegalArgumentException("fire takes 0 parameters!");
            }
        }
    });
    luaMethods.add(new LuaMethod("isDoneTurning") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { doneTurning };
            } else {
                throw new IllegalArgumentException("isDoneTurning takes 0 parameters!");
            }
        }
    });
    luaMethods.add(new LuaMethod("setRotationAngle") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                setTargetAngles(((Double) args[0]).floatValue(), targetHeightAngle);
                return null;
            } else {
                throw new IllegalArgumentException("setRotationAngle takes 1 parameter! (angle in degrees, 0 = north)");
            }
        }
    });
    luaMethods.add(new LuaMethod("setHeightAngle") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                setTargetAngles(targetRotationAngle, 90 - ((Double) args[0]).floatValue());
                return null;
            } else {
                throw new IllegalArgumentException("setHeightAngle takes 1 parameter! (angle in degrees, 90 = straight up)");
            }
        }
    });
    luaMethods.add(new LuaMethod("setExternalControl") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                externalControl = (Boolean) args[0];
                return null;
            } else {
                throw new IllegalArgumentException("setExternalControl takes 1 parameter! (boolean)");
            }
        }
    });
}
Also used : LuaMethod(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant)

Aggregations

LuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaMethod)6 LuaConstant (me.desht.pneumaticcraft.common.thirdparty.computercraft.LuaConstant)4 LuaException (dan200.computercraft.api.lua.LuaException)1 IHeatExchangerLogic (me.desht.pneumaticcraft.api.heat.IHeatExchangerLogic)1 IAirHandler (me.desht.pneumaticcraft.api.tileentity.IAirHandler)1 IHeatExchanger (me.desht.pneumaticcraft.api.tileentity.IHeatExchanger)1 IEventSensorSetting (me.desht.pneumaticcraft.api.universalSensor.IEventSensorSetting)1 IPollSensorSetting (me.desht.pneumaticcraft.api.universalSensor.IPollSensorSetting)1 ISensorSetting (me.desht.pneumaticcraft.api.universalSensor.ISensorSetting)1 ILuaMethod (me.desht.pneumaticcraft.common.thirdparty.computercraft.ILuaMethod)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentString (net.minecraft.util.text.TextComponentString)1