Java Code Examples for org.bukkit.util.Vector#getY()

The following examples show how to use org.bukkit.util.Vector#getY() . 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: HologramImpl.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void move(Vector to) {
    checkNotNull(to, "The Vector object in HologramImpl#move(Vector) is null");
    this.defX = to.getX();
    this.defY = to.getY();
    this.defZ = to.getZ();
    if (!this.isSimple()) {
        HoloAPI.getManager().saveToFile(this);
    }
    for (String ident : this.getPlayerViews().keySet()) {
        Player p = IdentUtil.getPlayerOf(ident);
        if (p != null) {
            this.move(p, to);
        }
    }
}
 
Example 2
Source File: TraceEffect.java    From EffectLib with MIT License 5 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    if (world == null) {
        world = location.getWorld();
    } else if (!location.getWorld().equals(world)) {
        cancel(true);
        return;
    }

    synchronized(wayPoints)
    {
        if (wayPoints.size() >= maxWayPoints) {
            wayPoints.remove(0);
        }
    }

    wayPoints.add(location.toVector());
    step++;
    if (step % refresh != 0) {
        return;
    }

    synchronized(wayPoints)
    {
        for (Vector position : wayPoints) {
            Location particleLocation = new Location(world, position.getX(), position.getY(), position.getZ());
            display(particle, particleLocation);
        }
    }
}
 
Example 3
Source File: CraftFireball.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setDirection(Vector direction) {
    Validate.notNull(direction, "Direction can not be null");
    double x = direction.getX();
    double y = direction.getY();
    double z = direction.getZ();
    double magnitude = (double) MathHelper.sqrt_double(x * x + y * y + z * z);
    getHandle().accelerationX = x / magnitude;
    getHandle().accelerationY = y / magnitude;
    getHandle().accelerationZ = z / magnitude;
}
 
Example 4
Source File: ControllablePigEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 5
Source File: ControllableOcelotEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 6
Source File: ControllableEnderDragonEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 7
Source File: Vectors.java    From Chimera with MIT License 5 votes vote down vote up
public static Vector rotateAroundXAxis(Vector vector, double angle) {
    double cos = cos(angle);
    double sin = sin(angle);
    double y = vector.getY() * cos - vector.getZ() * sin;
    double z = vector.getY() * sin + vector.getZ() * cos;
    
    return vector.setY(y).setZ(z);
}
 
Example 8
Source File: ControllableMushroomCowEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 9
Source File: ControllableBlazeEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 10
Source File: ControllableBatEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 11
Source File: ControllableSilverfishEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 12
Source File: BlockVectors.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean isInside(Vector point, Location blockLocation) {
  return blockLocation.getX() <= point.getX()
      && point.getX() <= blockLocation.getX() + 1
      && blockLocation.getY() <= point.getY()
      && point.getY() <= blockLocation.getY() + 1
      && blockLocation.getZ() <= point.getZ()
      && point.getZ() <= blockLocation.getZ() + 1;
}
 
Example 13
Source File: ControllableIronGolemEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 14
Source File: ControllableSlimeEntity.java    From EntityAPI with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void g(double x, double y, double z) {
    if (this.controllableEntity != null) {
        Vector velocity = this.controllableEntity.getMind().getAttribute(PushAttribute.class).call(this.controllableEntity, new Vector(x, y, z)).getPushVelocity();
        x = velocity.getX();
        y = velocity.getY();
        z = velocity.getZ();
    }
    super.g(x, y, z);
}
 
Example 15
Source File: EntityPet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
public void setVelocity(Vector vel) {
    this.motX = vel.getX();
    this.motY = vel.getY();
    this.motZ = vel.getZ();
    this.velocityChanged = true;
}
 
Example 16
Source File: EntityPet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
public void onLive() {
    if (this.pet == null) {
        this.remove(false);
        return;
    }

    if (this.getPlayerOwner() == null || !this.getPlayerOwner().isOnline() || Bukkit.getPlayerExact(this.getPlayerOwner().getName()) == null) {
        EchoPet.getManager().removePet(this.getPet(), true);
        return;
    }

    if (pet.isOwnerRiding() && this.passenger == null && !pet.isOwnerInMountingProcess()) {
        pet.ownerRidePet(false);
    }

    if (((CraftPlayer) this.getPlayerOwner()).getHandle().isInvisible() != this.isInvisible() && !this.shouldVanish) {
        this.setInvisible(!this.isInvisible());
    }

    if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSneaking() != this.isSneaking()) {
        this.setSneaking(!this.isSneaking());
    }

    if (((CraftPlayer) this.getPlayerOwner()).getHandle().isSprinting() != this.isSprinting()) {
        this.setSprinting(!this.isSprinting());
    }

    if (this.getPet().isHat()) {

        this.lastYaw = this.yaw = (this.getPet().getPetType() == PetType.ENDERDRAGON ? this.getPlayerOwner().getLocation().getYaw() - 180 : this.getPlayerOwner().getLocation().getYaw());
    }

    if (this.getPlayerOwner().isFlying() && EchoPet.getOptions().canFly(this.getPet().getPetType())) {
        Location petLoc = this.getLocation();
        Location ownerLoc = this.getPlayerOwner().getLocation();
        Vector v = ownerLoc.toVector().subtract(petLoc.toVector());

        double x = v.getX();
        double y = v.getY();
        double z = v.getZ();

        Vector vo = this.getPlayerOwner().getLocation().getDirection();
        if (vo.getX() > 0) {
            x -= 1.5;
        } else if (vo.getX() < 0) {
            x += 1.5;
        }
        if (vo.getZ() > 0) {
            z -= 1.5;
        } else if (vo.getZ() < 0) {
            z += 1.5;
        }

        this.setVelocity(new Vector(x, y, z).normalize().multiply(0.3F));
    }
}
 
Example 17
Source File: EntityInsentientPet.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
public void onLive() {
    if (this.getPet() == null) {
        this.remove(false);
        return;
    }

    if (this.getPlayerOwner() == null || !this.getPlayerOwner().isOnline()) {
        EchoPet.getManager().removePet(this.getPet(), true);
        return;
    }

    if (getPet().isOwnerRiding() && getEntity().getPassengers().isEmpty() && !getPet().isOwnerInMountingProcess()) {
        getPet().ownerRidePet(false);
    }

    if (getPlayerEntity().isInvisible() != getEntity().isInvisible() && !shouldVanish) {
        getEntity().setInvisible(!getEntity().isInvisible());
    }

    if (getPlayerEntity().isSneaking() != getEntity().isSneaking()) {
        getEntity().setSneaking(!getEntity().isSneaking());
    }

    if (getPlayerEntity().isSprinting() != getEntity().isSprinting()) {
        getEntity().setSprinting(!getEntity().isSprinting());
    }

    if (this.getPet().isHat()) {
        getEntity().setYaw(this.getPet().getPetType() == PetType.ENDERDRAGON ? this.getPlayerOwner().getLocation().getYaw() - 180 : this.getPlayerOwner().getLocation().getYaw());
    }

    if (this.getPlayerOwner().isFlying() && EchoPet.getOptions().canFly(this.getPet().getPetType())) {
        Location petLoc = this.getLocation();
        Location ownerLoc = this.getPlayerOwner().getLocation();
        Vector v = ownerLoc.toVector().subtract(petLoc.toVector());

        double x = v.getX();
        double y = v.getY();
        double z = v.getZ();

        Vector vo = this.getPlayerOwner().getLocation().getDirection();
        if (vo.getX() > 0) {
            x -= 1.5;
        } else if (vo.getX() < 0) {
            x += 1.5;
        }
        if (vo.getZ() > 0) {
            z -= 1.5;
        } else if (vo.getZ() < 0) {
            z += 1.5;
        }

        getBukkitEntity().setVelocity(new Vector(x, y, z).normalize().multiply(0.3F));
    }
    ImmutableSet<NMSEntity> passengers = ImmutableSet.copyOf(getEntity().getPassengers());
    if (passengers.isEmpty()) {
        petGoalSelector.updateGoals();
    }
    // Check for mounts
    for (NMSEntity passenger : passengers) {
        if (!knownMountedEntities.contains(passenger)) {
            onMounted(passenger);
            knownMountedEntities.add(passenger);
        }
    }
    // Check for dismounts
    knownMountedEntities.removeIf((entity) -> {
        if (!passengers.contains(entity)) {
            onDismounted(entity);
            return true;
        }
        return false;
    });
}
 
Example 18
Source File: ExprVectorXYZ.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Number convert(Vector v) {
	return axis == 0 ? v.getX() : (axis == 1 ? v.getY() : v.getZ());
}
 
Example 19
Source File: TowerBlockPlace.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculates the time needed to place one block.
 */
private static double calculateDelay(Integer jumpBoostLevel, Integer levitationLevel)
{
    if (levitationLevel != null) {
        // 0.9 Blocks per second per levitation level.
        return 900 / ((levitationLevel + 1D) * TOWER_LENIENCY * LEVITATION_LENIENCY);
    }

    // No JUMP_BOOST
    if (jumpBoostLevel == null) {
        return AMPLIFIER_CACHE.get(0);
    }

    // Player has JUMP_BOOST
    if (jumpBoostLevel < 0) {
        // Negative JUMP_BOOST -> Not allowed to place blocks -> Very high delay
        return 1500;
    }

    if (jumpBoostLevel + 1 < AMPLIFIER_CACHE.size()) {
        return AMPLIFIER_CACHE.get(jumpBoostLevel + 1);
    }

    // The velocity in the beginning
    Vector currentVelocity = new Vector(0, Jumping.getJumpYMotion(jumpBoostLevel), 0);

    // The first tick (1) happens here
    double currentBlockValue = currentVelocity.getY();

    // Start the tick-loop at 2 due to the one tick outside.
    for (short ticks = 2; ticks < 160; ticks++) {
        currentVelocity = Gravitation.applyGravitationAndAirResistance(currentVelocity, Gravitation.PLAYER);

        // Break as the player has already reached the max height (no more blocks to place below).
        if (currentVelocity.getY() <= 0) {
            // If the result is lower here, the detection is more lenient.
            // * 50 : Convert ticks to milliseconds
            // 0.925 is additional leniency
            // Deliberately ignore the "falling" phase above the last block to increase leniency and code simplicity
            return ((ticks * 50) / Math.floor(currentBlockValue)) * 0.925 * TOWER_LENIENCY;
        }

        currentBlockValue += currentVelocity.getY();
    }

    // Too high movement; no checking
    return 0;
}
 
Example 20
Source File: AxisAlignedBB.java    From AACAdditionPro with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Check if the given Vector lies within this Bounding Box
 *
 * @param vector the vector which may or may not be in this Bounding Box
 *
 * @return true when the vector is inside this Bounding Box, false when not
 */
public boolean isVectorInside(Vector vector)
{
    return !(vector.getX() <= this.minX || vector.getX() >= this.maxX) &&
           !(vector.getY() <= this.minY || vector.getY() >= this.maxY) &&
           (vector.getZ() > this.minZ || vector.getZ() < this.maxZ);
}