use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class DialingDeviceTileEntity method getReceiverName.
@Callback(doc = "For a given receiver (given as a table parameter with indexes 'dim', 'x', 'y', and 'z') return the name of that receiver", getter = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getReceiverName(Context context, Arguments args) throws Exception {
Map receiver = args.checkTable(0);
if (!receiver.containsKey("x") || !receiver.containsKey("y") || !receiver.containsKey("z")) {
throw new IllegalArgumentException("Receiver map doesn't contain the right x,y,z coordinate!");
}
if (!receiver.containsKey("dim")) {
throw new IllegalArgumentException("Receiver map doesn't contain the right dimension!");
}
Coordinate recC = new Coordinate(((Double) receiver.get("x")).intValue(), ((Double) receiver.get("y")).intValue(), ((Double) receiver.get("z")).intValue());
int recDim = ((Double) receiver.get("dim")).intValue();
TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
TeleportDestination destination = destinations.getDestination(recC, recDim);
if (destination == null) {
return null;
}
return new Object[] { destination.getName() };
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class DialingDeviceTileEntity method getDialed.
@Callback(doc = "Return the receiver (in the form of a table 'dim', 'x', 'y', and 'z') where the given transmitter is dialed too. The parameter is a table describing the transmitter ('x', 'y', and 'z')", getter = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getDialed(Context context, Arguments args) throws Exception {
Map transmitter = args.checkTable(0);
if (!transmitter.containsKey("x") || !transmitter.containsKey("y") || !transmitter.containsKey("z")) {
throw new IllegalArgumentException("Transmitter map doesn't contain the right x,y,z coordinate!");
}
Coordinate transC = new Coordinate(((Double) transmitter.get("x")).intValue(), ((Double) transmitter.get("y")).intValue(), ((Double) transmitter.get("z")).intValue());
List<TransmitterInfo> transmitterInfos = searchTransmitters();
for (TransmitterInfo info : transmitterInfos) {
if (info.getCoordinate().equals(transC)) {
TeleportDestination teleportDestination = info.getTeleportDestination();
if (teleportDestination == null) {
return null;
}
Map<String, Integer> coordinate = new HashMap<String, Integer>();
coordinate.put("dim", teleportDestination.getDimension());
Coordinate c = teleportDestination.getCoordinate();
coordinate.put("x", c.getX());
coordinate.put("y", c.getY());
coordinate.put("z", c.getZ());
return new Object[] { coordinate };
}
}
return null;
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class DialingDeviceTileEntity method interrupt.
@Callback(doc = "The parameter is a table describing the transmitter ('x', 'y', and 'z'). This method will interrupt the dialed connection")
@Optional.Method(modid = "OpenComputers")
public Object[] interrupt(Context context, Arguments args) throws Exception {
Map transmitter = args.checkTable(0);
if (!transmitter.containsKey("x") || !transmitter.containsKey("y") || !transmitter.containsKey("z")) {
throw new IllegalArgumentException("Transmitter map doesn't contain the right x,y,z coordinate!");
}
Coordinate transC = new Coordinate(((Double) transmitter.get("x")).intValue(), ((Double) transmitter.get("y")).intValue(), ((Double) transmitter.get("z")).intValue());
int transDim = worldObj.provider.dimensionId;
int result = dial(null, transC, transDim, null, -1, false);
if (result == DIAL_INVALID_DESTINATION_MASK) {
result = 0;
}
return new Object[] { result };
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class DialingDeviceTileEntity method calculateDistance.
/**
* Calculate the distance (in string form) between a transmitter and receiver.
* @param world
* @param transmitterInfo
* @param teleportDestination
* @return the distance or else 'dimension warp' in case it is another dimension.
*/
public static String calculateDistance(World world, TransmitterInfo transmitterInfo, TeleportDestination teleportDestination) {
if (world.provider.dimensionId != teleportDestination.getDimension()) {
return "dimension warp";
} else {
Coordinate c1 = transmitterInfo.getCoordinate();
Coordinate c2 = teleportDestination.getCoordinate();
double dist = Vec3.createVectorHelper(c1.getX(), c1.getY(), c1.getZ()).distanceTo(Vec3.createVectorHelper(c2.getX(), c2.getY(), c2.getZ()));
return Integer.toString((int) dist);
}
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class DialingDeviceTileEntity method dial.
@Callback(doc = "First parameter is a table describing the transmitter ('x', 'y', and 'z'). The second parameter is a table describing the receiver ('dim', 'x', 'y', and 'z'). This method will dial the transmitter to the receiver")
@Optional.Method(modid = "OpenComputers")
public Object[] dial(Context context, Arguments args) throws Exception {
Map transmitter = args.checkTable(0);
Map receiver = args.checkTable(1);
if (!transmitter.containsKey("x") || !transmitter.containsKey("y") || !transmitter.containsKey("z")) {
throw new IllegalArgumentException("Transmitter map doesn't contain the right x,y,z coordinate!");
}
if (!receiver.containsKey("x") || !receiver.containsKey("y") || !receiver.containsKey("z")) {
throw new IllegalArgumentException("Receiver map doesn't contain the right x,y,z coordinate!");
}
if (!receiver.containsKey("dim")) {
throw new IllegalArgumentException("Receiver map doesn't contain the right dimension!");
}
Coordinate transC = new Coordinate(((Double) transmitter.get("x")).intValue(), ((Double) transmitter.get("y")).intValue(), ((Double) transmitter.get("z")).intValue());
int transDim = worldObj.provider.dimensionId;
Coordinate recC = new Coordinate(((Double) receiver.get("x")).intValue(), ((Double) receiver.get("y")).intValue(), ((Double) receiver.get("z")).intValue());
int recDim = ((Double) receiver.get("dim")).intValue();
int result = dial(null, transC, transDim, recC, recDim, false);
return new Object[] { result };
}
Aggregations