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

The following examples show how to use org.bukkit.util.Vector#getX() . 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: HillObjective.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void renderBlocks() {
    if (progress == null) return;
    byte color1 = capturingTeam != null ? MiscUtil.convertChatColorToDyeColor(capturingTeam.getColor()).getWoolData() : -1;
    byte color2 = team != null ? MiscUtil.convertChatColorToDyeColor(team.getColor()).getWoolData() : -1;
    Vector center = progress.getCenterBlock().getVector();
    double x = center.getX();
    double z = center.getZ();
    double percent = Math.toRadians(getPercent() * 3.6);
    for(Block block : progress.getBlocks()) {
        if (!visualMaterials.evaluate(block).equals(FilterState.ALLOW)) continue;
        double dx = block.getX() - x;
        double dz = block.getZ() - z;
        double angle = Math.atan2(dz, dx);
        if(angle < 0) angle += 2 * Math.PI;
        byte color = angle < percent ? color1 : color2;
        if (color == -1) {
            Pair<Material,Byte> oldBlock = oldProgress.getBlockAt(new BlockVector(block.getLocation().position()));
            if (oldBlock.getLeft().equals(block.getType())) color = oldBlock.getRight();
        }
        if (color != -1) block.setData(color);
    }
}
 
Example 2
Source File: RegionPointProvider.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Location getPoint(Match match, @Nullable Entity entity) {
  Vector pos = this.region.getRandom(match.getRandom());
  PointProviderLocation location =
      new PointProviderLocation(match.getWorld(), pos.getX(), pos.getY(), pos.getZ());

  if (attributes.getYawProvider() != null) {
    location.setYaw(attributes.getYawProvider().getAngle(pos));
    location.setHasYaw(true);
  }

  if (attributes.getPitchProvider() != null) {
    location.setPitch(attributes.getPitchProvider().getAngle(pos));
    location.setHasPitch(true);
  }

  location = makeSafe(location);

  return location;
}
 
Example 3
Source File: ControllablePigZombieEntity.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 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: ControllableCaveSpiderEntity.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: ControllablePigZombieEntity.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 8
Source File: ControllableWolfEntity.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: ControllablePlayerEntity.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: ControllableZombieEntity.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: ControllableEndermanEntity.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: PlayerBoundingBox.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void teleportBoundingBox(Vector to, boolean onGround) {
    int i = 0;
    for (int x = -1; x < 2; x += 2) {
        for (int z = -1; z < 2; z += 2) {
            Packet teleportPacket = new PacketPlayOutEntityTeleport(zombieID.get(i),
                    to.getX() + (x * DamageIndicator.OFFSET), to.getY() , to.getZ() + (z * DamageIndicator.OFFSET),
                    (byte) 2, (byte) 0, onGround);
            PacketUtils.broadcastPacketByUUID(teleportPacket, viewers);
            i++;
        }
    }
}
 
Example 13
Source File: ControllableCreeperEntity.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: ControllableWitherEntity.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: ControllableVillagerEntity.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 16
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 17
Source File: Portal.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
protected Location cloneWith(Location original, Vector position, float yaw, float pitch) {
  return new Location(
      original.getWorld(), position.getX(), position.getY(), position.getZ(), yaw, pitch);
}
 
Example 18
Source File: MoveEvent.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private Vector handlePendingVelocities() {
    List<Pair<Vector, Long>> kbs = pp.getPendingVelocities();
    if (kbs.size() > 0) {
        double epsilon = 0.003;
        int kbIndex;
        int expiredKbs = 0;
        long currTime = System.currentTimeMillis();
        Vector currVelocity = new Vector(getTo().getX() - getFrom().getX(), getTo().getY() - getFrom().getY(), getTo().getZ() - getFrom().getZ());
        boolean jump = pp.isOnGround() && Math.abs(0.42 - currVelocity.getY()) < 0.00001;
        double speedPotMultiplier = 1;
        for (PotionEffect effect : p.getActivePotionEffects()) {
            if (!effect.getType().equals(PotionEffectType.SPEED))
                continue;
            speedPotMultiplier = 1 + (effect.getAmplifier() + 1 * 0.2);
        }
        boolean flying          = pp.isFlying();
        double sprintMultiplier = flying ? (pp.isSprinting() ? 2 : 1) : (pp.isSprinting() ? 1.3 : 1);
        double weirdConstant    = (jump && pp.isSprinting() ? 0.2518462 : (pp.isSwimming() ? 0.0196 : 0.098)); //(pp.isOnGround() ? 0.098 : (flying ? 0.049 : 0.0196));
        double baseMultiplier   = flying ? (10 * p.getFlySpeed()) : (5 * p.getWalkSpeed() * speedPotMultiplier);
        double maxDiscrepancy   = weirdConstant * baseMultiplier * sprintMultiplier + epsilon;

        //pending knockbacks must be in order; get the first entry in the list.
        //if the first entry doesn't work (probably because they were fired on the same tick),
        //then work down the list until we find something
        for (kbIndex = 0; kbIndex < kbs.size(); kbIndex++) {
            Pair<Vector, Long> kb = kbs.get(kbIndex);

            //replace the following if-statement with this sometime? You'll have to worry about the else-statement, though.
            //int timeDiff = (int)(currTime - kb.getValue());
            //int ping = ServerUtils.getPing(p);
            //int lowerBound = 100;
            //int upperBound = 300;
            //if (timeDiff >= ping - lowerBound && timeDiff <= ping + upperBound) { //400ms window to allow for network jitter

            if (currTime - kb.getValue() <= ServerUtils.getPing(p) + 200) { //add 200 just in case the player's ping jumps a bit

                Vector kbVelocity = kb.getKey();
                double x = hitSlowdown ? 0.6 * kbVelocity.getX() : kbVelocity.getX();
                double y = kbVelocity.getY();
                double z = hitSlowdown ? 0.6 * kbVelocity.getZ() : kbVelocity.getZ();

                //check Y component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.TOP) && y > 0) || (boxSidesTouchingBlocks.contains(Direction.BOTTOM) && y < 0)) && /*...player isn't colliding...*/
                        Math.abs(y - currVelocity.getY()) > 0.01 && /*...and velocity is nowhere close to kb velocity...*/
                        !jump && !pp.isSwimming() && !step /*...and did not jump and is not swimming and did not "step"*/) {
                    continue;
                }

                double minThresX = x - maxDiscrepancy;
                double maxThresX = x + maxDiscrepancy;
                double minThresZ = z - maxDiscrepancy;
                double maxThresZ = z + maxDiscrepancy;

                //check X component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.EAST) && x > 0) || (boxSidesTouchingBlocks.contains(Direction.WEST) && x < 0)) && /*...player isn't colliding...*/
                        !(currVelocity.getX() <= maxThresX && currVelocity.getX() >= minThresX)) { /*...and velocity is nowhere close to kb velocity...*/
                    continue;
                }
                //check Z component
                //skip to next kb if...
                if (!((boxSidesTouchingBlocks.contains(Direction.SOUTH) && z > 0) || (boxSidesTouchingBlocks.contains(Direction.NORTH) && z < 0)) && /*...player isn't colliding...*/
                        !(currVelocity.getZ() <= maxThresZ && currVelocity.getZ() >= minThresZ)) { /*...and velocity is nowhere close to kb velocity...*/
                    continue;
                }
                kbs.subList(0, kbIndex + 1).clear();
                return kbVelocity;
            }
            else {
                failedKnockback = true;
                expiredKbs++;
            }
        }
        kbs.subList(0, expiredKbs).clear();
    }
    return null;
}
 
Example 19
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 20
Source File: Location.java    From Kettle with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Subtracts the location by a vector.
 *
 * @param vec The vector to use
 * @return the same location
 * @see Vector
 */
public Location subtract(Vector vec) {
    this.x -= vec.getX();
    this.y -= vec.getY();
    this.z -= vec.getZ();
    return this;
}