Search in sources :

Example 61 with Coordinate

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() };
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Example 62 with Coordinate

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;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Example 63 with Coordinate

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 };
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Example 64 with Coordinate

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);
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate)

Example 65 with Coordinate

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 };
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) HashMap(java.util.HashMap) Map(java.util.Map) Callback(li.cil.oc.api.machine.Callback)

Aggregations

Coordinate (mcjty.lib.varia.Coordinate)181 GlobalCoordinate (mcjty.lib.varia.GlobalCoordinate)63 TileEntity (net.minecraft.tileentity.TileEntity)30 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)19 Block (net.minecraft.block.Block)14 HashMap (java.util.HashMap)13 Map (java.util.Map)13 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)13 World (net.minecraft.world.World)12 NBTTagList (net.minecraft.nbt.NBTTagList)11 Callback (li.cil.oc.api.machine.Callback)10 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)10 Panel (mcjty.lib.gui.widgets.Panel)10 ItemStack (net.minecraft.item.ItemStack)10 ArrayList (java.util.ArrayList)9 Label (mcjty.lib.gui.widgets.Label)8 BlockInfo (mcjty.rftools.BlockInfo)7 SyncedCoordinate (mcjty.lib.entity.SyncedCoordinate)5 ChoiceEvent (mcjty.lib.gui.events.ChoiceEvent)4 TeleportDestinationClientInfo (mcjty.rftools.blocks.teleporter.TeleportDestinationClientInfo)4