Search in sources :

Example 71 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class GuiDialingDevice method hilightSelectedReceiver.

private void hilightSelectedReceiver(int index) {
    TeleportDestination destination = getSelectedReceiver(index);
    if (destination == null) {
        return;
    }
    Coordinate c = destination.getCoordinate();
    double distance = Vec3.createVectorHelper(c.getX(), c.getY(), c.getZ()).distanceTo(mc.thePlayer.getPosition(1.0f));
    if (destination.getDimension() != mc.theWorld.provider.dimensionId || distance > 150) {
        Logging.warn(mc.thePlayer, "Receiver is too far to hilight!");
        mc.getMinecraft().thePlayer.closeScreen();
        return;
    }
    RFTools.instance.clientInfo.hilightBlock(c, System.currentTimeMillis() + 1000 * StorageScannerConfiguration.hilightTime);
    Logging.message(mc.thePlayer, "The receiver is now highlighted");
    mc.getMinecraft().thePlayer.closeScreen();
}
Also used : Coordinate(mcjty.lib.varia.Coordinate)

Example 72 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class TeleportationTools method dial.

// Server side only
public static int dial(World worldObj, DialingDeviceTileEntity dialingDeviceTileEntity, String player, Coordinate transmitter, int transDim, Coordinate coordinate, int dimension, boolean once) {
    World transWorld = RfToolsDimensionManager.getDimensionManager(worldObj).getWorldForDimension(transDim);
    if (transWorld == null) {
        return DialingDeviceTileEntity.DIAL_INVALID_SOURCE_MASK;
    }
    MatterTransmitterTileEntity transmitterTileEntity = (MatterTransmitterTileEntity) transWorld.getTileEntity(transmitter.getX(), transmitter.getY(), transmitter.getZ());
    if (transmitterTileEntity == null) {
        return DialingDeviceTileEntity.DIAL_INVALID_TRANSMITTER;
    }
    if (player != null && !transmitterTileEntity.checkAccess(player)) {
        return DialingDeviceTileEntity.DIAL_TRANSMITTER_NOACCESS;
    }
    if (coordinate == null) {
        transmitterTileEntity.setTeleportDestination(null, false);
        return DialingDeviceTileEntity.DIAL_INTERRUPTED;
    }
    TeleportDestination teleportDestination = findDestination(worldObj, coordinate, dimension);
    if (teleportDestination == null) {
        return DialingDeviceTileEntity.DIAL_INVALID_DESTINATION_MASK;
    }
    Coordinate c = teleportDestination.getCoordinate();
    World recWorld = RfToolsDimensionManager.getWorldForDimension(teleportDestination.getDimension());
    if (recWorld == null) {
        recWorld = MinecraftServer.getServer().worldServerForDimension(teleportDestination.getDimension());
        if (recWorld == null) {
            return DialingDeviceTileEntity.DIAL_INVALID_DESTINATION_MASK;
        }
    }
    // Only do this if not an rftools dimension.
    TileEntity tileEntity = recWorld.getTileEntity(c.getX(), c.getY(), c.getZ());
    if (!(tileEntity instanceof MatterReceiverTileEntity)) {
        return DialingDeviceTileEntity.DIAL_INVALID_DESTINATION_MASK;
    }
    MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) tileEntity;
    // Make sure destination is ok.
    matterReceiverTileEntity.updateDestination();
    if (player != null && !matterReceiverTileEntity.checkAccess(player)) {
        return DialingDeviceTileEntity.DIAL_RECEIVER_NOACCESS;
    }
    if (!checkBeam(transmitter, transWorld, 1, 4, 2)) {
        return DialingDeviceTileEntity.DIAL_TRANSMITTER_BLOCKED_MASK;
    }
    if (dialingDeviceTileEntity != null) {
        int cost = TeleportConfiguration.rfPerDial;
        cost = (int) (cost * (2.0f - dialingDeviceTileEntity.getInfusedFactor()) / 2.0f);
        if (dialingDeviceTileEntity.getEnergyStored(ForgeDirection.DOWN) < cost) {
            return DialingDeviceTileEntity.DIAL_DIALER_POWER_LOW_MASK;
        }
        dialingDeviceTileEntity.consumeEnergy(cost);
    }
    transmitterTileEntity.setTeleportDestination(teleportDestination, once);
    return DialingDeviceTileEntity.DIAL_OK;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Coordinate(mcjty.lib.varia.Coordinate) World(net.minecraft.world.World)

Example 73 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class SimpleDialerTileEntity method checkStateServer.

@Override
protected void checkStateServer() {
    // Update is called manuall which is why canUpdate() returns false.
    super.checkStateServer();
    if (transmitter == null) {
        return;
    }
    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    int newvalue = BlockTools.getRedstoneSignalIn(meta) ? 1 : 0;
    if (newvalue != prevValue) {
        prevValue = newvalue;
        if (newvalue == 1) {
            TeleportDestinations destinations = TeleportDestinations.getDestinations(worldObj);
            Coordinate coordinate = null;
            int dim = 0;
            if (receiver != null) {
                GlobalCoordinate gc = destinations.getCoordinateForId(receiver);
                if (gc != null) {
                    coordinate = gc.getCoordinate();
                    dim = gc.getDimension();
                }
            }
            int dial = TeleportationTools.dial(worldObj, null, null, transmitter.getCoordinate(), transmitter.getDimension(), coordinate, dim, onceMode);
            if (dial != DialingDeviceTileEntity.DIAL_OK) {
            // @todo some way to report error
            }
        }
    }
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 74 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class TeleportDestinations method writeDestinationsToNBT.

private static void writeDestinationsToNBT(NBTTagCompound tagCompound, Collection<TeleportDestination> destinations, Map<GlobalCoordinate, Integer> coordinateToInteger) {
    NBTTagList lst = new NBTTagList();
    for (TeleportDestination destination : destinations) {
        NBTTagCompound tc = new NBTTagCompound();
        Coordinate c = destination.getCoordinate();
        tc.setInteger("x", c.getX());
        tc.setInteger("y", c.getY());
        tc.setInteger("z", c.getZ());
        tc.setInteger("dim", destination.getDimension());
        tc.setString("name", destination.getName());
        if (coordinateToInteger != null) {
            Integer id = coordinateToInteger.get(new GlobalCoordinate(c, destination.getDimension()));
            if (id != null) {
                tc.setInteger("id", id);
            }
        }
        lst.appendTag(tc);
    }
    tagCompound.setTag("destinations", lst);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate)

Example 75 with Coordinate

use of mcjty.lib.varia.Coordinate in project RFTools by McJty.

the class TeleportDestinations method getValidDestinations.

// Server side only
public Collection<TeleportDestinationClientInfo> getValidDestinations(World worldObj, String playerName) {
    PlayerExtendedProperties properties = null;
    if (playerName != null) {
        List list = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
        for (Object player : list) {
            EntityPlayerMP entityplayermp = (EntityPlayerMP) player;
            if (playerName.equals(entityplayermp.getDisplayName())) {
                properties = PlayerExtendedProperties.getProperties(entityplayermp);
                break;
            }
        }
    }
    List<TeleportDestinationClientInfo> result = new ArrayList<TeleportDestinationClientInfo>();
    for (TeleportDestination destination : destinations.values()) {
        TeleportDestinationClientInfo destinationClientInfo = new TeleportDestinationClientInfo(destination);
        Coordinate c = destination.getCoordinate();
        World world = DimensionManager.getWorld(destination.getDimension());
        String dimName = null;
        if (world != null) {
            dimName = DimensionManager.getProvider(destination.getDimension()).getDimensionName();
        }
        DimensionInformation information = RfToolsDimensionManager.getDimensionManager(worldObj).getDimensionInformation(destination.getDimension());
        if (information != null) {
            dimName = information.getName();
        }
        if (dimName == null || dimName.trim().isEmpty()) {
            dimName = "Id " + destination.getDimension();
        } else {
            dimName = dimName + " (" + destination.getDimension() + ")";
        }
        destinationClientInfo.setDimensionName(dimName);
        if (world != null) {
            TileEntity te = world.getTileEntity(c.getX(), c.getY(), c.getZ());
            if (te instanceof MatterReceiverTileEntity) {
                MatterReceiverTileEntity matterReceiverTileEntity = (MatterReceiverTileEntity) te;
                if (playerName != null && !matterReceiverTileEntity.checkAccess(playerName)) {
                    // No access.
                    continue;
                }
            }
        }
        if (properties != null) {
            destinationClientInfo.setFavorite(properties.getFavoriteDestinationsProperties().isDestinationFavorite(new GlobalCoordinate(c, destination.getDimension())));
        }
        result.add(destinationClientInfo);
    }
    Collections.sort(result);
    return result;
}
Also used : GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) PlayerExtendedProperties(mcjty.rftools.playerprops.PlayerExtendedProperties) GlobalCoordinate(mcjty.lib.varia.GlobalCoordinate) Coordinate(mcjty.lib.varia.Coordinate) NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DimensionInformation(mcjty.rftools.dimension.DimensionInformation)

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