本文整理汇总了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 ===
}
示例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()
}
}
}
}