Java Code Examples for org.bukkit.Location#setDirection()
The following examples show how to use
org.bukkit.Location#setDirection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpawnModuleBuilder.java From CardinalPGM with MIT License | 6 votes |
private List<Pair<RegionModule, Vector>> getRegions(Element element){ List<Pair<RegionModule, Vector>> regions = new ArrayList<>(); for (Element region : element.getChildren()) { RegionModule current = RegionModuleBuilder.getRegion(region); Location location = new Location(GameHandler.getGameHandler().getMatchWorld(), 0, 0, 0); if (region.getParentElement().getParentElement().getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getParentElement().getParentElement().getAttributeValue("yaw"))); if (region.getParentElement().getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getParentElement().getAttributeValue("yaw"))); if (region.getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getAttributeValue("yaw"))); if (region.getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getAttributeValue("yaw"))); if (region.getParentElement().getParentElement().getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getParentElement().getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); if (region.getParentElement().getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); if (region.getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); regions.add(new ImmutablePair<>(current, location.getDirection())); } return regions; }
Example 2
Source File: SentinelUtilities.java From Sentinel with MIT License | 5 votes |
/** * Gets a 'launch detail' (starting location with direction vector set to correct firing direction, and a vector holding the exact launch vector, scaled to the correct speed). */ public static HashMap.SimpleEntry<Location, Vector> getLaunchDetail(Location start, Location target, Vector lead) { double speeda; double angt = Double.POSITIVE_INFINITY; double sbase = SentinelPlugin.instance.minShootSpeed; for (speeda = sbase; speeda <= sbase + 15; speeda += 5) { // TODO: Mathematically calculate a valid starting speed, to avoid pointlessly looping on a math utility. angt = SentinelUtilities.getArrowAngle(start, target, speeda, 20); if (!Double.isInfinite(angt)) { break; } } if (Double.isInfinite(angt)) { return null; } double hangT = SentinelUtilities.hangtime(angt, speeda, target.getY() - start.getY(), 20); Location to = target.clone().add(lead.clone().multiply(hangT)); Vector relative = to.clone().subtract(start.toVector()).toVector(); double deltaXZ = Math.sqrt(relative.getX() * relative.getX() + relative.getZ() * relative.getZ()); if (deltaXZ == 0) { deltaXZ = 0.1; } for (speeda = sbase; speeda <= sbase + 15; speeda += 5) { angt = SentinelUtilities.getArrowAngle(start, to, speeda, 20); if (!Double.isInfinite(angt)) { break; } } if (Double.isInfinite(angt)) { return null; } relative.setY(Math.tan(angt) * deltaXZ); relative = relative.normalize(); Vector normrel = relative.clone(); speeda = speeda + (1.188 * hangT * hangT); relative = relative.multiply(speeda / 20.0); start.setDirection(normrel); return new HashMap.SimpleEntry<>(start, relative); }
Example 3
Source File: Effect.java From EffectLib with MIT License | 5 votes |
protected final boolean validate() { // Check if the origin and target entities are present if (disappearWithOriginEntity && (origin != null && !origin.hasValidEntity())) { return false; } if (disappearWithTargetEntity && (target != null && !target.hasValidEntity())) { return false; } // Check for a valid Location updateLocation(); updateTarget(); Location location = getLocation(); if (location == null) { return false; } if (autoOrient) { Location targetLocation = target == null ? null : target.getLocation(); if (targetLocation != null) { Vector direction = targetLocation.toVector().subtract(location.toVector()); location.setDirection(direction); targetLocation.setDirection(direction.multiply(-1)); } } return true; }
Example 4
Source File: Gunnergoal.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
@Override public void run(GoalSelector goal) { if (target == null) { if (searchCooldown <= 0) { if (npc.isSpawned()) { double closestDis = cuttoffDistance; for (Entity e : npc.getEntity().getNearbyEntities(cuttoffDistance, cuttoffDistance, cuttoffDistance)) { if (e instanceof LivingEntity) { if (!CitizensAPI.getNPCRegistry().isNPC(e)) { double k = e.getLocation().distanceSquared(npc.getEntity().getLocation()); if (target == null || closestDis > k) { if (inLineOfSight(e, false)) { target = e; closestDis = k; } } } } } } searchCooldown = searchCooldownMax; } else { searchCooldown--; } } else { if (target.isDead() || target.getLocation().distanceSquared(npc.getEntity().getLocation()) >= cuttoffDistance) { target = null; } else { // Util.faceEntity(npc.getEntity(), target); Location tempc = npc.getEntity().getLocation(); tempc.setDirection(new Vector(target.getLocation().getX() - tempc.getX(), target.getLocation().getY() - tempc.getY(), target.getLocation().getZ() - tempc.getZ())); npc.teleport(tempc, TeleportCause.PLUGIN); npc.faceLocation(target.getLocation()); if (shootcooldown > 0) { shootcooldown--; return; } else if (reloadcooldown > 0) { reloadcooldown--; internalAmmoCount = g.getMaxBullets(); return; } if (internalAmmoCount <= 0) { reloadcooldown = maxReloadCooldown; return; } if (!inLineOfSight(target, true)) { target=null; return; } internalAmmoCount--; shootcooldown = maxShootCooldown; GunUtil.shootHandler(g, (Player) npc.getEntity()); GunUtil.playShoot(g, (Player) npc.getEntity()); if (target == null) { Bukkit.broadcastMessage("Shooting no target"); } // Bukkit.broadcastMessage("run1"); // new BukkitRunnable() { // public void run() { // GunUtil.shoot(g, (Player) npc.getEntity(), g.getSway(), g.getDamage(), 1, // g.getMaxDistance()); // GunUtil.playShoot(g, null, (Player) npc.getEntity()); // Bukkit.broadcastMessage("run"); // } // }.runTaskTimer(Main.getInstance(), 10 / g.getBulletsPerShot(), 10 / // g.getBulletsPerShot()); } } }