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


Java Player.getVelocity方法代码示例

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


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

示例1: onPlayerJump

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJump(PlayerMoveEvent event) {
    Player player = event.getPlayer();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    Vector velocity = player.getVelocity();
    Modifier jumpModifier = ItemManager.getModifier(player, ItemStat.StatType.JUMP);

    if (jumpModifier.getBonus() == 0 && jumpModifier.getMultiplier() == 1) {
        return;
    }

    // === START: Magic constants ===
    if (velocity.getY() == 0.41999998688697815D) {
        double jump = (1.5 + Math.sqrt(jumpModifier.getBonus())) * jumpModifier.getMultiplier();
        Vector moveDirection = event.getTo().toVector().subtract(event.getFrom().toVector());
        velocity.setX(moveDirection.getX() * jump * player.getWalkSpeed());
        velocity.setY(velocity.getY() * jump / 1.5);
        velocity.setZ(moveDirection.getZ() * jump * player.getWalkSpeed());
        player.setVelocity(velocity);
    }
    // === END: Magic constants ===
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:27,代码来源:ItemListener.java

示例2: onBlockBreak

import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
public void onBlockBreak(BlockPlaceEvent event) {
    if (event.isCancelled()) {
        Player player = event.getPlayer();
        if (player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) {
            return;
        }

        Block block = event.getBlockPlaced();
        if (block.getType().isSolid() && !(block.getState() instanceof Sign)) {
            int playerY = player.getLocation().getBlockY();
            int blockY = block.getLocation().getBlockY();
            if (playerY > blockY) {
                Vector vector = player.getVelocity();
                vector.setX(-0.1);
                vector.setZ(-0.1);
                player.setVelocity(vector.setY(vector.getY() - 0.41999998688697815D)); // Magic number acquired from EntityLiving#bj()
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:22,代码来源:BlockJumpGlitchFixListener.java


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