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

View File

@ -39,6 +39,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
public const MODIFIER_RESISTANCE = 4;
public const MODIFIER_ABSORPTION = 5;
public const MODIFIER_ARMOR_ENCHANTMENTS = 6;
public const MODIFIER_CRITICAL = 7;
public const CAUSE_CONTACT = 0;
public const CAUSE_ENTITY_ATTACK = 1;