本文整理了Java中org.bukkit.util.Vector.add()
方法的一些代码示例,展示了Vector.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.add()
方法的具体详情如下:
包路径:org.bukkit.util.Vector
类名称:Vector
方法名:add
[英]Adds a vector to this one
[中]将一个向量添加到此向量
代码示例来源:origin: GlowstoneMC/Glowstone
public void offset(Vector offset) {
min = min.add(offset);
max = max.add(offset);
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
// This behavior is similar to CraftBukkit, where a call with args
// (0, 0, 0) finds any entities whose bounding boxes intersect that of
// this entity.
BoundingBox searchBox = BoundingBox
.fromPositionAndSize(location.toVector(), new Vector(0, 0, 0));
Vector vec = new Vector(x, y, z);
Vector vec2 = new Vector(0, 0.5 * y, 0);
searchBox.minCorner.subtract(vec).add(vec2);
searchBox.maxCorner.add(vec).add(vec2);
return world.getEntityManager().getEntitiesInside(searchBox, this);
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Launches a projectile from this entity in the horizontal direction it is facing, relative to
* the given velocity vector.
*
* @param type the projectile class
* @param location the location to launch the projectile from
* @param originalVector the direction to shoot in
* @param pitchOffset degrees to subtract from the pitch angle while calculating the y
* component of the initial direction
* @param velocity the speed for the first flight tick
* @param <T> the projectile class
* @return the launched projectile
*/
protected <T extends Projectile> T launchProjectile(Class<? extends T> type, Location location,
Vector originalVector, float pitchOffset, float velocity) {
double pitchRadians = Math.toRadians(location.getPitch());
double yawRadians = Math.toRadians(location.getYaw());
double verticalMultiplier = cos(pitchRadians);
double x = verticalMultiplier * sin(-yawRadians);
double z = verticalMultiplier * cos(yawRadians);
double y = sin(-(Math.toRadians(location.getPitch() - pitchOffset)));
T projectile = launchProjectile(type, location, x, y, z, velocity);
projectile.getVelocity().add(originalVector);
return projectile;
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
protected void pulsePhysics() {
// drag application
movement.multiply(airDrag);
// convert movement x/z to a velocity
Vector velMovement = getVelocityFromMovement();
velocity.add(velMovement);
super.pulsePhysics();
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Creates a bounding box given its minimum corner and its size.
* @param pos the minimum corner
* @param size the displacement of the maximum corner from the minimum corner
* @return a bounding box from {@code pos} to {@code pos.clone().add(size)}
*/
public static BoundingBox fromPositionAndSize(Vector pos, Vector size) {
BoundingBox box = new BoundingBox();
box.minCorner.copy(pos);
box.maxCorner.copy(pos.clone().add(size));
return box;
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public Arrow spawnArrow(Location location, Vector velocity, float speed, float spread) {
// Transformative magic
Vector randVec = new Vector(ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom
.current().nextGaussian(), ThreadLocalRandom.current().nextGaussian());
randVec.multiply(0.0075 * spread);
velocity.normalize();
velocity.add(randVec);
velocity.multiply(speed);
// yaw = Math.atan2(x, z) * 180.0D / 3.1415927410125732D;
// pitch = Math.atan2(y, Math.sqrt(x * x + z * z)) * 180.0D / 3.1415927410125732D
Arrow arrow = spawn(location, Arrow.class);
arrow.setVelocity(velocity);
return arrow;
}
代码示例来源: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
Vector vec2 = new Vector(0, getMaxHeight(), 0);
searchBox.minCorner.subtract(vec);
searchBox.maxCorner.add(vec).add(vec2);
List<LivingEntity> livingEntities = new LinkedList<>();
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public List<Entity> getNearbyEntities(double x, double y, double z) {
// This behavior is similar to CraftBukkit, where a call with args
// (0, 0, 0) finds any entities whose bounding boxes intersect that of
// this entity.
BoundingBox searchBox;
if (boundingBox == null) {
searchBox = BoundingBox.fromPositionAndSize(location.toVector(), new Vector(0, 0, 0));
} else {
searchBox = BoundingBox.copyOf(boundingBox);
}
Vector vec = new Vector(x, y, z);
searchBox.minCorner.subtract(vec);
searchBox.maxCorner.add(vec);
return world.getEntityManager().getEntitiesInside(searchBox, this);
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Spawns a new {@link GlowItem} in the world, as if this HumanEntity had dropped it.
*
* <p>Note that this does NOT remove the item from the inventory.
*
* @param stack The item to drop
* @return the GlowItem that was generated, or null if the spawning was cancelled
* @throws IllegalArgumentException if the stack is empty
*/
public GlowItem drop(ItemStack stack) {
checkArgument(!InventoryUtil.isEmpty(stack), "stack must not be empty");
Location dropLocation = location.clone().add(0, getEyeHeight(true) - 0.3, 0);
GlowItem dropItem = world.dropItem(dropLocation, stack);
/*
These calculations are strictly based off of trial-and-error to find the
closest similar behavior to the official server. May be changed in the future.
*/
Vector vel = location.getDirection().multiply(0.3);
ThreadLocalRandom tlr = ThreadLocalRandom.current();
double randOffset = 0.02;
vel.add(new Vector(
tlr.nextDouble(randOffset) - randOffset / 2,
tlr.nextDouble(0.12),
tlr.nextDouble(randOffset) - randOffset / 2));
dropItem.setVelocity(vel);
return dropItem;
}
代码示例来源:origin: GlowstoneMC/Glowstone
neighbor.add(new Vector(0, -1, 0)).toLocation(
location.getWorld())).getType().equals(Material.AIR)) {
continue;
neighbor.add(new Vector(0, 1, 0)).toLocation(
location.getWorld())).getType().isSolid()) {
continue;
代码示例来源:origin: GlowstoneMC/Glowstone
float dz = (float) branch.getZ() / maxDistance;
for (int i = 0; i <= maxDistance; i++) {
branch = base.clone().add(
new Vector(0.5 + i * dx, 0.5 + i * dy, 0.5 + i * dz));
int x = Math.abs(branch.getBlockX() - base.getBlockX());
代码示例来源:origin: GlowstoneMC/Glowstone
currentVelocity.add(rayLength);
entity.setVelocity(currentVelocity);
代码示例来源:origin: GlowstoneMC/Glowstone
currentVelocity.add(rayLength.multiply(((amount + 1) / 2d)));
setVelocity(currentVelocity);
代码示例来源:origin: GlowstoneMC/Glowstone
velocity.add(getGravityAccel());
location.add(getVelocity());
velocity.multiply(airDrag);
代码示例来源:origin: CitizensDev/CitizensAPI
@Override
public void run() {
Collection<NPC> nearby = flock.getNearby(npc);
if (nearby.isEmpty())
return;
Vector base = new Vector(0, 0, 0);
for (FlockBehavior behavior : behaviors) {
base.add(behavior.getVector(npc, nearby));
}
base = clip(maxForce, base);
npc.getEntity().setVelocity(npc.getEntity().getVelocity().add(base));
}
代码示例来源:origin: elBukkit/MagicPlugin
@Nullable
protected Vector getIntersection(double fDst1, double fDst2, Vector p1, Vector p2, int side) {
if ((fDst1 * fDst2) >= 0.0f) return null;
if (fDst1 == fDst2) return null;
Vector p2Clone = p2.clone();
p2Clone = p1.clone().add(p2Clone.subtract(p1).multiply(-fDst1 / (fDst2 - fDst1)));
return inBox(p2Clone, side) ? p2Clone : null;
}
代码示例来源:origin: CitizensDev/CitizensAPI
@Override
public float getCost(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
Material above = source.getMaterialAt(pos.clone().add(UP));
Material in = source.getMaterialAt(pos);
if (above == WEB || in == WEB) {
return 0.5F;
}
return 0F;
}
代码示例来源:origin: CitizensDev/CitizensAPI
@Override
public Vector getVector(NPC npc, Collection<NPC> nearby) {
Vector velocities = new Vector(0, 0, 0);
for (NPC neighbor : nearby) {
if (!neighbor.isSpawned())
continue;
velocities = velocities.add(neighbor.getEntity().getVelocity());
}
Vector desired = velocities.multiply((double) 1 / nearby.size());
return desired.subtract(npc.getEntity().getVelocity()).multiply(weight);
}
}
代码示例来源:origin: CitizensDev/CitizensAPI
@Override
public Vector getVector(NPC npc, Collection<NPC> nearby) {
Location dummy = new Location(null, 0, 0, 0);
Vector positions = new Vector(0, 0, 0);
for (NPC neighbor : nearby) {
if (!neighbor.isSpawned())
continue;
positions = positions.add(neighbor.getEntity().getLocation(dummy).toVector());
}
Vector center = positions.multiply((double) 1 / nearby.size());
return npc.getEntity().getLocation(dummy).toVector().subtract(center).multiply(weight);
}
内容来源于网络,如有侵权,请联系作者删除!