本文整理匯總了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()
}
}
}
}