Separate effect registry from base Effect class

This commit is contained in:
Dylan K. Taylor 2019-07-18 15:49:58 +01:00
parent 728aa8aae7
commit 64948f38d0
16 changed files with 209 additions and 280 deletions

View File

@ -25,8 +25,8 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\lang\TranslationContainer;
use pocketmine\utils\TextFormat;
use function count;
@ -68,10 +68,10 @@ class EffectCommand extends VanillaCommand{
return true;
}
$effect = Effect::fromString($args[1]);
$effect = VanillaEffects::fromString($args[1]);
if($effect === null){
$effect = Effect::get((int) $args[1]);
$effect = VanillaEffects::byMcpeId((int) $args[1]);
}
if($effect === null){

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\object\ExperienceOrb;
use pocketmine\entity\object\FallingBlock;
use pocketmine\entity\object\ItemEntity;
@ -98,7 +97,6 @@ final class EntityFactory{
self::register(Human::class, ['Human']);
Attribute::init();
Effect::init();
PaintingMotive::init();
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\entity\projectile\ProjectileSource;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\player\PlayerExhaustEvent;
@ -315,9 +315,9 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
if($totemModifier < 0){ //Totem prevented death
$this->effectManager->clear();
$this->effectManager->add(new EffectInstance(Effect::REGENERATION(), 40 * 20, 1));
$this->effectManager->add(new EffectInstance(Effect::FIRE_RESISTANCE(), 40 * 20, 1));
$this->effectManager->add(new EffectInstance(Effect::ABSORPTION(), 5 * 20, 1));
$this->effectManager->add(new EffectInstance(VanillaEffects::REGENERATION(), 40 * 20, 1));
$this->effectManager->add(new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 40 * 20, 1));
$this->effectManager->add(new EffectInstance(VanillaEffects::ABSORPTION(), 5 * 20, 1));
$this->broadcastEntityEvent(ActorEventPacket::CONSUME_TOTEM);
$this->world->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound());

View File

@ -24,9 +24,9 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\block\Block;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\EffectManager;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
@ -118,7 +118,7 @@ abstract class Living extends Entity{
$activeEffectsTag = $nbt->getListTag("ActiveEffects");
if($activeEffectsTag !== null){
foreach($activeEffectsTag as $e){
$effect = Effect::get($e->getByte("Id"));
$effect = VanillaEffects::byMcpeId($e->getByte("Id"));
if($effect === null){
continue;
}
@ -241,7 +241,7 @@ abstract class Living extends Entity{
* @return float
*/
public function getJumpVelocity() : float{
return $this->jumpVelocity + ($this->effectManager->has(Effect::JUMP_BOOST()) ? ($this->effectManager->get(Effect::JUMP_BOOST())->getEffectLevel() / 10) : 0);
return $this->jumpVelocity + ($this->effectManager->has(VanillaEffects::JUMP_BOOST()) ? ($this->effectManager->get(VanillaEffects::JUMP_BOOST())->getEffectLevel() / 10) : 0);
}
/**
@ -254,7 +254,7 @@ abstract class Living extends Entity{
}
public function fall(float $fallDistance) : void{
$damage = ceil($fallDistance - 3 - ($this->effectManager->has(Effect::JUMP_BOOST()) ? $this->effectManager->get(Effect::JUMP_BOOST())->getEffectLevel() : 0));
$damage = ceil($fallDistance - 3 - ($this->effectManager->has(VanillaEffects::JUMP_BOOST()) ? $this->effectManager->get(VanillaEffects::JUMP_BOOST())->getEffectLevel() : 0));
if($damage > 0){
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev);
@ -317,8 +317,8 @@ abstract class Living extends Entity{
}
$cause = $source->getCause();
if($this->effectManager->has(Effect::RESISTANCE()) and $cause !== EntityDamageEvent::CAUSE_VOID and $cause !== EntityDamageEvent::CAUSE_SUICIDE){
$source->setModifier(-$source->getFinalDamage() * min(1, 0.2 * $this->effectManager->get(Effect::RESISTANCE())->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
if($this->effectManager->has(VanillaEffects::RESISTANCE()) and $cause !== EntityDamageEvent::CAUSE_VOID and $cause !== EntityDamageEvent::CAUSE_SUICIDE){
$source->setModifier(-$source->getFinalDamage() * min(1, 0.2 * $this->effectManager->get(VanillaEffects::RESISTANCE())->getEffectLevel()), EntityDamageEvent::MODIFIER_RESISTANCE);
}
$totalEpf = 0;
@ -400,7 +400,7 @@ abstract class Living extends Entity{
}
}
if($this->effectManager->has(Effect::FIRE_RESISTANCE()) and (
if($this->effectManager->has(VanillaEffects::FIRE_RESISTANCE()) and (
$source->getCause() === EntityDamageEvent::CAUSE_FIRE
or $source->getCause() === EntityDamageEvent::CAUSE_FIRE_TICK
or $source->getCause() === EntityDamageEvent::CAUSE_LAVA
@ -590,7 +590,7 @@ abstract class Living extends Entity{
* @return bool
*/
public function canBreathe() : bool{
return $this->effectManager->has(Effect::WATER_BREATHING()) or $this->effectManager->has(Effect::CONDUIT_POWER()) or !$this->isUnderwater();
return $this->effectManager->has(VanillaEffects::WATER_BREATHING()) or $this->effectManager->has(VanillaEffects::CONDUIT_POWER()) or !$this->isUnderwater();
}
/**

View File

@ -26,212 +26,9 @@ namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\utils\Color;
use function constant;
use function defined;
use function strtoupper;
class Effect{
//TODO: remove our dependence on these magic numbers
public const SPEED = 1;
public const SLOWNESS = 2;
public const HASTE = 3;
public const FATIGUE = 4, MINING_FATIGUE = 4;
public const STRENGTH = 5;
public const INSTANT_HEALTH = 6, HEALING = 6;
public const INSTANT_DAMAGE = 7, HARMING = 7;
public const JUMP_BOOST = 8, JUMP = 8;
public const NAUSEA = 9, CONFUSION = 9;
public const REGENERATION = 10;
public const RESISTANCE = 11, DAMAGE_RESISTANCE = 11;
public const FIRE_RESISTANCE = 12;
public const WATER_BREATHING = 13;
public const INVISIBILITY = 14;
public const BLINDNESS = 15;
public const NIGHT_VISION = 16;
public const HUNGER = 17;
public const WEAKNESS = 18;
public const POISON = 19;
public const WITHER = 20;
public const HEALTH_BOOST = 21;
public const ABSORPTION = 22;
public const SATURATION = 23;
public const LEVITATION = 24; //TODO
public const FATAL_POISON = 25;
public const CONDUIT_POWER = 26;
public const SLOW_FALLING = 27;
public const BAD_OMEN = 28;
public const VILLAGE_HERO = 29;
/** @var Effect[] */
protected static $effects = [];
public static function init() : void{
self::register(new SpeedEffect(Effect::SPEED, "%potion.moveSpeed", new Color(0x7c, 0xaf, 0xc6)));
self::register(new SlownessEffect(Effect::SLOWNESS, "%potion.moveSlowdown", new Color(0x5a, 0x6c, 0x81), true));
self::register(new Effect(Effect::HASTE, "%potion.digSpeed", new Color(0xd9, 0xc0, 0x43)));
self::register(new Effect(Effect::MINING_FATIGUE, "%potion.digSlowDown", new Color(0x4a, 0x42, 0x17), true));
self::register(new Effect(Effect::STRENGTH, "%potion.damageBoost", new Color(0x93, 0x24, 0x23)));
self::register(new InstantHealthEffect(Effect::INSTANT_HEALTH, "%potion.heal", new Color(0xf8, 0x24, 0x23), false, false));
self::register(new InstantDamageEffect(Effect::INSTANT_DAMAGE, "%potion.harm", new Color(0x43, 0x0a, 0x09), true, false));
self::register(new Effect(Effect::JUMP_BOOST, "%potion.jump", new Color(0x22, 0xff, 0x4c)));
self::register(new Effect(Effect::NAUSEA, "%potion.confusion", new Color(0x55, 0x1d, 0x4a), true));
self::register(new RegenerationEffect(Effect::REGENERATION, "%potion.regeneration", new Color(0xcd, 0x5c, 0xab)));
self::register(new Effect(Effect::RESISTANCE, "%potion.resistance", new Color(0x99, 0x45, 0x3a)));
self::register(new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", new Color(0xe4, 0x9a, 0x3a)));
self::register(new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", new Color(0x2e, 0x52, 0x99)));
self::register(new InvisibilityEffect(Effect::INVISIBILITY, "%potion.invisibility", new Color(0x7f, 0x83, 0x92)));
self::register(new Effect(Effect::BLINDNESS, "%potion.blindness", new Color(0x1f, 0x1f, 0x23), true));
self::register(new Effect(Effect::NIGHT_VISION, "%potion.nightVision", new Color(0x1f, 0x1f, 0xa1)));
self::register(new HungerEffect(Effect::HUNGER, "%potion.hunger", new Color(0x58, 0x76, 0x53), true));
self::register(new Effect(Effect::WEAKNESS, "%potion.weakness", new Color(0x48, 0x4d, 0x48), true));
self::register(new PoisonEffect(Effect::POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true));
self::register(new WitherEffect(Effect::WITHER, "%potion.wither", new Color(0x35, 0x2a, 0x27), true));
self::register(new HealthBoostEffect(Effect::HEALTH_BOOST, "%potion.healthBoost", new Color(0xf8, 0x7d, 0x23)));
self::register(new AbsorptionEffect(Effect::ABSORPTION, "%potion.absorption", new Color(0x25, 0x52, 0xa5)));
self::register(new SaturationEffect(Effect::SATURATION, "%potion.saturation", new Color(0xf8, 0x24, 0x23), false));
self::register(new LevitationEffect(Effect::LEVITATION, "%potion.levitation", new Color(0xce, 0xff, 0xff)));
self::register(new PoisonEffect(Effect::FATAL_POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true, true, true));
self::register(new Effect(Effect::CONDUIT_POWER, "%potion.conduitPower", new Color(0x1d, 0xc2, 0xd1)));
}
//region --- auto-generated code ---
public static function ABSORPTION() : Effect{
return self::get(Effect::ABSORPTION);
}
public static function BLINDNESS() : Effect{
return self::get(Effect::BLINDNESS);
}
public static function CONDUIT_POWER() : Effect{
return self::get(Effect::CONDUIT_POWER);
}
public static function FATAL_POISON() : Effect{
return self::get(Effect::FATAL_POISON);
}
public static function FIRE_RESISTANCE() : Effect{
return self::get(Effect::FIRE_RESISTANCE);
}
public static function HASTE() : Effect{
return self::get(Effect::HASTE);
}
public static function HEALTH_BOOST() : Effect{
return self::get(Effect::HEALTH_BOOST);
}
public static function HUNGER() : Effect{
return self::get(Effect::HUNGER);
}
public static function INSTANT_DAMAGE() : Effect{
return self::get(Effect::INSTANT_DAMAGE);
}
public static function INSTANT_HEALTH() : Effect{
return self::get(Effect::INSTANT_HEALTH);
}
public static function INVISIBILITY() : Effect{
return self::get(Effect::INVISIBILITY);
}
public static function JUMP_BOOST() : Effect{
return self::get(Effect::JUMP_BOOST);
}
public static function LEVITATION() : Effect{
return self::get(Effect::LEVITATION);
}
public static function MINING_FATIGUE() : Effect{
return self::get(Effect::MINING_FATIGUE);
}
public static function NAUSEA() : Effect{
return self::get(Effect::NAUSEA);
}
public static function NIGHT_VISION() : Effect{
return self::get(Effect::NIGHT_VISION);
}
public static function POISON() : Effect{
return self::get(Effect::POISON);
}
public static function REGENERATION() : Effect{
return self::get(Effect::REGENERATION);
}
public static function RESISTANCE() : Effect{
return self::get(Effect::RESISTANCE);
}
public static function SATURATION() : Effect{
return self::get(Effect::SATURATION);
}
public static function SLOWNESS() : Effect{
return self::get(Effect::SLOWNESS);
}
public static function SPEED() : Effect{
return self::get(Effect::SPEED);
}
public static function STRENGTH() : Effect{
return self::get(Effect::STRENGTH);
}
public static function WATER_BREATHING() : Effect{
return self::get(Effect::WATER_BREATHING);
}
public static function WEAKNESS() : Effect{
return self::get(Effect::WEAKNESS);
}
public static function WITHER() : Effect{
return self::get(Effect::WITHER);
}
//endregion
/**
* @param Effect $effect
*/
public static function register(Effect $effect) : void{
self::$effects[$effect->getId()] = $effect;
}
/**
* @param int $id
*
* @return Effect|null
*/
public static function get(int $id) : ?Effect{
return self::$effects[$id] ?? null;
}
/**
* @param string $name
*
* @return Effect|null
*/
public static function fromString(string $name) : ?Effect{
$const = self::class . "::" . strtoupper($name);
if(defined($const)){
return self::get(constant($const));
}
return null;
}
/** @var int */
protected $id;
/** @var string */

View File

@ -0,0 +1,134 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\utils\Color;
use pocketmine\utils\RegistryTrait;
use function assert;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
*
* @method static AbsorptionEffect ABSORPTION()
* @method static Effect BLINDNESS()
* @method static Effect CONDUIT_POWER()
* @method static PoisonEffect FATAL_POISON()
* @method static Effect FIRE_RESISTANCE()
* @method static Effect HASTE()
* @method static HealthBoostEffect HEALTH_BOOST()
* @method static HungerEffect HUNGER()
* @method static InstantDamageEffect INSTANT_DAMAGE()
* @method static InstantHealthEffect INSTANT_HEALTH()
* @method static InvisibilityEffect INVISIBILITY()
* @method static Effect JUMP_BOOST()
* @method static LevitationEffect LEVITATION()
* @method static Effect MINING_FATIGUE()
* @method static Effect NAUSEA()
* @method static Effect NIGHT_VISION()
* @method static PoisonEffect POISON()
* @method static RegenerationEffect REGENERATION()
* @method static Effect RESISTANCE()
* @method static SaturationEffect SATURATION()
* @method static SlownessEffect SLOWNESS()
* @method static SpeedEffect SPEED()
* @method static Effect STRENGTH()
* @method static Effect WATER_BREATHING()
* @method static Effect WEAKNESS()
* @method static WitherEffect WITHER()
*/
final class VanillaEffects{
use RegistryTrait;
/** @var Effect[] */
private static $mcpeIdMap = [];
protected static function setup() : void{
self::register("absorption", new AbsorptionEffect(22, "%potion.absorption", new Color(0x25, 0x52, 0xa5)));
self::register("blindness", new Effect(15, "%potion.blindness", new Color(0x1f, 0x1f, 0x23), true));
self::register("conduit_power", new Effect(26, "%potion.conduitPower", new Color(0x1d, 0xc2, 0xd1)));
self::register("fatal_poison", new PoisonEffect(25, "%potion.poison", new Color(0x4e, 0x93, 0x31), true, true, true));
self::register("fire_resistance", new Effect(12, "%potion.fireResistance", new Color(0xe4, 0x9a, 0x3a)));
self::register("haste", new Effect(3, "%potion.digSpeed", new Color(0xd9, 0xc0, 0x43)));
self::register("health_boost", new HealthBoostEffect(21, "%potion.healthBoost", new Color(0xf8, 0x7d, 0x23)));
self::register("hunger", new HungerEffect(17, "%potion.hunger", new Color(0x58, 0x76, 0x53), true));
self::register("instant_damage", new InstantDamageEffect(7, "%potion.harm", new Color(0x43, 0x0a, 0x09), true, false));
self::register("instant_health", new InstantHealthEffect(6, "%potion.heal", new Color(0xf8, 0x24, 0x23), false, false));
self::register("invisibility", new InvisibilityEffect(14, "%potion.invisibility", new Color(0x7f, 0x83, 0x92)));
self::register("jump_boost", new Effect(8, "%potion.jump", new Color(0x22, 0xff, 0x4c)));
self::register("levitation", new LevitationEffect(24, "%potion.levitation", new Color(0xce, 0xff, 0xff)));
self::register("mining_fatigue", new Effect(4, "%potion.digSlowDown", new Color(0x4a, 0x42, 0x17), true));
self::register("nausea", new Effect(9, "%potion.confusion", new Color(0x55, 0x1d, 0x4a), true));
self::register("night_vision", new Effect(16, "%potion.nightVision", new Color(0x1f, 0x1f, 0xa1)));
self::register("poison", new PoisonEffect(19, "%potion.poison", new Color(0x4e, 0x93, 0x31), true));
self::register("regeneration", new RegenerationEffect(10, "%potion.regeneration", new Color(0xcd, 0x5c, 0xab)));
self::register("resistance", new Effect(11, "%potion.resistance", new Color(0x99, 0x45, 0x3a)));
self::register("saturation", new SaturationEffect(23, "%potion.saturation", new Color(0xf8, 0x24, 0x23), false));
self::register("slowness", new SlownessEffect(2, "%potion.moveSlowdown", new Color(0x5a, 0x6c, 0x81), true));
self::register("speed", new SpeedEffect(1, "%potion.moveSpeed", new Color(0x7c, 0xaf, 0xc6)));
self::register("strength", new Effect(5, "%potion.damageBoost", new Color(0x93, 0x24, 0x23)));
self::register("water_breathing", new Effect(13, "%potion.waterBreathing", new Color(0x2e, 0x52, 0x99)));
self::register("weakness", new Effect(18, "%potion.weakness", new Color(0x48, 0x4d, 0x48), true));
self::register("wither", new WitherEffect(20, "%potion.wither", new Color(0x35, 0x2a, 0x27), true));
}
protected static function register(string $name, Effect $member) : void{
self::_registryRegister($name, $member);
assert(!isset(self::$mcpeIdMap[$member->getId()]));
self::$mcpeIdMap[$member->getId()] = $member;
}
/**
* @param int $id
*
* @return Effect
*/
public static function byMcpeId(int $id) : Effect{
self::checkInit();
if(!isset(self::$mcpeIdMap[$id])){
throw new \InvalidArgumentException("No such effect with MCPE ID $id");
}
return self::$mcpeIdMap[$id];
}
/**
* @return Effect[]
*/
public static function getAll() : array{
return self::_registryGetAll();
}
/**
* @param string $name
*
* @return Effect
*/
public static function fromString(string $name) : Effect{
$result = self::_registryFromString($name);
assert($result instanceof Effect);
return $result;
}
}

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\event\entity;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
@ -54,12 +54,12 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
protected function addAttackerModifiers(Entity $damager) : void{
if($damager instanceof Living){ //TODO: move this to entity classes
$effects = $damager->getEffects();
if($effects->has(Effect::STRENGTH())){
$this->setModifier($this->getBaseDamage() * 0.3 * $effects->get(Effect::STRENGTH())->getEffectLevel(), self::MODIFIER_STRENGTH);
if($effects->has(VanillaEffects::STRENGTH())){
$this->setModifier($this->getBaseDamage() * 0.3 * $effects->get(VanillaEffects::STRENGTH())->getEffectLevel(), self::MODIFIER_STRENGTH);
}
if($effects->has(Effect::WEAKNESS())){
$this->setModifier(-($this->getBaseDamage() * 0.2 * $effects->get(Effect::WEAKNESS())->getEffectLevel()), self::MODIFIER_WEAKNESS);
if($effects->has(VanillaEffects::WEAKNESS())){
$this->setModifier(-($this->getBaseDamage() * 0.2 * $effects->get(VanillaEffects::WEAKNESS())->getEffectLevel()), self::MODIFIER_WEAKNESS);
}
}
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
class GoldenApple extends Food{
@ -42,8 +42,8 @@ class GoldenApple extends Food{
public function getAdditionalEffects() : array{
return [
new EffectInstance(Effect::REGENERATION(), 100, 1),
new EffectInstance(Effect::ABSORPTION(), 2400)
new EffectInstance(VanillaEffects::REGENERATION(), 100, 1),
new EffectInstance(VanillaEffects::ABSORPTION(), 2400)
];
}
}

View File

@ -23,17 +23,17 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
class GoldenAppleEnchanted extends GoldenApple{
public function getAdditionalEffects() : array{
return [
new EffectInstance(Effect::REGENERATION(), 600, 4),
new EffectInstance(Effect::ABSORPTION(), 2400, 3),
new EffectInstance(Effect::RESISTANCE(), 6000),
new EffectInstance(Effect::FIRE_RESISTANCE(), 6000)
new EffectInstance(VanillaEffects::REGENERATION(), 600, 4),
new EffectInstance(VanillaEffects::ABSORPTION(), 2400, 3),
new EffectInstance(VanillaEffects::RESISTANCE(), 6000),
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 6000)
];
}
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use function mt_rand;
class PoisonousPotato extends Food{
@ -40,7 +40,7 @@ class PoisonousPotato extends Food{
public function getAdditionalEffects() : array{
if(mt_rand(0, 100) > 40){
return [
new EffectInstance(Effect::POISON(), 100)
new EffectInstance(VanillaEffects::POISON(), 100)
];
}
return [];

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\entity\Living;
class Potion extends Item implements Consumable{
@ -124,131 +124,131 @@ class Potion extends Item implements Consumable{
return [];
case self::NIGHT_VISION:
return [
new EffectInstance(Effect::NIGHT_VISION(), 3600)
new EffectInstance(VanillaEffects::NIGHT_VISION(), 3600)
];
case self::LONG_NIGHT_VISION:
return [
new EffectInstance(Effect::NIGHT_VISION(), 9600)
new EffectInstance(VanillaEffects::NIGHT_VISION(), 9600)
];
case self::INVISIBILITY:
return [
new EffectInstance(Effect::INVISIBILITY(), 3600)
new EffectInstance(VanillaEffects::INVISIBILITY(), 3600)
];
case self::LONG_INVISIBILITY:
return [
new EffectInstance(Effect::INVISIBILITY(), 9600)
new EffectInstance(VanillaEffects::INVISIBILITY(), 9600)
];
case self::LEAPING:
return [
new EffectInstance(Effect::JUMP_BOOST(), 3600)
new EffectInstance(VanillaEffects::JUMP_BOOST(), 3600)
];
case self::LONG_LEAPING:
return [
new EffectInstance(Effect::JUMP_BOOST(), 9600)
new EffectInstance(VanillaEffects::JUMP_BOOST(), 9600)
];
case self::STRONG_LEAPING:
return [
new EffectInstance(Effect::JUMP_BOOST(), 1800, 1)
new EffectInstance(VanillaEffects::JUMP_BOOST(), 1800, 1)
];
case self::FIRE_RESISTANCE:
return [
new EffectInstance(Effect::FIRE_RESISTANCE(), 3600)
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 3600)
];
case self::LONG_FIRE_RESISTANCE:
return [
new EffectInstance(Effect::FIRE_RESISTANCE(), 9600)
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 9600)
];
case self::SWIFTNESS:
return [
new EffectInstance(Effect::SPEED(), 3600)
new EffectInstance(VanillaEffects::SPEED(), 3600)
];
case self::LONG_SWIFTNESS:
return [
new EffectInstance(Effect::SPEED(), 9600)
new EffectInstance(VanillaEffects::SPEED(), 9600)
];
case self::STRONG_SWIFTNESS:
return [
new EffectInstance(Effect::SPEED(), 1800, 1)
new EffectInstance(VanillaEffects::SPEED(), 1800, 1)
];
case self::SLOWNESS:
return [
new EffectInstance(Effect::SLOWNESS(), 1800)
new EffectInstance(VanillaEffects::SLOWNESS(), 1800)
];
case self::LONG_SLOWNESS:
return [
new EffectInstance(Effect::SLOWNESS(), 4800)
new EffectInstance(VanillaEffects::SLOWNESS(), 4800)
];
case self::WATER_BREATHING:
return [
new EffectInstance(Effect::WATER_BREATHING(), 3600)
new EffectInstance(VanillaEffects::WATER_BREATHING(), 3600)
];
case self::LONG_WATER_BREATHING:
return [
new EffectInstance(Effect::WATER_BREATHING(), 9600)
new EffectInstance(VanillaEffects::WATER_BREATHING(), 9600)
];
case self::HEALING:
return [
new EffectInstance(Effect::INSTANT_HEALTH())
new EffectInstance(VanillaEffects::INSTANT_HEALTH())
];
case self::STRONG_HEALING:
return [
new EffectInstance(Effect::INSTANT_HEALTH(), null, 1)
new EffectInstance(VanillaEffects::INSTANT_HEALTH(), null, 1)
];
case self::HARMING:
return [
new EffectInstance(Effect::INSTANT_DAMAGE())
new EffectInstance(VanillaEffects::INSTANT_DAMAGE())
];
case self::STRONG_HARMING:
return [
new EffectInstance(Effect::INSTANT_DAMAGE(), null, 1)
new EffectInstance(VanillaEffects::INSTANT_DAMAGE(), null, 1)
];
case self::POISON:
return [
new EffectInstance(Effect::POISON(), 900)
new EffectInstance(VanillaEffects::POISON(), 900)
];
case self::LONG_POISON:
return [
new EffectInstance(Effect::POISON(), 2400)
new EffectInstance(VanillaEffects::POISON(), 2400)
];
case self::STRONG_POISON:
return [
new EffectInstance(Effect::POISON(), 440, 1)
new EffectInstance(VanillaEffects::POISON(), 440, 1)
];
case self::REGENERATION:
return [
new EffectInstance(Effect::REGENERATION(), 900)
new EffectInstance(VanillaEffects::REGENERATION(), 900)
];
case self::LONG_REGENERATION:
return [
new EffectInstance(Effect::REGENERATION(), 2400)
new EffectInstance(VanillaEffects::REGENERATION(), 2400)
];
case self::STRONG_REGENERATION:
return [
new EffectInstance(Effect::REGENERATION(), 440, 1)
new EffectInstance(VanillaEffects::REGENERATION(), 440, 1)
];
case self::STRENGTH:
return [
new EffectInstance(Effect::STRENGTH(), 3600)
new EffectInstance(VanillaEffects::STRENGTH(), 3600)
];
case self::LONG_STRENGTH:
return [
new EffectInstance(Effect::STRENGTH(), 9600)
new EffectInstance(VanillaEffects::STRENGTH(), 9600)
];
case self::STRONG_STRENGTH:
return [
new EffectInstance(Effect::STRENGTH(), 1800, 1)
new EffectInstance(VanillaEffects::STRENGTH(), 1800, 1)
];
case self::WEAKNESS:
return [
new EffectInstance(Effect::WEAKNESS(), 1800)
new EffectInstance(VanillaEffects::WEAKNESS(), 1800)
];
case self::LONG_WEAKNESS:
return [
new EffectInstance(Effect::WEAKNESS(), 4800)
new EffectInstance(VanillaEffects::WEAKNESS(), 4800)
];
case self::WITHER:
return [
new EffectInstance(Effect::WITHER(), 800, 1)
new EffectInstance(VanillaEffects::WITHER(), 800, 1)
];
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
class Pufferfish extends Food{
@ -38,9 +38,9 @@ class Pufferfish extends Food{
public function getAdditionalEffects() : array{
return [
new EffectInstance(Effect::HUNGER(), 300, 2),
new EffectInstance(Effect::POISON(), 1200, 3),
new EffectInstance(Effect::NAUSEA(), 300, 1)
new EffectInstance(VanillaEffects::HUNGER(), 300, 2),
new EffectInstance(VanillaEffects::POISON(), 1200, 3),
new EffectInstance(VanillaEffects::NAUSEA(), 300, 1)
];
}
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use function mt_rand;
class RawChicken extends Food{
@ -38,6 +38,6 @@ class RawChicken extends Food{
}
public function getAdditionalEffects() : array{
return mt_rand(0, 9) < 3 ? [new EffectInstance(Effect::HUNGER(), 600)] : [];
return mt_rand(0, 9) < 3 ? [new EffectInstance(VanillaEffects::HUNGER(), 600)] : [];
}
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use function lcg_value;
class RottenFlesh extends Food{
@ -40,7 +40,7 @@ class RottenFlesh extends Food{
public function getAdditionalEffects() : array{
if(lcg_value() <= 0.8){
return [
new EffectInstance(Effect::HUNGER(), 600)
new EffectInstance(VanillaEffects::HUNGER(), 600)
];
}

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
class SpiderEye extends Food{
@ -37,6 +37,6 @@ class SpiderEye extends Food{
}
public function getAdditionalEffects() : array{
return [new EffectInstance(Effect::POISON(), 80)];
return [new EffectInstance(VanillaEffects::POISON(), 80)];
}
}

View File

@ -29,8 +29,8 @@ use pocketmine\block\UnknownBlock;
use pocketmine\block\VanillaBlocks;
use pocketmine\command\CommandSender;
use pocketmine\crafting\CraftingGrid;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\entity\Entity;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Human;
@ -1884,7 +1884,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
}
$ev->setModifier($meleeEnchantmentDamage, EntityDamageEvent::MODIFIER_WEAPON_ENCHANTMENTS);
if(!$this->isSprinting() and !$this->isFlying() and $this->fallDistance > 0 and !$this->effectManager->has(Effect::BLINDNESS()) and !$this->isUnderwater()){
if(!$this->isSprinting() and !$this->isFlying() and $this->fallDistance > 0 and !$this->effectManager->has(VanillaEffects::BLINDNESS()) and !$this->isUnderwater()){
$ev->setModifier($ev->getFinalDamage() / 2, EntityDamageEvent::MODIFIER_CRITICAL);
}