当前位置: 首页>>代码示例>>Java>>正文


Java NumberConversions.square方法代码示例

本文整理汇总了Java中org.bukkit.util.NumberConversions.square方法的典型用法代码示例。如果您正苦于以下问题:Java NumberConversions.square方法的具体用法?Java NumberConversions.square怎么用?Java NumberConversions.square使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.util.NumberConversions的用法示例。


在下文中一共展示了NumberConversions.square方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setDirection

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:33,代码来源:Location.java

示例2: distanceSquared

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * Get the squared distance between this location and another.
 *
 * @see Vector
 * @param o The other location
 * @return the distance
 * @throws IllegalArgumentException for differing worlds
 */
public double distanceSquared(Location o) {
    if (o == null) {
        throw new IllegalArgumentException("Cannot measure distance to a null location");
    } else if (o.getWorld() == null || getWorld() == null) {
        throw new IllegalArgumentException("Cannot measure distance to a null world");
    } else if (o.getWorld() != getWorld()) {
        throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getName() + " and " + o.getWorld().getName());
    }

    return NumberConversions.square(x - o.x) + NumberConversions.square(y - o.y) + NumberConversions.square(z - o.z);
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:20,代码来源:Location.java

示例3: a

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
public void a(PacketPlayInUseItem packetplayinuseitem) {
    PlayerConnectionUtils.ensureMainThread(packetplayinuseitem, this, this.player.x());
    if (this.player.dead) return; // CraftBukkit
    WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
    EnumHand enumhand = packetplayinuseitem.c();
    ItemStack itemstack = this.player.b(enumhand);
    BlockPosition blockposition = packetplayinuseitem.a();
    EnumDirection enumdirection = packetplayinuseitem.b();

    this.player.resetIdleTimer();
    if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) {
        ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())});

        chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
        this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
    } else if (this.teleportPos == null && this.player.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
        // CraftBukkit start - Check if we can actually do something over this large a distance
        Location eyeLoc = this.getPlayer().getEyeLocation();
        double reachDistance = NumberConversions.square(eyeLoc.getX() - blockposition.getX()) + NumberConversions.square(eyeLoc.getY() - blockposition.getY()) + NumberConversions.square(eyeLoc.getZ() - blockposition.getZ());
        if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) {
            return;
        }
        // CraftBukkit end
        this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, blockposition, enumdirection, packetplayinuseitem.d(), packetplayinuseitem.e(), packetplayinuseitem.f());
    }

    this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition));
    this.player.playerConnection.sendPacket(new PacketPlayOutBlockChange(worldserver, blockposition.shift(enumdirection)));
    itemstack = this.player.b(enumhand);
    if (itemstack != null && itemstack.count == 0) {
        this.player.a(enumhand, (ItemStack) null);
        itemstack = null;
    }

}
 
开发者ID:bergerkiller,项目名称:SpigotSource,代码行数:36,代码来源:PlayerConnection.java

示例4: distance

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
public double distance(DemigodsLocation location) {
    if (location != null) {
        double squared = NumberConversions.square(X - location.X) + NumberConversions.square(Y - location.Y) + NumberConversions.square(Z = location.Z);
        return Math.sqrt(squared);
    }
    throw new NullPointerException("Cannot measure distance to a null location.");
}
 
开发者ID:DemigodsRPG,项目名称:Demigods3,代码行数:8,代码来源:DemigodsLocation.java

示例5: run

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
@Override
public void run()
{
    final Location playerLocation = player.getLocation();


    // Checks if the player is still on the line

    Vector position   = playerLocation.toVector();
    Vector origin     = getStart().toVector();
    Vector director   = yodel.getAngleVector();
    double k;

    if (isZero(origin)) origin = getEnd().toVector();

    try
    {
        k = director.getX() * (position.getX() - origin.getX())
                + director.getY() * (position.getY() - origin.getY())
                + director.getZ() * (position.getZ() - origin.getZ());

        k /= NumberConversions.square(director.getX())
                + NumberConversions.square(director.getY())
                + NumberConversions.square(director.getZ());
    }
    catch (ArithmeticException e)
    {
        this.hub.getLogger().log(Level.SEVERE, "Division by zero while checking route on yodel, remains unfixed", e);
        return;
    }

    Vector projection = origin.add(director.multiply(k));

    if (projection.distanceSquared(position) > 4)
    {
        player.teleport(projection.toLocation(playerLocation.getWorld()).setDirection(playerLocation.getDirection()));
    }


    // Updates the velocity

    player.setVelocity(velocityStep);
    player.setFallDistance(0);


    // Checks if the line is finished (either we are on the finish zone, or out of the path if for some
    // reason the landing zone was not entered)

    if (playerLocation.distanceSquared(getEnd()) < 6
            || playerLocation.distanceSquared(getStart()) > yodel.getLength() + 10)
    {
        this.yodel.stop(player);
    }
}
 
开发者ID:SamaGames,项目名称:Hub,代码行数:55,代码来源:YodelRunner.java

示例6: isInSphere

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * Returns whether this vector is within a sphere.
 *
 * @param origin sphere origin
 * @param radius sphere radius
 *
 * @return whether this vector is in the sphere
 */
public boolean isInSphere(ImmutableVector origin, double radius) {
  return origin != null
         && NumberConversions.square(origin.x - this.x)
            + NumberConversions.square(origin.y - this.y)
            + NumberConversions.square(origin.z - this.z) <= NumberConversions.square(radius);
}
 
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:15,代码来源:ImmutableVector.java

示例7: lengthSquared

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * Gets the magnitude of the location squared. Not world-aware and
 * orientation independent.
 *
 * @see Vector
 * @return the magnitude
 */
public double lengthSquared() {
    return NumberConversions.square(x) + NumberConversions.square(y) + NumberConversions.square(z);
}
 
开发者ID:CyberdyneCC,项目名称:Thermos-Bukkit,代码行数:11,代码来源:Location.java

示例8: lengthSquared

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * Returns the magnitude of this vector squared.
 *
 * @return the squared magnitude
 */
public double lengthSquared() {
  return NumberConversions.square(this.x) + NumberConversions.square(this.y)
         + NumberConversions.square(this.z);
}
 
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:10,代码来源:ImmutableVector.java

示例9: distanceSquared

import org.bukkit.util.NumberConversions; //导入方法依赖的package包/类
/**
 * Returns the squared distance between this vector and another {@link ImmutableVector}.
 *
 * @param o the other vector
 *
 * @return the distance
 */
public double distanceSquared(ImmutableVector o) {
  return NumberConversions.square(this.x - o.x)
         + NumberConversions.square(this.y - o.y)
         + NumberConversions.square(this.z - o.z);
}
 
开发者ID:SupaHam,项目名称:SupaCommons,代码行数:13,代码来源:ImmutableVector.java


注:本文中的org.bukkit.util.NumberConversions.square方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。