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


Java Vector.length方法代码示例

本文整理汇总了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;
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:20,代码来源:Boost.java

示例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);
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:25,代码来源:ActionEntityPathfind.java

示例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);

    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:77,代码来源:BlockDropsMatchModule.java

示例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();
}
 
开发者ID:SamaGames,项目名称:AgarMC,代码行数:7,代码来源:Utils.java


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