Implemented critical hits (#1929)

This commit is contained in:
Encritary
2018-02-19 15:14:32 +05:00
committed by Dylan K. Taylor
parent cbbed6a6c1
commit ad8d67137e
2 changed files with 15 additions and 0 deletions

View File

@@ -2411,6 +2411,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$ev->setCancelled();
}
if(!$this->isSprinting() and !$this->isFlying() and $this->fallDistance > 0 and !$this->hasEffect(Effect::BLINDNESS) and !$this->isInsideOfWater()){
$ev->setDamage($ev->getFinalDamage() / 2, EntityDamageEvent::MODIFIER_CRITICAL);
}
$target->attack($ev);
if($ev->isCancelled()){
@@ -2420,6 +2424,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
return true;
}
if($ev->getDamage(EntityDamageEvent::MODIFIER_CRITICAL) > 0){
$pk = new AnimatePacket();
$pk->action = AnimatePacket::ACTION_CRITICAL_HIT;
$pk->entityRuntimeId = $target->getId();
$this->server->broadcastPacket($target->getViewers(), $pk);
if($target instanceof Player){
$target->dataPacket($pk);
}
}
if($this->isSurvival()){
if($heldItem->useOn($target)){
$this->inventory->setItemInHand($heldItem);