mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
Move potion types to enum
This commit is contained in:
parent
908fa5f901
commit
5387456e44
99
src/data/bedrock/PotionTypeIdMap.php
Normal file
99
src/data/bedrock/PotionTypeIdMap.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?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\data\bedrock;
|
||||
|
||||
use pocketmine\item\PotionType;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
|
||||
final class PotionTypeIdMap{
|
||||
use SingletonTrait;
|
||||
|
||||
/**
|
||||
* @var PotionType[]
|
||||
* @phpstan-var array<int, PotionType>
|
||||
*/
|
||||
private array $idToEnum;
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
* @phpstan-var array<int, int>
|
||||
*/
|
||||
private array $enumToId;
|
||||
|
||||
private function __construct(){
|
||||
$this->register(PotionTypeIds::WATER, PotionType::WATER());
|
||||
$this->register(PotionTypeIds::MUNDANE, PotionType::MUNDANE());
|
||||
$this->register(PotionTypeIds::LONG_MUNDANE, PotionType::LONG_MUNDANE());
|
||||
$this->register(PotionTypeIds::THICK, PotionType::THICK());
|
||||
$this->register(PotionTypeIds::AWKWARD, PotionType::AWKWARD());
|
||||
$this->register(PotionTypeIds::NIGHT_VISION, PotionType::NIGHT_VISION());
|
||||
$this->register(PotionTypeIds::LONG_NIGHT_VISION, PotionType::LONG_NIGHT_VISION());
|
||||
$this->register(PotionTypeIds::INVISIBILITY, PotionType::INVISIBILITY());
|
||||
$this->register(PotionTypeIds::LONG_INVISIBILITY, PotionType::LONG_INVISIBILITY());
|
||||
$this->register(PotionTypeIds::LEAPING, PotionType::LEAPING());
|
||||
$this->register(PotionTypeIds::LONG_LEAPING, PotionType::LONG_LEAPING());
|
||||
$this->register(PotionTypeIds::STRONG_LEAPING, PotionType::STRONG_LEAPING());
|
||||
$this->register(PotionTypeIds::FIRE_RESISTANCE, PotionType::FIRE_RESISTANCE());
|
||||
$this->register(PotionTypeIds::LONG_FIRE_RESISTANCE, PotionType::LONG_FIRE_RESISTANCE());
|
||||
$this->register(PotionTypeIds::SWIFTNESS, PotionType::SWIFTNESS());
|
||||
$this->register(PotionTypeIds::LONG_SWIFTNESS, PotionType::LONG_SWIFTNESS());
|
||||
$this->register(PotionTypeIds::STRONG_SWIFTNESS, PotionType::STRONG_SWIFTNESS());
|
||||
$this->register(PotionTypeIds::SLOWNESS, PotionType::SLOWNESS());
|
||||
$this->register(PotionTypeIds::LONG_SLOWNESS, PotionType::LONG_SLOWNESS());
|
||||
$this->register(PotionTypeIds::WATER_BREATHING, PotionType::WATER_BREATHING());
|
||||
$this->register(PotionTypeIds::LONG_WATER_BREATHING, PotionType::LONG_WATER_BREATHING());
|
||||
$this->register(PotionTypeIds::HEALING, PotionType::HEALING());
|
||||
$this->register(PotionTypeIds::STRONG_HEALING, PotionType::STRONG_HEALING());
|
||||
$this->register(PotionTypeIds::HARMING, PotionType::HARMING());
|
||||
$this->register(PotionTypeIds::STRONG_HARMING, PotionType::STRONG_HARMING());
|
||||
$this->register(PotionTypeIds::POISON, PotionType::POISON());
|
||||
$this->register(PotionTypeIds::LONG_POISON, PotionType::LONG_POISON());
|
||||
$this->register(PotionTypeIds::STRONG_POISON, PotionType::STRONG_POISON());
|
||||
$this->register(PotionTypeIds::REGENERATION, PotionType::REGENERATION());
|
||||
$this->register(PotionTypeIds::LONG_REGENERATION, PotionType::LONG_REGENERATION());
|
||||
$this->register(PotionTypeIds::STRONG_REGENERATION, PotionType::STRONG_REGENERATION());
|
||||
$this->register(PotionTypeIds::STRENGTH, PotionType::STRENGTH());
|
||||
$this->register(PotionTypeIds::LONG_STRENGTH, PotionType::LONG_STRENGTH());
|
||||
$this->register(PotionTypeIds::STRONG_STRENGTH, PotionType::STRONG_STRENGTH());
|
||||
$this->register(PotionTypeIds::WEAKNESS, PotionType::WEAKNESS());
|
||||
$this->register(PotionTypeIds::LONG_WEAKNESS, PotionType::LONG_WEAKNESS());
|
||||
$this->register(PotionTypeIds::WITHER, PotionType::WITHER());
|
||||
}
|
||||
|
||||
private function register(int $id, PotionType $type) : void{
|
||||
$this->idToEnum[$id] = $type;
|
||||
$this->enumToId[$type->id()] = $id;
|
||||
}
|
||||
|
||||
public function fromId(int $id) : ?PotionType{
|
||||
return $this->idToEnum[$id] ?? null;
|
||||
}
|
||||
|
||||
public function toId(PotionType $type) : int{
|
||||
if(!isset($this->enumToId[$type->id()])){
|
||||
throw new \InvalidArgumentException("Type does not have a mapped ID");
|
||||
}
|
||||
return $this->enumToId[$type->id()];
|
||||
}
|
||||
}
|
64
src/data/bedrock/PotionTypeIds.php
Normal file
64
src/data/bedrock/PotionTypeIds.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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\data\bedrock;
|
||||
|
||||
final class PotionTypeIds{
|
||||
public const WATER = 0;
|
||||
public const MUNDANE = 1;
|
||||
public const LONG_MUNDANE = 2;
|
||||
public const THICK = 3;
|
||||
public const AWKWARD = 4;
|
||||
public const NIGHT_VISION = 5;
|
||||
public const LONG_NIGHT_VISION = 6;
|
||||
public const INVISIBILITY = 7;
|
||||
public const LONG_INVISIBILITY = 8;
|
||||
public const LEAPING = 9;
|
||||
public const LONG_LEAPING = 10;
|
||||
public const STRONG_LEAPING = 11;
|
||||
public const FIRE_RESISTANCE = 12;
|
||||
public const LONG_FIRE_RESISTANCE = 13;
|
||||
public const SWIFTNESS = 14;
|
||||
public const LONG_SWIFTNESS = 15;
|
||||
public const STRONG_SWIFTNESS = 16;
|
||||
public const SLOWNESS = 17;
|
||||
public const LONG_SLOWNESS = 18;
|
||||
public const WATER_BREATHING = 19;
|
||||
public const LONG_WATER_BREATHING = 20;
|
||||
public const HEALING = 21;
|
||||
public const STRONG_HEALING = 22;
|
||||
public const HARMING = 23;
|
||||
public const STRONG_HARMING = 24;
|
||||
public const POISON = 25;
|
||||
public const LONG_POISON = 26;
|
||||
public const STRONG_POISON = 27;
|
||||
public const REGENERATION = 28;
|
||||
public const LONG_REGENERATION = 29;
|
||||
public const STRONG_REGENERATION = 30;
|
||||
public const STRENGTH = 31;
|
||||
public const LONG_STRENGTH = 32;
|
||||
public const STRONG_STRENGTH = 33;
|
||||
public const WEAKNESS = 34;
|
||||
public const LONG_WEAKNESS = 35;
|
||||
public const WITHER = 36;
|
||||
}
|
@ -28,6 +28,8 @@ use DaveRandom\CallbackValidator\ParameterType;
|
||||
use DaveRandom\CallbackValidator\ReturnType;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\data\bedrock\EntityLegacyIds;
|
||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||
use pocketmine\data\bedrock\PotionTypeIds;
|
||||
use pocketmine\entity\object\ExperienceOrb;
|
||||
use pocketmine\entity\object\FallingBlock;
|
||||
use pocketmine\entity\object\ItemEntity;
|
||||
@ -41,7 +43,7 @@ use pocketmine\entity\projectile\ExperienceBottle;
|
||||
use pocketmine\entity\projectile\Snowball;
|
||||
use pocketmine\entity\projectile\SplashPotion;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Potion;
|
||||
use pocketmine\item\PotionType;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\NbtDataException;
|
||||
@ -148,7 +150,10 @@ final class EntityFactory{
|
||||
}, ['Snowball', 'minecraft:snowball'], EntityLegacyIds::SNOWBALL);
|
||||
|
||||
$this->register(SplashPotion::class, function(World $world, CompoundTag $nbt) : SplashPotion{
|
||||
$potionType = $nbt->getShort("PotionId", Potion::WATER);
|
||||
$potionType = PotionTypeIdMap::getInstance()->fromId($nbt->getShort("PotionId", PotionTypeIds::WATER));
|
||||
if($potionType === null){
|
||||
$potionType = PotionType::WATER(); //TODO: this should be an error, but we haven't registered all the types yet
|
||||
}
|
||||
return new SplashPotion(EntityDataHelper::parseLocation($nbt, $world), null, $potionType, $nbt);
|
||||
}, ['ThrownPotion', 'minecraft:potion', 'thrownpotion'], EntityLegacyIds::SPLASH_POTION);
|
||||
|
||||
|
@ -26,6 +26,7 @@ namespace pocketmine\entity\projectile;
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\color\Color;
|
||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||
use pocketmine\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\effect\InstantEffect;
|
||||
use pocketmine\entity\Entity;
|
||||
@ -35,6 +36,7 @@ use pocketmine\event\entity\ProjectileHitBlockEvent;
|
||||
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
||||
use pocketmine\event\entity\ProjectileHitEvent;
|
||||
use pocketmine\item\Potion;
|
||||
use pocketmine\item\PotionType;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||
@ -55,17 +57,16 @@ class SplashPotion extends Throwable{
|
||||
|
||||
/** @var bool */
|
||||
protected $linger = false;
|
||||
/** @var int */
|
||||
protected $potionId;
|
||||
protected PotionType $potionType;
|
||||
|
||||
public function __construct(Location $location, ?Entity $shootingEntity, int $potionId, ?CompoundTag $nbt = null){
|
||||
$this->potionId = $potionId;
|
||||
public function __construct(Location $location, ?Entity $shootingEntity, PotionType $potionType, ?CompoundTag $nbt = null){
|
||||
$this->potionType = $potionType;
|
||||
parent::__construct($location, $shootingEntity, $nbt);
|
||||
}
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setShort("PotionId", $this->getPotionId());
|
||||
$nbt->setShort("PotionId", PotionTypeIdMap::getInstance()->toId($this->getPotionType()));
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
@ -128,7 +129,7 @@ class SplashPotion extends Throwable{
|
||||
}else{
|
||||
//TODO: lingering potions
|
||||
}
|
||||
}elseif($event instanceof ProjectileHitBlockEvent and $this->getPotionId() === Potion::WATER){
|
||||
}elseif($event instanceof ProjectileHitBlockEvent and $this->getPotionType()->equals(PotionType::WATER())){
|
||||
$blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace());
|
||||
|
||||
if($blockIn->getId() === BlockLegacyIds::FIRE){
|
||||
@ -145,12 +146,12 @@ class SplashPotion extends Throwable{
|
||||
/**
|
||||
* Returns the meta value of the potion item that this splash potion corresponds to. This decides what effects will be applied to the entity when it collides with its target.
|
||||
*/
|
||||
public function getPotionId() : int{
|
||||
return $this->potionId;
|
||||
public function getPotionType() : PotionType{
|
||||
return $this->potionType;
|
||||
}
|
||||
|
||||
public function setPotionId(int $id) : void{
|
||||
$this->potionId = $id; //TODO: validation
|
||||
public function setPotionType(PotionType $type) : void{
|
||||
$this->potionType = $type;
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
@ -173,13 +174,13 @@ class SplashPotion extends Throwable{
|
||||
* @return EffectInstance[]
|
||||
*/
|
||||
public function getPotionEffects() : array{
|
||||
return Potion::getPotionEffectsById($this->getPotionId());
|
||||
return $this->potionType->getEffects();
|
||||
}
|
||||
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
parent::syncNetworkData($properties);
|
||||
|
||||
$properties->setShort(EntityMetadataProperties::POTION_AUX_VALUE, $this->potionId);
|
||||
$properties->setShort(EntityMetadataProperties::POTION_AUX_VALUE, PotionTypeIdMap::getInstance()->toId($this->potionType));
|
||||
$properties->setGenericFlag(EntityMetadataFlags::LINGER, $this->linger);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\data\bedrock\EntityLegacyIds;
|
||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Location;
|
||||
use pocketmine\entity\Squid;
|
||||
@ -278,9 +279,10 @@ class ItemFactory{
|
||||
))->setColor($color));
|
||||
}
|
||||
|
||||
foreach(Potion::ALL as $type){
|
||||
$this->register(new Potion(new ItemIdentifier(ItemIds::POTION, $type), "Potion", $type));
|
||||
$this->register(new SplashPotion(new ItemIdentifier(ItemIds::SPLASH_POTION, $type), "Splash Potion", $type));
|
||||
foreach(PotionType::getAll() as $type){
|
||||
$typeId = PotionTypeIdMap::getInstance()->toId($type);
|
||||
$this->register(new Potion(new ItemIdentifier(ItemIds::POTION, $typeId), "Potion", $type));
|
||||
$this->register(new SplashPotion(new ItemIdentifier(ItemIds::SPLASH_POTION, $typeId), "Splash Potion", $type));
|
||||
}
|
||||
|
||||
foreach(TreeType::getAll() as $type){
|
||||
|
@ -23,242 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\effect\VanillaEffects;
|
||||
use pocketmine\entity\Living;
|
||||
|
||||
class Potion extends Item implements ConsumableItem{
|
||||
|
||||
public const WATER = 0;
|
||||
public const MUNDANE = 1;
|
||||
public const LONG_MUNDANE = 2;
|
||||
public const THICK = 3;
|
||||
public const AWKWARD = 4;
|
||||
public const NIGHT_VISION = 5;
|
||||
public const LONG_NIGHT_VISION = 6;
|
||||
public const INVISIBILITY = 7;
|
||||
public const LONG_INVISIBILITY = 8;
|
||||
public const LEAPING = 9;
|
||||
public const LONG_LEAPING = 10;
|
||||
public const STRONG_LEAPING = 11;
|
||||
public const FIRE_RESISTANCE = 12;
|
||||
public const LONG_FIRE_RESISTANCE = 13;
|
||||
public const SWIFTNESS = 14;
|
||||
public const LONG_SWIFTNESS = 15;
|
||||
public const STRONG_SWIFTNESS = 16;
|
||||
public const SLOWNESS = 17;
|
||||
public const LONG_SLOWNESS = 18;
|
||||
public const WATER_BREATHING = 19;
|
||||
public const LONG_WATER_BREATHING = 20;
|
||||
public const HEALING = 21;
|
||||
public const STRONG_HEALING = 22;
|
||||
public const HARMING = 23;
|
||||
public const STRONG_HARMING = 24;
|
||||
public const POISON = 25;
|
||||
public const LONG_POISON = 26;
|
||||
public const STRONG_POISON = 27;
|
||||
public const REGENERATION = 28;
|
||||
public const LONG_REGENERATION = 29;
|
||||
public const STRONG_REGENERATION = 30;
|
||||
public const STRENGTH = 31;
|
||||
public const LONG_STRENGTH = 32;
|
||||
public const STRONG_STRENGTH = 33;
|
||||
public const WEAKNESS = 34;
|
||||
public const LONG_WEAKNESS = 35;
|
||||
public const WITHER = 36;
|
||||
private PotionType $potionType;
|
||||
|
||||
public const ALL = [
|
||||
self::WATER,
|
||||
self::MUNDANE,
|
||||
self::LONG_MUNDANE,
|
||||
self::THICK,
|
||||
self::AWKWARD,
|
||||
self::NIGHT_VISION,
|
||||
self::LONG_NIGHT_VISION,
|
||||
self::INVISIBILITY,
|
||||
self::LONG_INVISIBILITY,
|
||||
self::LEAPING,
|
||||
self::LONG_LEAPING,
|
||||
self::STRONG_LEAPING,
|
||||
self::FIRE_RESISTANCE,
|
||||
self::LONG_FIRE_RESISTANCE,
|
||||
self::SWIFTNESS,
|
||||
self::LONG_SWIFTNESS,
|
||||
self::STRONG_SWIFTNESS,
|
||||
self::SLOWNESS,
|
||||
self::LONG_SLOWNESS,
|
||||
self::WATER_BREATHING,
|
||||
self::LONG_WATER_BREATHING,
|
||||
self::HEALING,
|
||||
self::STRONG_HEALING,
|
||||
self::HARMING,
|
||||
self::STRONG_HARMING,
|
||||
self::POISON,
|
||||
self::LONG_POISON,
|
||||
self::STRONG_POISON,
|
||||
self::REGENERATION,
|
||||
self::LONG_REGENERATION,
|
||||
self::STRONG_REGENERATION,
|
||||
self::STRENGTH,
|
||||
self::LONG_STRENGTH,
|
||||
self::STRONG_STRENGTH,
|
||||
self::WEAKNESS,
|
||||
self::LONG_WEAKNESS,
|
||||
self::WITHER
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns a list of effects applied by potions with the specified ID.
|
||||
*
|
||||
* @return EffectInstance[]
|
||||
*/
|
||||
public static function getPotionEffectsById(int $id) : array{
|
||||
switch($id){
|
||||
case self::WATER:
|
||||
case self::MUNDANE:
|
||||
case self::LONG_MUNDANE:
|
||||
case self::THICK:
|
||||
case self::AWKWARD:
|
||||
return [];
|
||||
case self::NIGHT_VISION:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::NIGHT_VISION(), 3600)
|
||||
];
|
||||
case self::LONG_NIGHT_VISION:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::NIGHT_VISION(), 9600)
|
||||
];
|
||||
case self::INVISIBILITY:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INVISIBILITY(), 3600)
|
||||
];
|
||||
case self::LONG_INVISIBILITY:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INVISIBILITY(), 9600)
|
||||
];
|
||||
case self::LEAPING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 3600)
|
||||
];
|
||||
case self::LONG_LEAPING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 9600)
|
||||
];
|
||||
case self::STRONG_LEAPING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 1800, 1)
|
||||
];
|
||||
case self::FIRE_RESISTANCE:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 3600)
|
||||
];
|
||||
case self::LONG_FIRE_RESISTANCE:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 9600)
|
||||
];
|
||||
case self::SWIFTNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 3600)
|
||||
];
|
||||
case self::LONG_SWIFTNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 9600)
|
||||
];
|
||||
case self::STRONG_SWIFTNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 1800, 1)
|
||||
];
|
||||
case self::SLOWNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::SLOWNESS(), 1800)
|
||||
];
|
||||
case self::LONG_SLOWNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::SLOWNESS(), 4800)
|
||||
];
|
||||
case self::WATER_BREATHING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::WATER_BREATHING(), 3600)
|
||||
];
|
||||
case self::LONG_WATER_BREATHING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::WATER_BREATHING(), 9600)
|
||||
];
|
||||
case self::HEALING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INSTANT_HEALTH())
|
||||
];
|
||||
case self::STRONG_HEALING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INSTANT_HEALTH(), null, 1)
|
||||
];
|
||||
case self::HARMING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INSTANT_DAMAGE())
|
||||
];
|
||||
case self::STRONG_HARMING:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::INSTANT_DAMAGE(), null, 1)
|
||||
];
|
||||
case self::POISON:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::POISON(), 900)
|
||||
];
|
||||
case self::LONG_POISON:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::POISON(), 2400)
|
||||
];
|
||||
case self::STRONG_POISON:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::POISON(), 440, 1)
|
||||
];
|
||||
case self::REGENERATION:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 900)
|
||||
];
|
||||
case self::LONG_REGENERATION:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 2400)
|
||||
];
|
||||
case self::STRONG_REGENERATION:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 440, 1)
|
||||
];
|
||||
case self::STRENGTH:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 3600)
|
||||
];
|
||||
case self::LONG_STRENGTH:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 9600)
|
||||
];
|
||||
case self::STRONG_STRENGTH:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 1800, 1)
|
||||
];
|
||||
case self::WEAKNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::WEAKNESS(), 1800)
|
||||
];
|
||||
case self::LONG_WEAKNESS:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::WEAKNESS(), 4800)
|
||||
];
|
||||
case self::WITHER:
|
||||
return [
|
||||
new EffectInstance(VanillaEffects::WITHER(), 800, 1)
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
private $potionId;
|
||||
|
||||
public function __construct(ItemIdentifier $identifier, string $name, int $potionId){
|
||||
public function __construct(ItemIdentifier $identifier, string $name, PotionType $potionType){
|
||||
parent::__construct($identifier, $name);
|
||||
$this->potionId = $potionId;
|
||||
$this->potionType = $potionType;
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
@ -271,7 +44,7 @@ class Potion extends Item implements ConsumableItem{
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
//TODO: check CustomPotionEffects NBT
|
||||
return self::getPotionEffectsById($this->potionId);
|
||||
return $this->potionType->getEffects();
|
||||
}
|
||||
|
||||
public function getResidue() : Item{
|
||||
|
202
src/item/PotionType.php
Normal file
202
src/item/PotionType.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?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\item;
|
||||
|
||||
use pocketmine\entity\effect\EffectInstance;
|
||||
use pocketmine\entity\effect\VanillaEffects;
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
* This must be regenerated whenever registry members are added, removed or changed.
|
||||
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
|
||||
*
|
||||
* @method static PotionType AWKWARD()
|
||||
* @method static PotionType FIRE_RESISTANCE()
|
||||
* @method static PotionType HARMING()
|
||||
* @method static PotionType HEALING()
|
||||
* @method static PotionType INVISIBILITY()
|
||||
* @method static PotionType LEAPING()
|
||||
* @method static PotionType LONG_FIRE_RESISTANCE()
|
||||
* @method static PotionType LONG_INVISIBILITY()
|
||||
* @method static PotionType LONG_LEAPING()
|
||||
* @method static PotionType LONG_MUNDANE()
|
||||
* @method static PotionType LONG_NIGHT_VISION()
|
||||
* @method static PotionType LONG_POISON()
|
||||
* @method static PotionType LONG_REGENERATION()
|
||||
* @method static PotionType LONG_SLOWNESS()
|
||||
* @method static PotionType LONG_STRENGTH()
|
||||
* @method static PotionType LONG_SWIFTNESS()
|
||||
* @method static PotionType LONG_WATER_BREATHING()
|
||||
* @method static PotionType LONG_WEAKNESS()
|
||||
* @method static PotionType MUNDANE()
|
||||
* @method static PotionType NIGHT_VISION()
|
||||
* @method static PotionType POISON()
|
||||
* @method static PotionType REGENERATION()
|
||||
* @method static PotionType SLOWNESS()
|
||||
* @method static PotionType STRENGTH()
|
||||
* @method static PotionType STRONG_HARMING()
|
||||
* @method static PotionType STRONG_HEALING()
|
||||
* @method static PotionType STRONG_LEAPING()
|
||||
* @method static PotionType STRONG_POISON()
|
||||
* @method static PotionType STRONG_REGENERATION()
|
||||
* @method static PotionType STRONG_STRENGTH()
|
||||
* @method static PotionType STRONG_SWIFTNESS()
|
||||
* @method static PotionType SWIFTNESS()
|
||||
* @method static PotionType THICK()
|
||||
* @method static PotionType WATER()
|
||||
* @method static PotionType WATER_BREATHING()
|
||||
* @method static PotionType WEAKNESS()
|
||||
* @method static PotionType WITHER()
|
||||
*/
|
||||
final class PotionType{
|
||||
use EnumTrait {
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("water", fn() => []),
|
||||
new self("mundane", fn() => []),
|
||||
new self("long_mundane", fn() => []),
|
||||
new self("thick", fn() => []),
|
||||
new self("awkward", fn() => []),
|
||||
new self("night_vision", fn() => [
|
||||
new EffectInstance(VanillaEffects::NIGHT_VISION(), 3600)
|
||||
]),
|
||||
new self("long_night_vision", fn() => [
|
||||
new EffectInstance(VanillaEffects::NIGHT_VISION(), 9600)
|
||||
]),
|
||||
new self("invisibility", fn() => [
|
||||
new EffectInstance(VanillaEffects::INVISIBILITY(), 3600)
|
||||
]),
|
||||
new self("long_invisibility", fn() => [
|
||||
new EffectInstance(VanillaEffects::INVISIBILITY(), 9600)
|
||||
]),
|
||||
new self("leaping", fn() => [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 3600)
|
||||
]),
|
||||
new self("long_leaping", fn() => [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 9600)
|
||||
]),
|
||||
new self("strong_leaping", fn() => [
|
||||
new EffectInstance(VanillaEffects::JUMP_BOOST(), 1800, 1)
|
||||
]),
|
||||
new self("fire_resistance", fn() => [
|
||||
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 3600)
|
||||
]),
|
||||
new self("long_fire_resistance", fn() => [
|
||||
new EffectInstance(VanillaEffects::FIRE_RESISTANCE(), 9600)
|
||||
]),
|
||||
new self("swiftness", fn() => [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 3600)
|
||||
]),
|
||||
new self("long_swiftness", fn() => [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 9600)
|
||||
]),
|
||||
new self("strong_swiftness", fn() => [
|
||||
new EffectInstance(VanillaEffects::SPEED(), 1800, 1)
|
||||
]),
|
||||
new self("slowness", fn() => [
|
||||
new EffectInstance(VanillaEffects::SLOWNESS(), 1800)
|
||||
]),
|
||||
new self("long_slowness", fn() => [
|
||||
new EffectInstance(VanillaEffects::SLOWNESS(), 4800)
|
||||
]),
|
||||
new self("water_breathing", fn() => [
|
||||
new EffectInstance(VanillaEffects::WATER_BREATHING(), 3600)
|
||||
]),
|
||||
new self("long_water_breathing", fn() => [
|
||||
new EffectInstance(VanillaEffects::WATER_BREATHING(), 9600)
|
||||
]),
|
||||
new self("healing", fn() => [
|
||||
new EffectInstance(VanillaEffects::INSTANT_HEALTH())
|
||||
]),
|
||||
new self("strong_healing", fn() => [
|
||||
new EffectInstance(VanillaEffects::INSTANT_HEALTH(), null, 1)
|
||||
]),
|
||||
new self("harming", fn() => [
|
||||
new EffectInstance(VanillaEffects::INSTANT_DAMAGE())
|
||||
]),
|
||||
new self("strong_harming", fn() => [
|
||||
new EffectInstance(VanillaEffects::INSTANT_DAMAGE(), null, 1)
|
||||
]),
|
||||
new self("poison", fn() => [
|
||||
new EffectInstance(VanillaEffects::POISON(), 900)
|
||||
]),
|
||||
new self("long_poison", fn() => [
|
||||
new EffectInstance(VanillaEffects::POISON(), 2400)
|
||||
]),
|
||||
new self("strong_poison", fn() => [
|
||||
new EffectInstance(VanillaEffects::POISON(), 440, 1)
|
||||
]),
|
||||
new self("regeneration", fn() => [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 900)
|
||||
]),
|
||||
new self("long_regeneration", fn() => [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 2400)
|
||||
]),
|
||||
new self("strong_regeneration", fn() => [
|
||||
new EffectInstance(VanillaEffects::REGENERATION(), 440, 1)
|
||||
]),
|
||||
new self("strength", fn() => [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 3600)
|
||||
]),
|
||||
new self("long_strength", fn() => [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 9600)
|
||||
]),
|
||||
new self("strong_strength", fn() => [
|
||||
new EffectInstance(VanillaEffects::STRENGTH(), 1800, 1)
|
||||
]),
|
||||
new self("weakness", fn() => [
|
||||
new EffectInstance(VanillaEffects::WEAKNESS(), 1800)
|
||||
]),
|
||||
new self("long_weakness", fn() => [
|
||||
new EffectInstance(VanillaEffects::WEAKNESS(), 4800)
|
||||
]),
|
||||
new self("wither", fn() => [
|
||||
new EffectInstance(VanillaEffects::WITHER(), 800, 1)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/** @phpstan-var \Closure() : list<EffectInstance> */
|
||||
private \Closure $effectsGetter;
|
||||
|
||||
/**
|
||||
* @phpstan-param \Closure() : list<EffectInstance> $effectsGetter
|
||||
*/
|
||||
private function __construct(string $enumName, \Closure $effectsGetter){
|
||||
$this->Enum___construct($enumName);
|
||||
$this->effectsGetter = $effectsGetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EffectInstance[]
|
||||
* @phpstan-return list<EffectInstance>
|
||||
*/
|
||||
public function getEffects() : array{
|
||||
return ($this->effectsGetter)();
|
||||
}
|
||||
}
|
@ -30,12 +30,11 @@ use pocketmine\player\Player;
|
||||
|
||||
class SplashPotion extends ProjectileItem{
|
||||
|
||||
/** @var int */
|
||||
private $potionId;
|
||||
private PotionType $potionType;
|
||||
|
||||
public function __construct(ItemIdentifier $identifier, string $name, int $potionId){
|
||||
public function __construct(ItemIdentifier $identifier, string $name, PotionType $potionType){
|
||||
parent::__construct($identifier, $name);
|
||||
$this->potionId = $potionId;
|
||||
$this->potionType = $potionType;
|
||||
}
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
@ -43,7 +42,7 @@ class SplashPotion extends ProjectileItem{
|
||||
}
|
||||
|
||||
protected function createEntity(Location $location, Player $thrower) : Throwable{
|
||||
return new SplashPotionEntity($location, $thrower, $this->potionId);
|
||||
return new SplashPotionEntity($location, $thrower, $this->potionType);
|
||||
}
|
||||
|
||||
public function getThrowForce() : float{
|
||||
|
Loading…
x
Reference in New Issue
Block a user