/** * Gets a unit-vector pointing in the direction that this Location is * facing. * * @return a vector pointing the direction of this location's {@link * #getPitch() pitch} and {@link #getYaw() yaw} */ public Vector getDirection() { Vector vector = new Vector(); double rotX = this.getYaw(); double rotY = this.getPitch(); vector.setY(-Math.sin(Math.toRadians(rotY))); double xz = Math.cos(Math.toRadians(rotY)); vector.setX(-xz * Math.sin(Math.toRadians(rotX))); vector.setZ(xz * Math.cos(Math.toRadians(rotX))); return vector; }
/** * Moves this box so that its center is the given point. * @param x the center X coordinate * @param y the center Y coordinate * @param z the center Z coordinate */ public void setCenter(double x, double y, double z) { minCorner.setX(x - width / 2); minCorner.setY(y); minCorner.setZ(z - depth / 2); maxCorner.setX(x + width / 2); maxCorner.setY(y + vertSize); maxCorner.setZ(z + depth / 2); }
protected void jump() { if (location.getBlock().isLiquid()) { // jump out more when you breach the surface of the liquid if (location.getBlock().getRelative(BlockFace.UP).isEmpty()) { velocity.setY(velocity.getY() + 0.3); } // less jumping in liquid velocity.setY(velocity.getY() + 0.04); } else { // jump normally velocity.setY(velocity.getY() + 0.42); } }
/** * Converts two Vector instances to a BoundingBox. * @param a any corner * @param b the corner opposite {@code a} * @return a bounding box from {@code a} to {@code b} */ public static BoundingBox fromCorners(Vector a, Vector b) { BoundingBox box = new BoundingBox(); box.minCorner.setX(Math.min(a.getX(), b.getX())); box.minCorner.setY(Math.min(a.getY(), b.getY())); box.minCorner.setZ(Math.min(a.getZ(), b.getZ())); box.maxCorner.setX(Math.max(a.getX(), b.getX())); box.maxCorner.setY(Math.max(a.getY(), b.getY())); box.maxCorner.setZ(Math.max(a.getZ(), b.getZ())); return box; }
/** * Creates a bounding box that is effectively the entire given block. * @param block the block */ public BlockBoundingBox(Block block) { minCorner.setX(block.getX()); minCorner.setY(block.getY()); minCorner.setZ(block.getZ()); maxCorner.setX(block.getX() + 1); maxCorner.setY(block.getY() + 0.95); maxCorner.setZ(block.getZ() + 1); }
@Override protected void updateBoundingBox() { BlockFace rightFace = getRightFace(); double modX = Math.abs(rightFace.getModX() * art.getBlockWidth()); double modY = art.getBlockHeight(); double modZ = Math.abs(rightFace.getModZ() * art.getBlockWidth()); if (modX == 0.0) { modX = PAINTING_DEPTH; } else if (modZ == 0.0) { modZ = PAINTING_DEPTH; } // restrict the bounding box to not reach exactly onto the next blocks modX -= 0.00001; modY -= 0.00001; modZ -= 0.00001; boundingBox = new EntityBoundingBox(modX, modY, modZ); super.updateBoundingBox(); // y of the painting is in the center, but for most other it is at the foot // therefore center it here boundingBox.minCorner.setY(location.getY() - modY / 2); boundingBox.maxCorner.setY(location.getY() + modY / 2); }
/** * Maps {0, 0, 0} to {0, 1, 0} and all other vectors to their normalized form. * * @param ray the ray to transform * @return a ray of length 1 */ public static Vector getVelocityRay(Vector ray) { Vector velocityRay = ray.clone(); if (velocityRay.lengthSquared() == 0) { velocityRay.setX(0); velocityRay.setY(1); velocityRay.setZ(0); } else { velocityRay.normalize(); } return velocityRay; }
protected Vector getVelocityFromMovement() { movement.setY(0);
velocity.setY(0); velocity.setY(velocity.getY() + getGravityAccel().getY() / 4); } else if (location.getBlock().getType() == Material.LAVA) { velocity.multiply(liquidDrag - 0.3); velocity.setY(velocity.getY() + getGravityAccel().getY() / 4); } else { if (applyDragBeforeAccel) { velocity.setY(airDrag * velocity.getY() + getGravityAccel().getY()); } else { velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY())); velocity.setY(0); velocity.setZ(velocity.getZ() * slipMultiplier); } else { case WATER: case LAVA: velocity.setY(velocity.getY() + getGravityAccel().getY() / 4); break; default: velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
delta.setY(Math.abs(delta.getY())); delta.setZ(Math.abs(delta.getZ())); int flatDistance = (int) Math.round(Math.hypot(delta.getX(), delta.getZ()) * 100.0);
delta.setY(Math.abs(delta.getY())); delta.setZ(Math.abs(delta.getZ())); int flatDistance = (int) Math.round(Math.hypot(delta.getX(), delta.getZ()) * 100.0);
startClone.setY(startClone.getY() + yOffset);
public static final Vector rotateAroundAxisX(Vector v, double angle) { double y, z, cos, sin; cos = Math.cos(angle); sin = Math.sin(angle); y = v.getY() * cos - v.getZ() * sin; z = v.getY() * sin + v.getZ() * cos; return v.setY(y).setZ(z); }
public static final Vector rotateAroundAxisZ(Vector v, double angle) { double x, y, cos, sin; cos = Math.cos(angle); sin = Math.sin(angle); x = v.getX() * cos - v.getY() * sin; y = v.getX() * sin + v.getY() * cos; return v.setX(x).setY(y); }
@Override public void onRun() { Location location = getLocation(); for (int i = 0; i < 10; i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d); v.setY(RandomUtils.random.nextFloat() * 1.8); location.add(v); display(particle, location); location.subtract(v); } }
public static void setVelocity(Entity entity, Vector velocity) { if (!MathUtils.isFinite(velocity.getX()) || !MathUtils.isFinite(velocity.getY()) || !MathUtils.isFinite(velocity.getZ())) { return; } if (Math.abs(velocity.getX()) > MAX_VELOCITY) velocity.setX(MAX_VELOCITY * Math.signum(velocity.getX())); if (Math.abs(velocity.getY()) > MAX_VELOCITY) velocity.setY(MAX_VELOCITY * Math.signum(velocity.getY())); if (Math.abs(velocity.getZ()) > MAX_VELOCITY) velocity.setZ(MAX_VELOCITY * Math.signum(velocity.getZ())); entity.setVelocity(velocity); } }
public VectorNode(VectorNode parent, Vector location, PathInfo info) { super(parent); this.location = location.setX(location.getBlockX()).setY(location.getBlockY()).setZ(location.getBlockZ()); this.info = info; }
@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); }
private void jump(final Player p) { if (!GeneralMethods.isSolid(p.getLocation().getBlock().getRelative(BlockFace.DOWN))) { this.remove(); return; } final Vector vec = p.getVelocity(); vec.setY(this.height); p.setVelocity(vec); this.bPlayer.addCooldown(this); return; }