Search in sources :

Example 6 with TileEntityTelemetry

use of micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry in project Galacticraft by micdoodle8.

the class TileEntityTelemetry method getNearest.

public static TileEntityTelemetry getNearest(TileEntity te) {
    if (te == null) {
        return null;
    }
    BlockVec3 target = new BlockVec3(te);
    int distSq = 1025;
    BlockVec3Dim nearest = null;
    int dim = GCCoreUtil.getDimensionID(te.getWorld());
    for (BlockVec3Dim telemeter : loadedList) {
        if (telemeter.dim != dim) {
            continue;
        }
        int dist = telemeter.distanceSquared(target);
        if (dist < distSq) {
            distSq = dist;
            nearest = telemeter;
        }
    }
    if (nearest == null) {
        return null;
    }
    TileEntity result = te.getWorld().getTileEntity(new BlockPos(nearest.x, nearest.y, nearest.z));
    if (result instanceof TileEntityTelemetry) {
        return (TileEntityTelemetry) result;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.BlockPos) BlockVec3Dim(micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

TileEntityTelemetry (micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry)4 Entity (net.minecraft.entity.Entity)4 TileEntity (net.minecraft.tileentity.TileEntity)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)2 BlockVec3Dim (micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)2 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)2 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 ITelemetry (micdoodle8.mods.galacticraft.api.entity.ITelemetry)1 IWorldTransferCallback (micdoodle8.mods.galacticraft.api.entity.IWorldTransferCallback)1 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)1