Search in sources :

Example 81 with Location

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

the class EntityHelper_v1_9_R2 method rayTrace.

@Override
public Location rayTrace(Location start, Vector direction, double range) {
    Vector startVec = start.toVector();
    MovingObjectPosition l = rayTrace(start.getWorld(), startVec, startVec.clone().add(direction.multiply(range)));
    if (l != null && l.pos != null) {
        return new Location(start.getWorld(), l.pos.x, l.pos.y, l.pos.z);
    }
    return null;
}
Also used : Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 82 with Location

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

the class EntityHelper_v1_9_R2 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 83 with Location

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

the class FishingTrait method reel.

// <--[action]
// @Actions
// reel in fishing rod
//
// @Triggers when the NPC reels in its fishing rod.
//
// @Context
// None
//
// -->
private void reel() {
    DenizenAPI.getDenizenNPC(npc).action("reel in fishing rod", null);
    int chance = (int) (Math.random() * 100);
    try {
        fishHook.remove();
    } catch (Exception e) {
    }
    if (catchPercent > chance && fishHook != null && catchType != FishingHelper.CatchType.NONE) {
        try {
            fish.remove();
        } catch (Exception e) {
        }
        Location location = fishHook.getLocation();
        ItemStack result = NMSHandler.getInstance().getFishingHelper().getResult(fishHook, catchType);
        if (result != null) {
            fish = location.getWorld().dropItem(location, result);
            Location npcLocation = npc.getEntity().getLocation();
            double d5 = npcLocation.getX() - location.getX();
            double d6 = npcLocation.getY() - location.getY();
            double d7 = npcLocation.getZ() - location.getZ();
            double d8 = Math.sqrt(d5 * d5 + d6 * d6 + d7 * d7);
            double d9 = 0.1D;
            fish.setVelocity(new Vector(d5 * d9, d6 * d9 + Math.sqrt(d8) * 0.08D, d7 * d9));
        }
        DenizenAPI.getDenizenNPC(npc).action("catch fish", null);
    }
    PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 84 with Location

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

the class FishingTrait method cast.

// <--[action]
// @Actions
// cast fishing rod
//
// @Triggers when the NPC casts a fishing rod.
//
// @Context
// None
//
// -->
private void cast() {
    DenizenAPI.getDenizenNPC(npc).action("cast fishing rod", null);
    if (fishingLocation == null) {
        dB.echoError("Fishing location not found!");
        return;
    }
    double v = 34;
    double g = 20;
    Location from = npc.getEntity().getLocation();
    from = from.add(0, .33, 0);
    Location to = fishingLocation;
    Vector test = to.clone().subtract(from).toVector();
    Double elev = test.getY();
    Double testAngle = launchAngle(from, to, v, elev, g);
    if (testAngle == null) {
        return;
    }
    Double hangtime = hangtime(testAngle, v, elev, g);
    Vector victor = to.clone().subtract(from).toVector();
    Double dist = Math.sqrt(Math.pow(victor.getX(), 2) + Math.pow(victor.getZ(), 2));
    elev = victor.getY();
    if (dist == 0) {
        return;
    }
    Double launchAngle = launchAngle(from, to, v, elev, g);
    if (launchAngle == null) {
        return;
    }
    victor.setY(Math.tan(launchAngle) * dist);
    victor = normalizeVector(victor);
    v = v + (.5 * Math.pow(hangtime, 2));
    //Random rand = new Random(1234);
    v = v + (CoreUtilities.getRandom().nextDouble() - .8) / 2;
    victor = victor.multiply(v / 20.0);
    fishHook = NMSHandler.getInstance().getFishingHelper().spawnHook(from, (Player) npc.getEntity());
    fishHook.setShooter((ProjectileSource) npc.getEntity());
    fishHook.setVelocity(victor);
    PlayerAnimation.ARM_SWING.play((Player) npc.getEntity());
}
Also used : Player(org.bukkit.entity.Player) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 85 with Location

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

the class HealthTrait method onSpawn.

/**
     * Listens for spawn of an NPC and updates its health with the max health
     * information for this trait.
     */
@Override
public void onSpawn() {
    dying = false;
    setHealth();
    void_watcher_task = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {

        @Override
        public void run() {
            if (!npc.isSpawned()) {
                Bukkit.getScheduler().cancelTask(void_watcher_task);
                return;
            }
            if (npc.getEntity().getLocation().getY() < -1000) {
                npc.despawn(DespawnReason.DEATH);
                if (respawn) {
                    Location res = getRespawnLocation();
                    if (res.getY() < 1) {
                        res.setY(res.getWorld().getHighestBlockYAt(res.getBlockX(), res.getBlockZ()));
                    }
                    if (npc.isSpawned()) {
                        npc.getEntity().teleport(res);
                    } else {
                        npc.spawn(res);
                    }
                }
            }
        }
    }, 200, 200);
}
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