Search in sources :

Example 6 with LuaMethod

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

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("getCurrentHeight") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { getCoreElevator().extension };
            } else {
                throw new IllegalArgumentException("getCurrentHeight method takes no arguments!");
            }
        }
    });
    luaMethods.add(new LuaMethod("getTargetHeight") {

        @Override
        public Object[] call(Object[] args) throws Exception {
            if (args.length == 0) {
                return new Object[] { getCoreElevator().targetExtension };
            } else {
                throw new IllegalArgumentException("getTargetHeight method takes no arguments!");
            }
        }
    });
    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(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