Refactored LUA API and updated general consistency
- renamed getters: interfaced -> isInterfaced, position -> getLocalPosition, version -> getVersion - renamed & generalized getters: tier -> getTier, upgrades -> getUpgrades - added getGlobalPosition
This commit is contained in:
parent
f1ac449045
commit
c0da9de4fa
9 changed files with 203 additions and 126 deletions
6
src/main/java/cr0s/warpdrive/api/FunctionGet.java
Normal file
6
src/main/java/cr0s/warpdrive/api/FunctionGet.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package cr0s.warpdrive.api;
|
||||||
|
|
||||||
|
public interface FunctionGet<Return> {
|
||||||
|
|
||||||
|
Return apply();
|
||||||
|
}
|
6
src/main/java/cr0s/warpdrive/api/FunctionSetVector.java
Normal file
6
src/main/java/cr0s/warpdrive/api/FunctionSetVector.java
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
package cr0s.warpdrive.api;
|
||||||
|
|
||||||
|
public interface FunctionSetVector<Component> {
|
||||||
|
|
||||||
|
void apply(Component x, Component y, Component z);
|
||||||
|
}
|
|
@ -2,12 +2,18 @@ package cr0s.warpdrive.api.computer;
|
||||||
|
|
||||||
public interface IInterfaced {
|
public interface IInterfaced {
|
||||||
|
|
||||||
// Declare type
|
// return true if it supports the interface
|
||||||
Object[] interfaced();
|
Object[] isInterfaced();
|
||||||
|
|
||||||
// Return block coordinates
|
// return local block coordinates
|
||||||
Object[] position();
|
Object[] getLocalPosition();
|
||||||
|
|
||||||
// Return version
|
// return tier index and name
|
||||||
Object[] version();
|
Object[] getTier();
|
||||||
|
|
||||||
|
// return upgradability and status
|
||||||
|
Object[] getUpgrades();
|
||||||
|
|
||||||
|
// return the mod version
|
||||||
|
Integer[] getVersion();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package cr0s.warpdrive.block;
|
||||||
|
|
||||||
import cr0s.warpdrive.Commons;
|
import cr0s.warpdrive.Commons;
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
|
import cr0s.warpdrive.api.FunctionGet;
|
||||||
|
import cr0s.warpdrive.api.FunctionSetVector;
|
||||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||||
import cr0s.warpdrive.data.EnumTier;
|
import cr0s.warpdrive.data.Vector3;
|
||||||
import cr0s.warpdrive.data.VectorI;
|
import cr0s.warpdrive.data.VectorI;
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
|
@ -68,9 +70,11 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
super();
|
super();
|
||||||
|
|
||||||
addMethods(new String[] {
|
addMethods(new String[] {
|
||||||
"interfaced",
|
"isInterfaced",
|
||||||
"position",
|
"getLocalPosition",
|
||||||
"version"
|
"getTier",
|
||||||
|
"getUpgrades",
|
||||||
|
"getVersion",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,21 +233,28 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
return methodName;
|
return methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declare type
|
// Common OC/CC methods
|
||||||
@Override
|
@Override
|
||||||
public Object[] interfaced() {
|
public Object[] isInterfaced() {
|
||||||
return new String[] { "I'm a WarpDrive computer interfaced tile entity." };
|
return new Object[] { true, "I'm a WarpDrive computer interfaced tile entity." };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return block coordinates
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] position() {
|
public Object[] getLocalPosition() {
|
||||||
return new Object[] { pos.getX(), pos.getY(), pos.getZ(), "?", pos.getX(), pos.getY(), pos.getZ() };
|
return new Object[] { pos.getX(), pos.getY(), pos.getZ() };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return version
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] version() {
|
public Object[] getTier() {
|
||||||
|
return new Object[] { enumTier.getIndex(), enumTier.getName() };
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getUpgrades() {
|
||||||
|
return new Object[] { isUpgradeable(), getUpgradesAsString() };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer[] getVersion() {
|
||||||
if (WarpDriveConfig.LOGGING_LUA) {
|
if (WarpDriveConfig.LOGGING_LUA) {
|
||||||
WarpDrive.logger.info(String.format("Version is %s isDev %s", WarpDrive.VERSION, WarpDrive.isDev));
|
WarpDrive.logger.info(String.format("Version is %s isDev %s", WarpDrive.VERSION, WarpDrive.isDev));
|
||||||
}
|
}
|
||||||
|
@ -257,7 +268,7 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
for (final String string : strings) {
|
for (final String string : strings) {
|
||||||
integers.add(Integer.parseInt(string));
|
integers.add(Integer.parseInt(string));
|
||||||
}
|
}
|
||||||
return integers.toArray();
|
return integers.toArray(new Integer[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComputerCraft IPeripheral methods
|
// ComputerCraft IPeripheral methods
|
||||||
|
@ -289,6 +300,39 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
return vDefault;
|
return vDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Object[] computer_getOrSetVector3(final FunctionGet<Vector3> getVector, final FunctionSetVector<Float> setVector, final Object[] arguments) {
|
||||||
|
if ( arguments != null
|
||||||
|
&& arguments.length > 0
|
||||||
|
&& arguments[0] != null ) {
|
||||||
|
try {
|
||||||
|
if (arguments.length == 1) {
|
||||||
|
final float value = Commons.toFloat(arguments[0]);
|
||||||
|
setVector.apply(value, value, value);
|
||||||
|
} else if (arguments.length == 2) {
|
||||||
|
final float valueXZ = Commons.toFloat(arguments[0]);
|
||||||
|
final float valueY = Commons.toFloat(arguments[1]);
|
||||||
|
setVector.apply(valueXZ, valueY, valueXZ);
|
||||||
|
} else if (arguments.length == 3) {
|
||||||
|
final float valueX = Commons.toFloat(arguments[0]);
|
||||||
|
final float valueY = Commons.toFloat(arguments[1]);
|
||||||
|
final float valueZ = Commons.toFloat(arguments[2]);
|
||||||
|
setVector.apply(valueX, valueY, valueZ);
|
||||||
|
}
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
final String message = String.format("Float expected for all arguments %s",
|
||||||
|
Arrays.toString(arguments));
|
||||||
|
if (WarpDriveConfig.LOGGING_LUA) {
|
||||||
|
WarpDrive.logger.error(String.format("%s LUA error on %s: %s",
|
||||||
|
this, setVector, message));
|
||||||
|
}
|
||||||
|
final Vector3 v3Actual = getVector.apply();
|
||||||
|
return new Object[] { v3Actual.x, v3Actual.y, v3Actual.z, message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final Vector3 v3Actual = getVector.apply();
|
||||||
|
return new Double[] { v3Actual.x, v3Actual.y, v3Actual.z };
|
||||||
|
}
|
||||||
|
|
||||||
protected UUID computer_getUUID(final UUID uuidDefault, final Object[] arguments) {
|
protected UUID computer_getUUID(final UUID uuidDefault, final Object[] arguments) {
|
||||||
try {
|
try {
|
||||||
if (arguments.length == 1 && arguments[0] != null) {
|
if (arguments.length == 1 && arguments[0] != null) {
|
||||||
|
@ -311,14 +355,20 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
|
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
|
||||||
|
|
||||||
switch (methodName) {
|
switch (methodName) {
|
||||||
case "interfaced":
|
case "isInterfaced":
|
||||||
return interfaced();
|
return isInterfaced();
|
||||||
|
|
||||||
case "position":
|
case "getLocalPosition":
|
||||||
return position();
|
return getLocalPosition();
|
||||||
|
|
||||||
case "version":
|
case "getTier":
|
||||||
return version();
|
return getTier();
|
||||||
|
|
||||||
|
case "getUpgrades":
|
||||||
|
return getUpgrades();
|
||||||
|
|
||||||
|
case "getVersion":
|
||||||
|
return getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -396,20 +446,32 @@ public abstract class TileEntityAbstractInterfaced extends TileEntityAbstractBas
|
||||||
// OpenComputers methods
|
// OpenComputers methods
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] position(final Context context, final Arguments arguments) {
|
public Object[] isInterfaced(final Context context, final Arguments arguments) {
|
||||||
return position();
|
return isInterfaced();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] version(final Context context, final Arguments arguments) {
|
public Object[] getLocalPosition(final Context context, final Arguments arguments) {
|
||||||
return version();
|
return getLocalPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] interfaced(final Context context, final Arguments arguments) {
|
public Object[] getUpgrades(final Context context, final Arguments arguments) {
|
||||||
return interfaced();
|
return getUpgrades();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
@Optional.Method(modid = "opencomputers")
|
||||||
|
public Object[] getTier(final Context context, final Arguments arguments) {
|
||||||
|
return getTier();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Callback
|
||||||
|
@Optional.Method(modid = "opencomputers")
|
||||||
|
public Object[] getVersion(final Context context, final Arguments arguments) {
|
||||||
|
return getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class TileEntityChunkLoader extends TileEntityAbstractChunkLoading {
|
||||||
"enable",
|
"enable",
|
||||||
"bounds",
|
"bounds",
|
||||||
"radius",
|
"radius",
|
||||||
"upgrades",
|
|
||||||
"getEnergyRequired"
|
"getEnergyRequired"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -203,10 +202,6 @@ public class TileEntityChunkLoader extends TileEntityAbstractChunkLoading {
|
||||||
return new Object[] { radiusXneg, radiusXpos, radiusZneg, radiusZpos };
|
return new Object[] { radiusXneg, radiusXpos, radiusZneg, radiusZpos };
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] upgrades() {
|
|
||||||
return new Object[] { getUpgradesAsString() };
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object[] getEnergyRequired() {
|
public Object[] getEnergyRequired() {
|
||||||
return new Object[] { chunkloading_getEnergyRequired() };
|
return new Object[] { chunkloading_getEnergyRequired() };
|
||||||
}
|
}
|
||||||
|
@ -230,12 +225,6 @@ public class TileEntityChunkLoader extends TileEntityAbstractChunkLoading {
|
||||||
return radius(OC_convertArgumentsAndLogCall(context, arguments));
|
return radius(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
|
||||||
@Optional.Method(modid = "opencomputers")
|
|
||||||
public Object[] upgrades(final Context context, final Arguments arguments) {
|
|
||||||
return upgrades();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] getEnergyRequired(final Context context, final Arguments arguments) {
|
public Object[] getEnergyRequired(final Context context, final Arguments arguments) {
|
||||||
|
@ -258,9 +247,6 @@ public class TileEntityChunkLoader extends TileEntityAbstractChunkLoading {
|
||||||
case "enable":
|
case "enable":
|
||||||
return enable(arguments);
|
return enable(arguments);
|
||||||
|
|
||||||
case "upgrades":
|
|
||||||
return upgrades();
|
|
||||||
|
|
||||||
case "getEnergyRequired":
|
case "getEnergyRequired":
|
||||||
return getEnergyRequired();
|
return getEnergyRequired();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class TileEntityRadar extends TileEntityAbstractEnergy {
|
||||||
|
|
||||||
peripheralName = "warpdriveRadar";
|
peripheralName = "warpdriveRadar";
|
||||||
addMethods(new String[] {
|
addMethods(new String[] {
|
||||||
|
"getGlobalPosition",
|
||||||
"radius",
|
"radius",
|
||||||
"getEnergyRequired",
|
"getEnergyRequired",
|
||||||
"start",
|
"start",
|
||||||
|
@ -107,14 +108,14 @@ public class TileEntityRadar extends TileEntityAbstractEnergy {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common OC/CC methods
|
// Common OC/CC methods
|
||||||
@Override
|
public Object[] getGlobalPosition() {
|
||||||
public Object[] position() {
|
|
||||||
final CelestialObject celestialObject = CelestialObjectManager.get(world, pos.getX(), pos.getZ());
|
final CelestialObject celestialObject = CelestialObjectManager.get(world, pos.getX(), pos.getZ());
|
||||||
if (celestialObject != null) {
|
if (celestialObject != null) {
|
||||||
|
final String galaxyName = StarMapRegistry.getGalaxyName(celestialObject, pos.getX(), pos.getY(), pos.getZ());
|
||||||
final Vector3 vec3Position = StarMapRegistry.getUniversalCoordinates(celestialObject, pos.getX(), pos.getY(), pos.getZ());
|
final Vector3 vec3Position = StarMapRegistry.getUniversalCoordinates(celestialObject, pos.getX(), pos.getY(), pos.getZ());
|
||||||
return new Object[] { pos.getX(), pos.getY(), pos.getZ(), celestialObject.getDisplayName(), vec3Position.x, vec3Position.y, vec3Position.z };
|
return new Object[] { galaxyName, celestialObject.getDisplayName(), vec3Position.x, vec3Position.y, vec3Position.z };
|
||||||
} else {
|
} else {
|
||||||
return new Object[] { pos.getX(), pos.getY(), pos.getZ(), Commons.format(world), pos.getX(), pos.getY(), pos.getZ() };
|
return new Object[] { StarMapRegistry.GALAXY_UNDEFINED, Commons.format(world), pos.getX(), pos.getY(), pos.getZ() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,14 +228,14 @@ public class TileEntityRadar extends TileEntityAbstractEnergy {
|
||||||
// OpenComputer callback methods
|
// OpenComputer callback methods
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] radius(final Context context, final Arguments arguments) {
|
public Object[] getGlobalPosition(final Context context, final Arguments arguments) {
|
||||||
return radius(OC_convertArgumentsAndLogCall(context, arguments));
|
return getGlobalPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] getEnergyRequired(final Context context, final Arguments arguments) {
|
public Object[] radius(final Context context, final Arguments arguments) {
|
||||||
return getEnergyRequired(OC_convertArgumentsAndLogCall(context, arguments));
|
return radius(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
|
@ -292,6 +293,9 @@ public class TileEntityRadar extends TileEntityAbstractEnergy {
|
||||||
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
|
final String methodName = CC_getMethodNameAndLogCall(method, arguments);
|
||||||
|
|
||||||
switch (methodName) {
|
switch (methodName) {
|
||||||
|
case "getGlobalPosition":
|
||||||
|
return getGlobalPosition();
|
||||||
|
|
||||||
case "radius":
|
case "radius":
|
||||||
return radius(arguments);
|
return radius(arguments);
|
||||||
|
|
||||||
|
|
|
@ -1175,6 +1175,61 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
return bResult;
|
return bResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Common OC/CC methods
|
||||||
|
@Override
|
||||||
|
public Object[] getEnergyRequired() {
|
||||||
|
return new Object[0]; // @TODO getEnergyRequired for projector
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object[] state() { // isConnected, isPowered, shape
|
||||||
|
final int energy = energy_getEnergyStored();
|
||||||
|
final String status = getStatusHeaderInPureText();
|
||||||
|
return new Object[] { status, isEnabled, isConnected, isPowered, getShape().name(), energy };
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] min(final Object[] arguments) {
|
||||||
|
return computer_getOrSetVector3(this::getMin, this::setMin, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] max(final Object[] arguments) {
|
||||||
|
return computer_getOrSetVector3(this::getMax, this::setMax, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] rotation(final Object[] arguments) {
|
||||||
|
if ( arguments != null
|
||||||
|
&& arguments.length > 0
|
||||||
|
&& arguments[0] != null ) {
|
||||||
|
try {
|
||||||
|
if (arguments.length == 1) {
|
||||||
|
final float value = Commons.toFloat(arguments[0]);
|
||||||
|
setRotation(value, 0, 0);
|
||||||
|
} else if (arguments.length == 2) {
|
||||||
|
final float value1 = Commons.toFloat(arguments[0]);
|
||||||
|
final float value2 = Commons.toFloat(arguments[1]);
|
||||||
|
setRotation(value1, value2, 0);
|
||||||
|
} else if (arguments.length == 3) {
|
||||||
|
final float value1 = Commons.toFloat(arguments[0]);
|
||||||
|
final float value2 = Commons.toFloat(arguments[1]);
|
||||||
|
final float value3 = Commons.toFloat(arguments[2]);
|
||||||
|
setRotation(value1, value2, value3);
|
||||||
|
}
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
final String message = String.format("Float expected for all arguments %s",
|
||||||
|
Arrays.toString(arguments));
|
||||||
|
if (WarpDriveConfig.LOGGING_LUA) {
|
||||||
|
WarpDrive.logger.error(String.format("%s LUA error on rotation(): %s",
|
||||||
|
this, message));
|
||||||
|
}
|
||||||
|
return new Object[] { rotationYaw, rotationPitch, rotationRoll, message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Float[] { rotationYaw, rotationPitch, rotationRoll };
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] translation(final Object[] arguments) {
|
||||||
|
return computer_getOrSetVector3(this::getTranslation, this::setTranslation, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
// OpenComputer callback methods
|
// OpenComputer callback methods
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
|
@ -1185,60 +1240,25 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] min(final Context context, final Arguments arguments) {
|
public Object[] min(final Context context, final Arguments arguments) {
|
||||||
if (arguments.count() == 1) {
|
return min(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
setMin((float)arguments.checkDouble(0), (float)arguments.checkDouble(0), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 2) {
|
|
||||||
setMin((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 3) {
|
|
||||||
setMin((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(2));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Min.x, v3Min.y, v3Min.z };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] max(final Context context, final Arguments arguments) {
|
public Object[] max(final Context context, final Arguments arguments) {
|
||||||
if (arguments.count() == 1) {
|
return max(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
setMax((float)arguments.checkDouble(0), (float)arguments.checkDouble(0), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 2) {
|
|
||||||
setMax((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 3) {
|
|
||||||
setMax((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(2));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Max.x, v3Max.y, v3Max.z };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] rotation(final Context context, final Arguments arguments) {
|
public Object[] rotation(final Context context, final Arguments arguments) {
|
||||||
if (arguments.count() == 1) {
|
return rotation(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
setRotation((float)arguments.checkDouble(0), rotationPitch, rotationRoll);
|
|
||||||
} else if (arguments.count() == 2) {
|
|
||||||
setRotation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), rotationRoll);
|
|
||||||
} else if (arguments.count() == 3) {
|
|
||||||
setRotation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(2));
|
|
||||||
}
|
|
||||||
return new Float[] { rotationYaw, rotationPitch, rotationRoll };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common OC/CC methods
|
|
||||||
private Object[] state() { // isConnected, isPowered, shape
|
|
||||||
final int energy = energy_getEnergyStored();
|
|
||||||
final String status = getStatusHeaderInPureText();
|
|
||||||
return new Object[] { status, isEnabled, isConnected, isPowered, getShape().name(), energy };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Callback
|
@Callback
|
||||||
@Optional.Method(modid = "opencomputers")
|
@Optional.Method(modid = "opencomputers")
|
||||||
public Object[] translation(final Context context, final Arguments arguments) {
|
public Object[] translation(final Context context, final Arguments arguments) {
|
||||||
if (arguments.count() == 1) {
|
return translation(OC_convertArgumentsAndLogCall(context, arguments));
|
||||||
setTranslation((float)arguments.checkDouble(0), (float)arguments.checkDouble(0), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 2) {
|
|
||||||
setTranslation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(0));
|
|
||||||
} else if (arguments.count() == 3) {
|
|
||||||
setTranslation((float)arguments.checkDouble(0), (float)arguments.checkDouble(1), (float)arguments.checkDouble(2));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Translation.x, v3Translation.y, v3Translation.z };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComputerCraft IPeripheral methods implementation
|
// ComputerCraft IPeripheral methods implementation
|
||||||
|
@ -1249,47 +1269,19 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
||||||
|
|
||||||
switch (methodName) {
|
switch (methodName) {
|
||||||
case "min":
|
case "min":
|
||||||
if (arguments.length == 1 && arguments[0] != null) {
|
return min(arguments);
|
||||||
setMin(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 2) {
|
|
||||||
setMin(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 3) {
|
|
||||||
setMin(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[2]));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Min.x, v3Min.y, v3Min.z };
|
|
||||||
|
|
||||||
case "max":
|
case "max":
|
||||||
if (arguments.length == 1 && arguments[0] != null) {
|
return max(arguments);
|
||||||
setMax(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 2) {
|
|
||||||
setMax(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 3) {
|
|
||||||
setMax(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[2]));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Max.x, v3Max.y, v3Max.z };
|
|
||||||
|
|
||||||
case "rotation":
|
case "rotation":
|
||||||
if (arguments.length == 1 && arguments[0] != null) {
|
return rotation(arguments);
|
||||||
setRotation(Commons.toFloat(arguments[0]), rotationPitch, rotationRoll);
|
|
||||||
} else if (arguments.length == 2) {
|
|
||||||
setRotation(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), rotationRoll);
|
|
||||||
} else if (arguments.length == 3) {
|
|
||||||
setRotation(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[2]));
|
|
||||||
}
|
|
||||||
return new Float[] { rotationYaw, rotationPitch, rotationRoll };
|
|
||||||
|
|
||||||
case "state":
|
case "state":
|
||||||
return state();
|
return state();
|
||||||
|
|
||||||
case "translation":
|
case "translation":
|
||||||
if (arguments.length == 1 && arguments[0] != null) {
|
return translation(arguments);
|
||||||
setTranslation(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 2) {
|
|
||||||
setTranslation(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[0]));
|
|
||||||
} else if (arguments.length == 3) {
|
|
||||||
setTranslation(Commons.toFloat(arguments[0]), Commons.toFloat(arguments[1]), Commons.toFloat(arguments[2]));
|
|
||||||
}
|
|
||||||
return new Double[] { v3Translation.x, v3Translation.y, v3Translation.z };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.callMethod(computer, context, method, arguments);
|
return super.callMethod(computer, context, method, arguments);
|
||||||
|
|
|
@ -145,12 +145,12 @@ public class TileEntityShipController extends TileEntityAbstractShipController {
|
||||||
|
|
||||||
// Common OC/CC methods
|
// Common OC/CC methods
|
||||||
@Override
|
@Override
|
||||||
public Object[] position() {
|
public Object[] getLocalPosition() {
|
||||||
final TileEntityShipCore tileEntityShipCore = tileEntityShipCoreWeakReference == null ? null : tileEntityShipCoreWeakReference.get();
|
final TileEntityShipCore tileEntityShipCore = tileEntityShipCoreWeakReference == null ? null : tileEntityShipCoreWeakReference.get();
|
||||||
if (tileEntityShipCore == null) {
|
if (tileEntityShipCore == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return tileEntityShipCore.position();
|
return tileEntityShipCore.getLocalPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -383,6 +383,21 @@ public class StarMapRegistry {
|
||||||
return arrayListRadarEchos;
|
return arrayListRadarEchos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String GALAXY_UNDEFINED = "???";
|
||||||
|
public static String getGalaxyName(final CelestialObject celestialObject, final double x, final double y, final double z) {
|
||||||
|
if (celestialObject == null) {
|
||||||
|
// not a registered area
|
||||||
|
return GALAXY_UNDEFINED;
|
||||||
|
}
|
||||||
|
CelestialObject celestialObjectNode = celestialObject;
|
||||||
|
boolean hasHyperspace = celestialObjectNode.isHyperspace();
|
||||||
|
while (celestialObjectNode.parent != null) {
|
||||||
|
celestialObjectNode = celestialObjectNode.parent;
|
||||||
|
hasHyperspace |= celestialObjectNode.isHyperspace();
|
||||||
|
}
|
||||||
|
return hasHyperspace ? celestialObjectNode.getDisplayName() : GALAXY_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector3 getUniversalCoordinates(final CelestialObject celestialObject, final double x, final double y, final double z) {
|
public static Vector3 getUniversalCoordinates(final CelestialObject celestialObject, final double x, final double y, final double z) {
|
||||||
if (celestialObject == null) {
|
if (celestialObject == null) {
|
||||||
// not a registered area
|
// not a registered area
|
||||||
|
|
Loading…
Add table
Reference in a new issue