Search in sources :

Example 76 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_10_R1 method mapTrace.

@Override
public MapTraceResult mapTrace(LivingEntity from, double range) {
    Location start = from.getEyeLocation();
    Vector startVec = start.toVector();
    double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
    double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180));
    double ny = Math.sin(start.getPitch() * (Math.PI / 180));
    double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180));
    Vector endVec = startVec.clone().add(new Vector(nx, -ny, nz).multiply(range));
    MovingObjectPosition l = rayTrace(start.getWorld(), startVec, endVec);
    if (l == null || l.pos == null) {
        return null;
    }
    Vector finalVec = new Vector(l.pos.x, l.pos.y, l.pos.z);
    MapTraceResult mtr = new MapTraceResult();
    switch(l.direction) {
        case NORTH:
            mtr.angle = BlockFace.NORTH;
            break;
        case SOUTH:
            mtr.angle = BlockFace.SOUTH;
            break;
        case EAST:
            mtr.angle = BlockFace.EAST;
            break;
        case WEST:
            mtr.angle = BlockFace.WEST;
            break;
    }
    // wallPosition - ((end - start).normalize() * 0.072)
    Vector hit = finalVec.clone().subtract((endVec.clone().subtract(startVec)).normalize().multiply(0.072));
    mtr.hitLocation = new Location(start.getWorld(), hit.getX(), hit.getY(), hit.getZ());
    return mtr;
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 77 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_10_R1 method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.server.v1_10_R1.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
    final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
    UUID uuid = follower.getUniqueId();
    if (followTasks.containsKey(uuid)) {
        followTasks.get(uuid).cancel();
    }
    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;
    followTasks.put(follower.getUniqueId(), new BukkitRunnable() {

        private boolean inRadius = false;

        public void run() {
            if (!target.isValid() || !follower.isValid()) {
                this.cancel();
            }
            followerNavigation.a(2F);
            Location targetLocation = target.getLocation();
            PathEntity path;
            if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
                if (!inRadius) {
                    follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                } else {
                    inRadius = false;
                    path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                    if (path != null) {
                        followerNavigation.a(path, 1D);
                        followerNavigation.a(2D);
                    }
                }
            } else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
                path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                if (path != null) {
                    followerNavigation.a(path, 1D);
                    followerNavigation.a(2D);
                }
            } else {
                inRadius = true;
            }
            if (inRadius && !allowWander) {
                followerNavigation.o();
            }
            nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) net.minecraft.server.v1_10_R1(net.minecraft.server.v1_10_R1) CompoundTag_v1_10_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 78 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_10_R1 method rotate.

@Override
public void rotate(Entity entity, float yaw, float pitch) {
    // it will appear to be online
    if (entity instanceof Player && ((Player) entity).isOnline()) {
        Location location = entity.getLocation();
        location.setYaw(yaw);
        location.setPitch(pitch);
        entity.teleport(location);
    } else if (entity instanceof LivingEntity) {
        if (entity instanceof EnderDragon) {
            yaw = normalizeYaw(yaw - 180);
        }
        look(entity, yaw, pitch);
    } else {
        net.minecraft.server.v1_10_R1.Entity handle = ((CraftEntity) entity).getHandle();
        handle.yaw = yaw;
        handle.pitch = pitch;
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity) Entity(org.bukkit.entity.Entity) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) Location(org.bukkit.Location)

Example 79 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class Utilities method getWalkableLocationNear.

/**
     * Gets a Location within a range that an entity can walk in.
     *
     * @param location the Location to check with
     * @param range    the range around the Location
     * @return a random Location within range, or null if no Location within range is safe
     */
public static Location getWalkableLocationNear(Location location, int range) {
    List<Location> locations = new ArrayList<Location>();
    location = location.getBlock().getLocation();
    // Loop through each location within the range
    for (double x = -(range); x <= range; x++) {
        for (double y = -(range); y <= range; y++) {
            for (double z = -(range); z <= range; z++) {
                // Add each block location within range
                Location loc = location.clone().add(x, y, z);
                if (checkLocation(location, loc, range) && isWalkable(loc)) {
                    locations.add(loc);
                }
            }
        }
    }
    // No safe Locations found
    if (locations.isEmpty()) {
        return null;
    }
    // Return a random Location from the list
    return locations.get(random.nextInt(locations.size()));
}
Also used : ArrayList(java.util.ArrayList) Location(org.bukkit.Location)

Example 80 with Location

use of org.bukkit.Location in project Denizen-For-Bukkit by DenizenScript.

the class CuboidEnterExitSmartEvent method onWorldChange.

public void onWorldChange(PlayerChangedWorldEvent event) {
    if (dEntity.isNPC(event.getPlayer())) {
        return;
    }
    Location to = event.getPlayer().getLocation().clone();
    Location from = event.getPlayer().getLocation().clone();
    from.setWorld(event.getFrom());
    PlayerMoveEvent evt = new PlayerMoveEvent(event.getPlayer(), from, to);
    internalRun(evt, "world_change");
}
Also used : Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 Island (com.wasteofplastic.acidisland.Island)12