public static Vector getRayBetween(Location target, Location source) { return target.clone().subtract(source).toVector(); } }
private void spawnSnowman(Location location) { if (SNOWMAN_PATTERN.matches(location, true, 0, 0)) { location.getWorld() .spawnEntity(location.clone().subtract(-0.5, 2, -0.5), EntityType.SNOWMAN); } } }
private boolean spawnIronGolem(Location location) { if (IRONGOLEM_PATTERN.matches(location, true, 1, 0)) { Entity entity = location.getWorld() .spawnEntity(location.clone().subtract(-0.5, 2, -0.5), EntityType.IRON_GOLEM); ((GlowIronGolem) entity).setPlayerCreated(true); return true; } return false; }
/** * Gets the lowest block at the given {@link Location} such that the block * and all blocks above it are either air or one of the given materials. * * @param location Coordinates to get the highest block * @param except Blocks to exclude in addition to air * @return Highest non-empty block */ public Block getHighestBlockAt(Location location, Material... except) { Block block = getHighestBlockAt(location); List<Material> array = Arrays.asList(except); for (int i = 0; i < 6; i++) { block = block.getLocation().clone().subtract(0, i == 0 ? 0 : 1, 0).getBlock(); if (block.getType() == Material.AIR || array.contains(block.getType())) { continue; } return block; } return getHighestBlockAt(location); }
location.setYaw(random.nextFloat() * 360 - 180); if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) { location.subtract(0, 1, 0);
@Override public boolean isInside(Location location) { Location max = center.clone().add(size / 2, 0, size / 2); Location min = center.clone().subtract(size / 2, 0, size / 2); return location.getX() <= max.getX() && location.getZ() <= max.getZ() && location.getX() >= min.getX() && location.getZ() >= min.getZ(); }
while ((l.getBlock().getType() == Material.AIR || l.getBlock().getType() == Material.LEAVES) && blockY > 0) { l.subtract(0, 1, 0);
current.subtract(right.getModX() * art.getBlockWidth(), 0, right.getModZ() * art.getBlockWidth());
Vector delta = newLocation.clone().subtract(oldLocation).toVector(); delta.setX(Math.abs(delta.getX())); delta.setY(Math.abs(delta.getY()));
Vector delta = newLocation.clone().subtract(oldLocation).toVector(); delta.setX(Math.abs(delta.getX())); delta.setY(Math.abs(delta.getY()));
@Override public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) { GlowSkull skull = (GlowSkull) block.getState(); skull.setSkullType(getType(holding.getDurability())); if (skull.getSkullType() == SkullType.PLAYER) { SkullMeta meta = (SkullMeta) holding.getItemMeta(); if (meta != null) { skull.setOwner(meta.getOwner()); } } MaterialData data = skull.getData(); if (!(data instanceof Skull)) { warnMaterialData(Skull.class, data); return; } Skull skullData = (Skull) data; if (canRotate(skullData)) { // Can be rotated skull.setRotation(player.getFacing().getOppositeFace()); } skull.update(); // Wither for (int i = 0; i < 3; i++) { if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) { block.getWorld() .spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER); break; } } }
public static boolean isMatBelow(Player player, Material material, int depth) { Location location = player.getLocation().clone(); // Cloned location for (int blocks = 1; blocks <= depth; blocks++) { // From 1 to depth location.subtract(0, 1, 0); // Move one block down if (location.getBlock().getType() == material) { // If this is the material -> return true (break/exit loop) return true; } } return false; // No such material was found in all blocks -> return false }
public void cast(Player caster){ Location loc = caster.getTargetBlock(null, 512).getLocation(); for (int c = -3; c < 3; c++) for (int b = -1; b < 5; b++) for (int a = -3; a < 3; a++) { Block ice = caster.getWorld().getBlockAt(loc.add(a, b, c)); ice.setTypeId(79); loc = loc.subtract(a, b, c); } }
@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 Location getRelativeMin() { World world = getBlock().getWorld(); Location min = new Location(world, minx, miny, minz); min.subtract(getLocation()); return min; }
public Location getRelativeMax() { World world = getBlock().getWorld(); Location max = new Location(world, maxx, maxy, maxz); max.subtract(getLocation()); return max; }
/** * Rotates an NPC to face a target location. */ public void faceLocation(Location l) { npc.faceLocation(l.clone().subtract(0, getLivingEntity().getEyeHeight(), 0)); }
private void moveEarth(final Vector apply, final Vector direction) { for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, 2)) { if (entity.getEntityId() != this.player.getEntityId()) { entity.setVelocity(apply); } } this.moveEarth(this.origin.clone().subtract(direction), direction, 3, false); }
protected void detonate(Location location, Vector v) { final Firework fw = (Firework) location.getWorld().spawnEntity(location.add(v), EntityType.FIREWORK); location.subtract(v); FireworkMeta meta = fw.getFireworkMeta(); meta.setPower(0); for (int i = 0; i < intensity; i++) { meta.addEffect(firework); } fw.setFireworkMeta(meta); fw.detonate(); } }