Search in sources :

Example 1 with LuaMethod

use of pneumaticCraft.common.thirdparty.computercraft.LuaMethod in project PneumaticCraft by MineMaarten.

the class TileEntityBase method addLuaMethods.

/*
     * COMPUTERCRAFT API 
     */
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(ForgeDirection.UNKNOWN).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(pneumaticCraft.api.tileentity.IHeatExchanger) ILuaMethod(pneumaticCraft.common.thirdparty.computercraft.ILuaMethod) LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaException(dan200.computercraft.api.lua.LuaException) IHeatExchangerLogic(pneumaticCraft.api.IHeatExchangerLogic)

Example 2 with LuaMethod

use of pneumaticCraft.common.thirdparty.computercraft.LuaMethod in project PneumaticCraft by MineMaarten.

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(pneumaticCraft.common.thirdparty.computercraft.LuaMethod)

Example 3 with LuaMethod

use of pneumaticCraft.common.thirdparty.computercraft.LuaMethod in project PneumaticCraft by MineMaarten.

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 doesn't take any arguments!");
            }
        }
    });
    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 doesn't take any arguments!");
            }
        }
    });
    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 does take one argument!");
            }
        }
    });
    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 does take one argument!");
            }
        }
    });
    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 does take one argument!");
            }
        }
    });
}
Also used : LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(pneumaticCraft.common.thirdparty.computercraft.LuaConstant)

Example 4 with LuaMethod

use of pneumaticCraft.common.thirdparty.computercraft.LuaMethod in project PneumaticCraft by MineMaarten.

the class TileEntityElevatorBase method addLuaMethods.

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

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                setTargetHeight(((Double) args[0]).floatValue());
                if (getCoreElevator().isControlledByRedstone())
                    getCoreElevator().handleGUIButtonPress(0, null);
                getCoreElevator().sendDescPacketFromAllElevators();
                return null;
            } else {
                throw new IllegalArgumentException("setHeight does take one argument (height)");
            }
        }
    });
    luaMethods.add(new LuaMethod("setExternalControl") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 1) {
                if ((Boolean) args[0] && getCoreElevator().isControlledByRedstone() || !(Boolean) args[0] && !getCoreElevator().isControlledByRedstone()) {
                    getCoreElevator().handleGUIButtonPress(0, null);
                }
                return null;
            } else {
                throw new IllegalArgumentException("setExternalControl does take one argument! (bool)");
            }
        }
    });
}
Also used : LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(pneumaticCraft.common.thirdparty.computercraft.LuaConstant)

Example 5 with LuaMethod

use of pneumaticCraft.common.thirdparty.computercraft.LuaMethod in project PneumaticCraft by MineMaarten.

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[] { getPressure(ForgeDirection.UNKNOWN) };
            } else if (args.length == 1) {
                return new Object[] { getPressure(getDirForString((String) args[0])) };
            } else {
                throw new IllegalArgumentException("getPressure method requires 0 or 1 argument (direction: up, down, east, west, north, south!");
            }
        }
    });
    luaMethods.add(new LuaConstant("getDangerPressure", DANGER_PRESSURE));
    luaMethods.add(new LuaConstant("getCriticalPressure", CRITICAL_PRESSURE));
    luaMethods.add(new LuaConstant("getDefaultVolume", DEFAULT_VOLUME));
}
Also used : LuaMethod(pneumaticCraft.common.thirdparty.computercraft.LuaMethod) LuaConstant(pneumaticCraft.common.thirdparty.computercraft.LuaConstant)

Aggregations

LuaMethod (pneumaticCraft.common.thirdparty.computercraft.LuaMethod)6 LuaConstant (pneumaticCraft.common.thirdparty.computercraft.LuaConstant)4 LuaException (dan200.computercraft.api.lua.LuaException)1 ItemStack (net.minecraft.item.ItemStack)1 ChunkPosition (net.minecraft.world.ChunkPosition)1 IHeatExchangerLogic (pneumaticCraft.api.IHeatExchangerLogic)1 IHeatExchanger (pneumaticCraft.api.tileentity.IHeatExchanger)1 IEventSensorSetting (pneumaticCraft.api.universalSensor.IEventSensorSetting)1 IPollSensorSetting (pneumaticCraft.api.universalSensor.IPollSensorSetting)1 ISensorSetting (pneumaticCraft.api.universalSensor.ISensorSetting)1 ILuaMethod (pneumaticCraft.common.thirdparty.computercraft.ILuaMethod)1