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!");
}
}
});
}
}
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");
}
}
});
}
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!");
}
}
});
}
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)");
}
}
});
}
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));
}
Aggregations