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

The following examples show how to use org.bukkit.util.Vector#getZ() . 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: AABB.java    From Hawk with GNU General Public License v3.0 6 votes vote down vote up
public Vector translateAndCollide(Vector vector, World world, int gameVersion) {
    AABB preBox = this.clone();
    preBox.expand(-0.0001, -0.0001, -0.0001);
    List<AABB> collidedBlocksBefore = preBox.getBlockAABBs(world, gameVersion, Material.WEB);

    double pdX = vector.getX();
    double pdY = vector.getY();
    double pdZ = vector.getZ();

    AABB testBox = this.clone();
    testBox.expand(-0.00000001, -0.00000001, -0.00000001);
    pdX = moveOnAxis(testBox, pdX, 0, world, gameVersion, collidedBlocksBefore);
    pdY = moveOnAxis(testBox, pdY, 1, world, gameVersion, collidedBlocksBefore);
    pdZ = moveOnAxis(testBox, pdZ, 2, world, gameVersion, collidedBlocksBefore);

    Vector move = new Vector(pdX, pdY, pdZ);
    translate(move);

    return move;
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Object particlesPacket(String name, boolean longRange, Vector pos, Vector offset, float data, int count, int... extra) {
    return new PacketPlayOutWorldParticles(EnumParticle.valueOf(EnumParticle.class, name),
                                           longRange,
                                           (float) pos.getX(), (float) pos.getY(), (float) pos.getZ(),
                                           (float) offset.getX(), (float) offset.getY(), (float) offset.getZ(),
                                           data,
                                           count,
                                           extra);
}
 
Example 7
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 8
Source File: ControllableSheepEntity.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: 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 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: ControllableSkeletonEntity.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: ControllableWitchEntity.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 13
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 14
Source File: RegionSave.java    From CardinalPGM with MIT License 4 votes vote down vote up
public BlockVector blockAlign(Vector vector) {
    return new BlockVector((int) vector.getX() + 0.5d, (int) vector.getY() + 0.5d, (int) vector.getZ() + 0.5d);
}
 
Example 15
Source File: PointRegion.java    From CardinalPGM with MIT License 4 votes vote down vote up
public PointRegion(String name, Vector vector) {
    this(name, vector.getX(), vector.getY(), vector.getZ());
}
 
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()) {
        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: FightHitbox.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private void processDirection(InteractEntityEvent e, float yaw, float pitch) {
    Entity entity = e.getEntity();
    if (!(entity instanceof Player) && !CHECK_OTHER_ENTITIES)
        return;
    Player attacker = e.getPlayer();
    int ping = ServerUtils.getPing(attacker);
    if (ping > PING_LIMIT && PING_LIMIT != -1)
        return;

    HawkPlayer att = e.getHawkPlayer();
    Location attackerEyeLocation = att.getPosition().clone().add(new Vector(0, 1.62, 0)).toLocation(att.getWorld());
    Vector attackerDirection = MathPlus.getDirection(yaw, pitch);

    double maxReach = MAX_REACH;
    if (attacker.getGameMode() == GameMode.CREATIVE)
        maxReach += 1.9;

    Vector victimLocation;
    if (LAG_COMPENSATION)
        //No need to add 50ms; the move and attack are already chronologically so close together
        victimLocation = hawk.getLagCompensator().getHistoryLocation(ping, e.getEntity()).toVector();
    else
        victimLocation = e.getEntity().getLocation().toVector();

    Vector eyePos = new Vector(attackerEyeLocation.getX(), attacker.isSneaking() ? attackerEyeLocation.getY() - 0.08 : attackerEyeLocation.getY(), attackerEyeLocation.getZ());
    Vector direction = new Vector(attackerDirection.getX(), attackerDirection.getY(), attackerDirection.getZ());
    Ray attackerRay = new Ray(eyePos, direction);

    AABB victimAABB;
    victimAABB = WrappedEntity.getWrappedEntity(entity).getHitbox(victimLocation);
    victimAABB.expand(BOX_EPSILON, BOX_EPSILON, BOX_EPSILON);

    Vector intersectVec3d = victimAABB.intersectsRay(attackerRay, 0, Float.MAX_VALUE);

    if (DEBUG_HITBOX) {
        victimAABB.highlight(hawk, attacker.getWorld(), 0.29);
    }

    if (DEBUG_RAY) {
        attackerRay.highlight(hawk, attacker.getWorld(), maxReach, 0.1);
    }

    if (intersectVec3d != null) {
        Location intersect = new Location(attacker.getWorld(), intersectVec3d.getX(), intersectVec3d.getY(), intersectVec3d.getZ());
        double interDistance = intersect.distance(attackerEyeLocation);
        if (interDistance > maxReach) {
            punish(att, 1, true, e, new Placeholder("type", "Reach: " + MathPlus.round(interDistance, 2) + "m"));
            return;
        }
        if (CHECK_OCCLUSION && interDistance > 1D) {
            BlockIterator iter = new BlockIterator(attacker.getWorld(), eyePos, attackerDirection, 0, (int) interDistance + 1);
            while (iter.hasNext()) {
                Block bukkitBlock = iter.next();

                if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid())
                    continue;

                WrappedBlock b = WrappedBlock.getWrappedBlock(bukkitBlock, att.getClientVersion());
                Vector intersection = b.getHitBox().intersectsRay(new Ray(attackerEyeLocation.toVector(), attackerDirection), 0, Float.MAX_VALUE);
                if (intersection != null) {
                    if (intersection.distance(eyePos) < interDistance) {
                        punish(att, 1, true, e, new Placeholder("type", "Interacted through " + b.getBukkitBlock().getType()));
                        return;
                    }
                }
            }

        }
    } else if (CHECK_BOX_INTERSECTION) {
        punish(att, 1, true, e, new Placeholder("type", "Did not hit hitbox."));
        return;
    }

    reward(att); //reward player
}
 
Example 18
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 19
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 20
Source File: Location.java    From Kettle with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Adds the location by a vector.
 *
 * @param vec Vector to use
 * @return the same location
 * @see Vector
 */
public Location add(Vector vec) {
    this.x += vec.getX();
    this.y += vec.getY();
    this.z += vec.getZ();
    return this;
}