/** * Constructs a new {@link Vector} based on this Location * * @return New Vector containing the coordinates represented by this * Location */ public Vector toVector() { return new Vector(x, y, z); }
/** * Gets a new midpoint vector between this vector and another. * * @param other The other vector * @return a new midpoint vector */ public Vector getMidpoint(Vector other) { double x = (this.x + other.x) / 2; double y = (this.y + other.y) / 2; double z = (this.z + other.z) / 2; return new Vector(x, y, z); }
@Override public Vector getSize() { return new Vector(1, 1, 1); } }
@Override public Vector getSize() { return new Vector(width, vertSize, depth); }
public GlowJungleTemple(Random random, Location location) { super(random, location, new Vector(12, 14, 15)); }
/** * Gets the minimum components of two vectors. * * @param v1 The first vector. * @param v2 The second vector. * @return minimum */ public static Vector getMinimum(Vector v1, Vector v2) { return new Vector(Math.min(v1.x, v2.x), Math.min(v1.y, v2.y), Math.min(v1.z, v2.z)); }
/** * Gets the maximum components of two vectors. * * @param v1 The first vector. * @param v2 The second vector. * @return maximum */ public static Vector getMaximum(Vector v1, Vector v2) { return new Vector(Math.max(v1.x, v2.x), Math.max(v1.y, v2.y), Math.max(v1.z, v2.z)); }
/** * Gets a random vector with components having a random value between 0 * and 1. * * @return A random vector. */ public static Vector getRandom() { return new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()); }
@Override public boolean canPlace(int baseX, int baseY, int baseZ, World world) { Vector from = new Vector(baseX, baseY, baseZ); Vector to = new Vector(baseX, baseY + height - 1, baseZ); int blocks = countAvailableBlocks(from, to, world); if (blocks == -1) { return true; } else if (blocks > 5) { height = blocks; return true; } return false; }
/** * Updates the structure's bounding box to be the bounding box of the union of its pieces. */ public void wrapAllPieces() { boundingBox = new StructureBoundingBox( new Vector(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), new Vector(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE)); children.stream().filter(Objects::nonNull) .forEach(piece -> boundingBox.expandTo(piece.getBoundingBox())); }
public static Vector deserialize(Map<String, Object> args) { double x = 0; double y = 0; double z = 0; if (args.containsKey("x")) { x = (Double) args.get("x"); } if (args.containsKey("y")) { y = (Double) args.get("y"); } if (args.containsKey("z")) { z = (Double) args.get("z"); } return new Vector(x, y, z); } }
@Override public List<Entity> getNearbyEntities(double x, double y, double z) { // This behavior is similar to CraftBukkit, where a call with args // (0, 0, 0) finds any entities whose bounding boxes intersect that of // this entity. BoundingBox searchBox = BoundingBox .fromPositionAndSize(location.toVector(), new Vector(0, 0, 0)); Vector vec = new Vector(x, y, z); Vector vec2 = new Vector(0, 0.5 * y, 0); searchBox.minCorner.subtract(vec).add(vec2); searchBox.maxCorner.add(vec).add(vec2); return world.getEntityManager().getEntitiesInside(searchBox, this); }
@Override public void setOnGround(boolean onGround) { super.setOnGround(onGround); if (onGround) { setLife((short) 0); // Despawn timer only starts when we stick in a block setVelocity(new Vector(0, 0, 0)); } }
/** * Creates a minecart. * * @param location the location * @param minecartType the minecart type (i.e. the type of block carried, if any) */ public GlowMinecart(Location location, MinecartType minecartType) { super(location); setSize(0.98f, 0.7f); setAirDrag(0.95); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); this.minecartType = minecartType; }
/** * Creates an arrow entity. * * @param location the initial location */ public GlowArrow(Location location) { super(location); setGravityAccel(new Vector(0, -0.05, 0)); setAirDrag(0.99); setApplyDragBeforeAccel(true); setBoundingBox(0.5, 0.5); }
/** * Creates a boat. * * @param location the boat's location */ public GlowBoat(Location location) { super(location); setSize(1.375f, 0.5625f); setAirDrag(0.95); setGravityAccel(new Vector(0, VERTICAL_GRAVITY_ACCEL, 0)); setWoodType(TreeSpecies.GENERIC); }
private void createNewBoundingBox(Location location, Vector size) { Vector min = new Vector(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Vector max = new Vector(location.getBlockX() + size.getBlockX() - 1, location.getBlockY() + size.getBlockY() - 1, location.getBlockZ() + size.getBlockZ() - 1); boundingBox = new StructureBoundingBox(min, max); }
/** * Returns the position where an item will emerge from the dispenser. * @param block a dispenser block * @return the position as a Vector */ public static Vector getDispensePosition(GlowBlock block) { BlockFace facing = getFacing(block); double x = block.getX() + 0.7 * facing.getModX(); double y = block.getY() + 0.7 * facing.getModY(); double z = block.getZ() + 0.7 * facing.getModZ(); return new Vector(x, y, z); }
/** * 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); }