/** * Constructs the BlockIterator. * * @param loc The location for the start of the ray trace * @param yOffset The trace begins vertically offset from the start vector * by this value */ public BlockIterator(Location loc, double yOffset) { this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, 0); }
/** * Constructs the BlockIterator * * @param loc The location for the start of the ray trace * @param yOffset The trace begins vertically offset from the start vector * by this value * @param maxDistance This is the maximum distance in blocks for the * trace. Setting this value above 140 may lead to problems with * unloaded chunks. A value of 0 indicates no limit */ public BlockIterator(Location loc, double yOffset, int maxDistance) { this(loc.getWorld(), loc.toVector(), loc.getDirection(), yOffset, maxDistance); }
@Override public <T extends Projectile> T launchProjectile(Class<? extends T> type) { return launchProjectile(type, getLocation().getDirection()); // todo: multiply by some speed }
/** * Determines the initial location of the fishing hook. * * @param player the player who is fishing * @return the initial location of the hook */ private Location calculateSpawnLocation(Player player) { Location loc = player.getEyeLocation(); Vector direction = loc.getDirection(); double dx = direction.getX() * player.getWidth() / 2; double dz = direction.getZ() * player.getWidth() / 2; loc.add(dx, 0, dz); return loc; } }
/** * Creates a thrown egg with default speed. * * @param location the position and facing of the thrower */ public GlowEgg(Location location) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(3)); setBoundingBox(0.25, 0.25); }
/** * Creates a thrown snowball with default speed. * * @param location the position and facing of the thrower */ public GlowSnowball(Location location) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(3)); setBoundingBox(0.25, 0.25); }
/** * Creates a thrown ender pearl. * * @param location the position and facing of the thrower * @param speed the initial speed */ public GlowEnderPearl(Location location, float speed) { super(location); setAirDrag(0.99); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setApplyDragBeforeAccel(true); setVelocity(location.getDirection().multiply(speed)); setBoundingBox(0.25, 0.25); }
/** * Creates a fishing bob. * * @param location the location * @param itemStack the fishing rod (used to handle enchantments) or null (equivalent to * @param angler the player who is casting this fish hook (must be set at spawn time) */ public GlowFishingHook(Location location, ItemStack itemStack, Player angler) { super(location); setSize(0.25f, 0.25f); lifeTime = calculateLifeTime(); this.itemStack = InventoryUtil.itemOrEmpty(itemStack).clone(); // TODO: velocity does not match vanilla Vector direction = location.getDirection(); setVelocity(direction.multiply(1.5)); super.setShooter(angler); }
/** * Spawns a new {@link GlowItem} in the world, as if this HumanEntity had dropped it. * * <p>Note that this does NOT remove the item from the inventory. * * @param stack The item to drop * @return the GlowItem that was generated, or null if the spawning was cancelled * @throws IllegalArgumentException if the stack is empty */ public GlowItem drop(ItemStack stack) { checkArgument(!InventoryUtil.isEmpty(stack), "stack must not be empty"); Location dropLocation = location.clone().add(0, getEyeHeight(true) - 0.3, 0); GlowItem dropItem = world.dropItem(dropLocation, stack); /* These calculations are strictly based off of trial-and-error to find the closest similar behavior to the official server. May be changed in the future. */ Vector vel = location.getDirection().multiply(0.3); ThreadLocalRandom tlr = ThreadLocalRandom.current(); double randOffset = 0.02; vel.add(new Vector( tlr.nextDouble(randOffset) - randOffset / 2, tlr.nextDouble(0.12), tlr.nextDouble(randOffset) - randOffset / 2)); dropItem.setVelocity(vel); return dropItem; }
location.add(location.getDirection()); location.setPitch(0); location.setYaw(0);
launchedProjectile.setVelocity(player.getEyeLocation().getDirection().multiply( Math.max(5, chargeFraction * MAX_SPEED)));
setVelocity(velocity); } else { Vector direction = boostedEntity.getLocation().getDirection(); Vector velocity = boostedEntity.getVelocity();
/** * Performs a ray tracing operation from one point to the other, and obtains the (first) block hit * * @param startLocation to start ray tracing from, direction from Location is used * @param maxLength limit of ray tracing * @return the hit Block, or null if none was found (AIR) */ public static Block rayTraceBlock(Location startLocation, double maxLength) { return rayTraceBlock(startLocation, startLocation.getDirection(), maxLength); } }
@Override public Vector getDirection() { Location location = getLocation(); if (location != null) { return location.getDirection(); } return new Vector(0, 1, 0); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (ThreadLocalRandom.current().nextDouble(100) < chance) { damage *= factor; } if (getAngleBetweenVectors(((LivingEntity) event.getEntity()).getEyeLocation().getDirection(), player.getEyeLocation().getDirection()) < 90 && ThreadLocalRandom.current().nextDouble(100) < backstabChance) { damage *= backstabFactor; } return PowerResult.ok(damage); }
@Override public Vector3D getDirection() { Vector v = l.getDirection(); return new Vector3D(v.getX(), v.getY(), v.getZ()); }
@Nullable @Override public Block getInteractBlock() { Location location = getEyeLocation(); if (location == null) return null; Block playerBlock = location.getBlock(); if (isTargetable(playerBlock)) return playerBlock; Vector direction = location.getDirection().normalize(); return location.add(direction).getBlock(); }
@Override public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); if (rand.nextInt(chance) == 0) { Bukkit.getScheduler().runTask(RPGItems.plugin, () -> entity.setVelocity(player.getLocation().getDirection().setY(power))); } return PowerResult.ok(damage); }
protected Vector getDirection() { Location origin = this.getOrigin(); Location target = this.getTarget(); if (origin == null) return new Vector(0, 1, 0); Vector direction = target == null ? origin.getDirection() : target.toVector().subtract(origin.toVector()); return direction.normalize(); }
/** * Returns the location of the tip of the left arm assuming it is fully * extended. Use the displayLeftArm() check to see if it is fully extended. * * @return location of the tip of the left arm */ public Location getLeftArmEnd() { final Location l1 = GeneralMethods.getLeftSide(this.player.getLocation(), 2).add(0, 1.5, 0); return l1.clone().add(this.player.getLocation().getDirection().normalize().multiply(this.initLength)); }