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;
}
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;
}
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());
}
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());
}
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);
}
Aggregations