本文整理了Java中org.bukkit.util.Vector.getZ()
方法的一些代码示例,展示了Vector.getZ()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.getZ()
方法的具体详情如下:
包路径:org.bukkit.util.Vector
类名称:Vector
方法名:getZ
[英]Gets the Z component.
[中]获取Z组件。
代码示例来源:origin: Bukkit/Bukkit
private BlockFace getZFace(Vector direction) {
return ((direction.getZ() > 0) ? BlockFace.SOUTH : BlockFace.NORTH);
}
代码示例来源:origin: Bukkit/Bukkit
private double getZLength(Vector direction) {
return Math.abs(direction.getZ());
}
代码示例来源:origin: Bukkit/Bukkit
private double getZPosition(Vector direction, Vector position, Block block) {
return getPosition(direction.getZ(), position.getZ(), block.getZ());
}
代码示例来源:origin: Bukkit/Bukkit
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("x", getX());
result.put("y", getY());
result.put("z", getZ());
return result;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Create a list of doubles from a Vector.
*
* @param vec The vector to write.
* @return The list.
*/
public static List<Double> vectorToList(Vector vec) {
return Arrays.asList(vec.getX(), vec.getY(), vec.getZ());
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Construct the vector with another vector.
*
* @param vec The other vector.
*/
public BlockVector(Vector vec) {
this.x = vec.getX();
this.y = vec.getY();
this.z = vec.getZ();
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Subtracts the location by a vector.
*
* @see Vector
* @param vec The vector to use
* @return the same location
*/
public Location subtract(Vector vec) {
this.x -= vec.getX();
this.y -= vec.getY();
this.z -= vec.getZ();
return this;
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Adds the location by a vector.
*
* @see Vector
* @param vec Vector to use
* @return the same location
*/
public Location add(Vector vec) {
this.x += vec.getX();
this.y += vec.getY();
this.z += vec.getZ();
return this;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Tests whether two bounding boxes intersect.
* @param a a bounding box
* @param b a bounding box
* @return true if {@code a} and {@code b} intersect; false otherwise
*/
public static boolean intersects(BoundingBox a, BoundingBox b) {
Vector minA = a.minCorner;
Vector maxA = a.maxCorner;
Vector minB = b.minCorner;
Vector maxB = b.maxCorner;
return maxA.getX() >= minB.getX() && minA.getX() <= maxB.getX()
&& maxA.getY() >= minB.getY() && minA.getY() <= maxB.getY()
&& maxA.getZ() >= minB.getZ() && minA.getZ() <= maxB.getZ();
}
代码示例来源:origin: Bukkit/Bukkit
/**
* Sets the {@link #getYaw() yaw} and {@link #getPitch() pitch} to point
* in the direction of the vector.
*/
public Location setDirection(Vector vector) {
/*
* Sin = Opp / Hyp
* Cos = Adj / Hyp
* Tan = Opp / Adj
*
* x = -Opp
* z = Adj
*/
final double _2PI = 2 * Math.PI;
final double x = vector.getX();
final double z = vector.getZ();
if (x == 0 && z == 0) {
pitch = vector.getY() > 0 ? -90 : 90;
return this;
}
double theta = Math.atan2(-x, z);
yaw = (float) Math.toDegrees((theta + _2PI) % _2PI);
double x2 = NumberConversions.square(x);
double z2 = NumberConversions.square(z);
double xz = Math.sqrt(x2 + z2);
pitch = (float) Math.toDegrees(Math.atan(-vector.getY() / xz));
return this;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Converts two Vector instances to a BoundingBox.
* @param a any corner
* @param b the corner opposite {@code a}
* @return a bounding box from {@code a} to {@code b}
*/
public static BoundingBox fromCorners(Vector a, Vector b) {
BoundingBox box = new BoundingBox();
box.minCorner.setX(Math.min(a.getX(), b.getX()));
box.minCorner.setY(Math.min(a.getY(), b.getY()));
box.minCorner.setZ(Math.min(a.getZ(), b.getZ()));
box.maxCorner.setX(Math.max(a.getX(), b.getX()));
box.maxCorner.setY(Math.max(a.getY(), b.getY()));
box.maxCorner.setZ(Math.max(a.getZ(), b.getZ()));
return box;
}
代码示例来源:origin: GlowstoneMC/Glowstone
public SpawnObjectMessage(int id, UUID uuid, int type, double x, double y, double z, int pitch,
int yaw, int data, Vector vector) {
this(id, uuid, type, x, y, z, pitch, yaw, data,
convert(vector.getX()), convert(vector.getY()), convert(vector.getZ()));
}
代码示例来源:origin: GlowstoneMC/Glowstone
public EntityVelocityMessage(int id, Vector velocity) {
this(id, convert(velocity.getX()), convert(velocity.getY()), convert(velocity.getZ()));
}
代码示例来源:origin: GlowstoneMC/Glowstone
private int countAvailableBlocks(Vector from, Vector to, World world) {
int n = 0;
Vector target = to.subtract(from);
int maxDistance = Math.max(Math.abs(target.getBlockY()),
Math.max(Math.abs(target.getBlockX()), Math.abs(target.getBlockZ())));
float dx = (float) target.getX() / maxDistance;
float dy = (float) target.getY() / maxDistance;
float dz = (float) target.getZ() / maxDistance;
for (int i = 0; i <= maxDistance; i++, n++) {
target = from.clone()
.add(new Vector((double) (0.5F + i * dx), 0.5F + i * dy, 0.5F + i * dz));
if (target.getBlockY() < 0 || target.getBlockY() > 255
|| !overridables.contains(blockTypeAt(
target.getBlockX(), target.getBlockY(), target.getBlockZ(), world))) {
return n;
}
}
return -1;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Determines the initial location of the fishing hook.
*
* @param player the player who is fishing
* @return the initial location of the hook
*/
private Location calculateSpawnLocation(Player player) {
Location loc = player.getEyeLocation();
Vector direction = loc.getDirection();
double dx = direction.getX() * player.getWidth() / 2;
double dz = direction.getZ() * player.getWidth() / 2;
loc.add(dx, 0, dz);
return loc;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
protected void pulsePhysics() {
if (boundingBox != null) {
Vector size = boundingBox.getSize();
for (Entity entity : world.getNearbyEntities(
location, size.getX(), size.getY(), size.getZ())) {
if (entity != this && !(entity.equals(shooter))) {
if (entity instanceof LivingEntity) {
EventFactory.getInstance().callEvent(new ProjectileHitEvent(this, entity));
collide((LivingEntity) entity);
break;
}
}
}
}
super.pulsePhysics();
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public void save(T entity, CompoundTag tag) {
super.save(entity, tag);
Vector vel = entity.getVelocity();
// Mojang creates tags "direction" and "power", as duplicates of "Motion"
final List<Double> velocityAsList = Arrays.asList(vel.getX(), vel.getY(), vel.getZ());
tag.putDoubleList("direction", velocityAsList);
tag.putDoubleList("power", velocityAsList);
tag.putBool(IS_INCENDIARY, entity.isIncendiary());
tag.putInt(YIELD_INT, (int) entity.getYield());
tag.putFloat(YIELD_FLOAT, (int) entity.getYield());
}
代码示例来源:origin: GlowstoneMC/Glowstone
private void playOutExplosion(GlowPlayer player, Iterable<Block> blocks) {
Collection<Record> records = new ArrayList<>();
for (Block block : blocks) {
Location blockLocation = block.getLocation();
byte x = (byte) (blockLocation.getBlockX() - (int) this.location.getX());
byte y = (byte) (blockLocation.getBlockY() - (int) this.location.getY());
byte z = (byte) (blockLocation.getBlockZ() - (int) this.location.getZ());
records.add(new Record(x, y, z));
}
Vector velocity = player.getVelocity();
ExplosionMessage message = new ExplosionMessage(
(float) location.getX(), (float) location.getY(), (float) location.getZ(), power,
(float) velocity.getX(), (float) velocity.getY(), (float) velocity.getZ(), records);
player.getSession().send(message);
}
代码示例来源:origin: GlowstoneMC/Glowstone
private void doDispense(GlowBlock block, ItemStack items, int power, BlockFace facing,
Vector target) {
double x = target.getX();
double y = target.getY();
double z = target.getZ();
if (facing.getModY() != 0) {
y -= 0.125;
} else {
y -= 0.15625;
}
double velocity = ThreadLocalRandom.current().nextDouble() * 0.1 + 0.2;
double velocityX = facing.getModX() * velocity;
double velocityY = 0.2;
double velocityZ = facing.getModZ() * velocity;
velocityX += ThreadLocalRandom.current().nextGaussian() * 0.0075 * power;
velocityY += ThreadLocalRandom.current().nextGaussian() * 0.0075 * power;
velocityZ += ThreadLocalRandom.current().nextGaussian() * 0.0075 * power;
BlockDispenseEvent dispenseEvent = new BlockDispenseEvent(block, items,
new Vector(velocityX, velocityY, velocityZ));
EventFactory.getInstance().callEvent(dispenseEvent);
if (!dispenseEvent.isCancelled()) {
GlowItem item = block.getWorld().dropItem(new Location(block.getWorld(), x, y, z),
dispenseEvent.getItem());
item.setVelocity(dispenseEvent.getVelocity());
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
GlowWorld world = block.getWorld();
Vector position = BlockDispenser.getDispensePosition(block);
BlockFace face = BlockDispenser.getFacing(block);
Projectile entity = projectileCreator.apply(
new Location(world, position.getX(), position.getY(), position.getZ()), stack);
entity.setShooter(new GlowDispenser(block));
entity.setVelocity(
new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() < 1) {
return null;
}
return stack;
}
内容来源于网络,如有侵权,请联系作者删除!