本文整理匯總了Java中org.bukkit.util.Vector.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector.normalize方法的具體用法?Java Vector.normalize怎麽用?Java Vector.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.util.Vector
的用法示例。
在下文中一共展示了Vector.normalize方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyImpulses
import org.bukkit.util.Vector; //導入方法依賴的package包/類
private void applyImpulses(LivingEntity attacker) {
final KnockbackSettings knockback = this.knockback.get();
final Vector normal = victim.getLocation().subtract(attacker.getLocation()).toVector();
if(normal.isZero()) return;
normal.normalize();
final Vector victimNormal = knockback.pitchedNormal(normal);
final Vector attackerNormal = normal.times(-1);
if(victimNormal.isZero() || attackerNormal.isZero()) return;
final boolean ground = attacker.isOnGround();
final double attackSpeed = Math.max(0, attacker.getPredictedVelocity().dot(normal));
final boolean sprint = ground && attackSpeed > knockback.sprintThreshold;
victim.applyImpulse(victimNormal.multiply(knockback.power(sprint)), true);
attacker.applyImpulse(attackerNormal.multiply(knockback.recoil(ground) * attackSpeed), true);
final MatchPlayer matchAttacker = match.getPlayer(attacker);
if(matchAttacker != null) {
matchAttacker.facet(DamageDisplayPlayerFacet.class).showKnockback(victim, sprint);
}
}
示例2: repellExpOrb
import org.bukkit.util.Vector; //導入方法依賴的package包/類
final void repellExpOrb(final Player player, final ExperienceOrb orb) {
final Location pLoc = player.getLocation();
final Location oLoc = orb.getLocation();
final Vector dir = oLoc.toVector().subtract(pLoc.toVector());
final double dx = Math.abs(dir.getX());
final double dz = Math.abs(dir.getZ());
if ( (dx == 0.0) && (dz == 0.0)){
// Special case probably never happens
dir.setX(0.001);
}
if ((dx < 3.0) && (dz < 3.0)){
final Vector nDir = dir.normalize();
final Vector newV = nDir.clone().multiply(0.3);
newV.setY(0);
orb.setVelocity(newV);
if ((dx < 1.0) && (dz < 1.0)){
// maybe oLoc
orb.teleport(oLoc.clone().add(nDir.multiply(1.0)), TeleportCause.PLUGIN);
}
if ((dx < 0.5) && (dz < 0.5)){
orb.remove();
}
}
}
示例3: pitchedNormal
import org.bukkit.util.Vector; //導入方法依賴的package包/類
public Vector pitchedNormal(Vector delta) {
delta = delta.clone();
delta.setY(0);
if(delta.isZero()) return Vectors.ZERO;
delta.normalize();
final double theta = Math.toRadians(pitch);
final double cos = Math.cos(theta);
delta.set(cos * delta.getX(),
Math.sin(theta),
cos * delta.getZ());
return delta;
}
示例4: calculateVectorPath
import org.bukkit.util.Vector; //導入方法依賴的package包/類
public static ArrayList<Location> calculateVectorPath(Location start, Vector direction, int length, int spacing, boolean ignoreBlock) {
ArrayList<Location> locs = new ArrayList<Location>();
Location loc = start;
direction = direction.normalize();
length *= spacing;
direction = direction.multiply(1.0 / spacing);
for (int k = 0; k < length; k++) {
loc = loc.add(direction);
if (!ignoreBlock && !RParticles.isAirlike(loc.getBlock()))
break;
locs.add(loc.clone());
}
return locs;
}
示例5: 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();
}