本文整理汇总了Java中org.bukkit.util.Vector.length方法的典型用法代码示例。如果您正苦于以下问题:Java Vector.length方法的具体用法?Java Vector.length怎么用?Java Vector.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.util.Vector
的用法示例。
在下文中一共展示了Vector.length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: boost
import org.bukkit.util.Vector; //导入方法依赖的package包/类
private boolean boost(Entity source, Entity receiver) {
if (!(source instanceof Player) || !(receiver instanceof Player) || !isPlaying((Player) source) || !isPlaying((Player) receiver))
return false;
receiver.sendMessage(ChatColor.GREEN + "Whoosh!");
Vector toSender = source.getVelocity().subtract(receiver.getVelocity());
toSender.setY(0);
double distance = toSender.length();
if(distance > 0) {
toSender.multiply(1D / distance);
} else {
float yaw = source.getLocation().getYaw();
toSender.setX(-1 * Math.sin(toRad(yaw)));
toSender.setZ(Math.cos(toRad(yaw)));
}
toSender.multiply(2.5D);
toSender.setY(2);
receiver.setVelocity(toSender);
return true;
}
示例2: stepLocation
import org.bukkit.util.Vector; //导入方法依赖的package包/类
private void stepLocation(Entity ent, Location to, double blocksPerTick) {
if (!ent.isValid())
return;
Location from = ent.getLocation();
World world = from.getWorld();
Vector fv = new Vector(from.getX(), from.getY(), from.getZ());
Vector tv = new Vector(to.getX(), to.getY(), to.getZ());
double bpt = blocksPerTick;
Vector dv = new Vector(0d, 0d, 0d);
dv.add(tv);
dv.subtract(fv);
Vector nv = dv.clone();
nv.multiply(1 / dv.length() * bpt);
if (nv.length() > dv.length())
return;
nv.add(fv);
Location nl = new Location(world, nv.getX(), nv.getY(), nv.getZ());
nl.setDirection(dv);
ent.teleport(nl);
}
示例3: doBlockDrops
import org.bukkit.util.Vector; //导入方法依赖的package包/类
/**
* This is not an event handler. It is called explicitly by BlockTransformListener
* after all event handlers have been called.
*/
@SuppressWarnings("deprecation")
public void doBlockDrops(final BlockTransformEvent event) {
if(!causesDrops(event.getCause())) {
return;
}
final BlockDrops drops = event.getDrops();
if(drops != null) {
event.setCancelled(true);
final BlockState oldState = event.getOldState();
final BlockState newState = event.getNewState();
final Block block = event.getOldState().getBlock();
final int newTypeId = newState.getTypeId();
final byte newData = newState.getRawData();
block.setTypeIdAndData(newTypeId, newData, true);
boolean explosion = false;
MatchPlayer player = ParticipantBlockTransformEvent.getParticipant(event);
if(event.getCause() instanceof EntityExplodeEvent) {
EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
explosion = true;
if(drops.fallChance != null &&
oldState.getType().isBlock() &&
oldState.getType() != Material.AIR &&
this.getMatch().getRandom().nextFloat() < drops.fallChance) {
FallingBlock fallingBlock = event.getOldState().spawnFallingBlock();
fallingBlock.setDropItem(false);
if(drops.landChance != null && this.getMatch().getRandom().nextFloat() >= drops.landChance) {
this.fallingBlocksThatWillNotLand.add(fallingBlock);
}
Vector v = fallingBlock.getLocation().subtract(explodeEvent.getLocation()).toVector();
double distance = v.length();
v.normalize().multiply(BASE_FALL_SPEED * drops.fallSpeed / Math.max(1d, distance));
// A very simple deflection model. Check for a solid
// neighbor block and "bounce" the velocity off of it.
Block west = block.getRelative(BlockFace.WEST);
Block east = block.getRelative(BlockFace.EAST);
Block down = block.getRelative(BlockFace.DOWN);
Block up = block.getRelative(BlockFace.UP);
Block north = block.getRelative(BlockFace.NORTH);
Block south = block.getRelative(BlockFace.SOUTH);
if((v.getX() < 0 && west != null && Materials.isColliding(west.getType())) ||
v.getX() > 0 && east != null && Materials.isColliding(east.getType())) {
v.setX(-v.getX());
}
if((v.getY() < 0 && down != null && Materials.isColliding(down.getType())) ||
v.getY() > 0 && up != null && Materials.isColliding(up.getType())) {
v.setY(-v.getY());
}
if((v.getZ() < 0 && north != null && Materials.isColliding(north.getType())) ||
v.getZ() > 0 && south != null && Materials.isColliding(south.getType())) {
v.setZ(-v.getZ());
}
fallingBlock.setVelocity(v);
}
}
dropObjects(drops, player, newState.getLocation(), 1d, explosion);
}
}
示例4: getDirection
import org.bukkit.util.Vector; //导入方法依赖的package包/类
public static Vector getDirection(double x1, double y1, double x2, double y2) {
Vector vec = new Vector(x2 - x1, 0, y2 - y1);
if (vec.length() < 0.001)
return vec;
return vec.normalize();
}