Enchantment: more static getters, firehose magic numbers

This is similar in nature to 646fea5a4e.

On a side note: Migrating this way is a pain in the ass due to lack of types. What the heck is int supposed to mean?!?!?!?! At least if we wanted to go _back_ to magic numbers, it would be easy to locate everything with an Enchantment typehint...
This commit is contained in:
Dylan K. Taylor
2019-02-20 13:45:50 +00:00
parent 646fea5a4e
commit 7170d9009d
11 changed files with 111 additions and 31 deletions

View File

@ -441,14 +441,14 @@ abstract class Living extends Entity implements Damageable{
/**
* Returns the highest level of the specified enchantment on any armour piece that the entity is currently wearing.
*
* @param int $enchantmentId
* @param Enchantment $enchantment
*
* @return int
*/
public function getHighestArmorEnchantmentLevel(int $enchantmentId) : int{
public function getHighestArmorEnchantmentLevel(Enchantment $enchantment) : int{
$result = 0;
foreach($this->armorInventory->getContents() as $item){
$result = max($result, $item->getEnchantmentLevel($enchantmentId));
$result = max($result, $item->getEnchantmentLevel($enchantment));
}
return $result;
@ -462,7 +462,7 @@ abstract class Living extends Entity implements Damageable{
}
public function setOnFire(int $seconds) : void{
parent::setOnFire($seconds - (int) min($seconds, $seconds * $this->getHighestArmorEnchantmentLevel(Enchantment::FIRE_PROTECTION) * 0.15));
parent::setOnFire($seconds - (int) min($seconds, $seconds * $this->getHighestArmorEnchantmentLevel(Enchantment::FIRE_PROTECTION()) * 0.15));
}
/**
@ -507,7 +507,7 @@ abstract class Living extends Entity implements Damageable{
if($source instanceof EntityDamageByEntityEvent){
$damage = 0;
foreach($this->armorInventory->getContents() as $k => $item){
if($item instanceof Armor and ($thornsLevel = $item->getEnchantmentLevel(Enchantment::THORNS)) > 0){
if($item instanceof Armor and ($thornsLevel = $item->getEnchantmentLevel(Enchantment::THORNS())) > 0){
if(mt_rand(0, 99) < $thornsLevel * 15){
$this->damageItem($item, 3);
$damage += ($thornsLevel > 10 ? $thornsLevel - 10 : 1 + mt_rand(0, 3));
@ -577,7 +577,7 @@ abstract class Living extends Entity implements Damageable{
//TODO: knockback should not just apply for entity damage sources
//this doesn't matter for TNT right now because the PrimedTNT entity is considered the source, not the block.
$base = $source->getKnockBack();
$source->setKnockBack($base - min($base, $base * $this->getHighestArmorEnchantmentLevel(Enchantment::BLAST_PROTECTION) * 0.15));
$source->setKnockBack($base - min($base, $base * $this->getHighestArmorEnchantmentLevel(Enchantment::BLAST_PROTECTION()) * 0.15));
}
parent::attack($source);
@ -738,7 +738,7 @@ abstract class Living extends Entity implements Damageable{
if(!$this->canBreathe()){
$this->setBreathing(false);
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION())) <= 0 or
lcg_value() <= (1 / ($respirationLevel + 1))
){
$ticks -= $tickDiff;