mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
EntityFactory: remove legacy save IDs
this can be more cleanly handled using BedrockData.
This commit is contained in:
parent
ec59dc1c80
commit
16f90f4120
@ -1,134 +0,0 @@
|
|||||||
<?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 EntityLegacyIds{
|
|
||||||
|
|
||||||
public const CHICKEN = 10;
|
|
||||||
public const COW = 11;
|
|
||||||
public const PIG = 12;
|
|
||||||
public const SHEEP = 13;
|
|
||||||
public const WOLF = 14;
|
|
||||||
public const VILLAGER = 15;
|
|
||||||
public const MOOSHROOM = 16;
|
|
||||||
public const SQUID = 17;
|
|
||||||
public const RABBIT = 18;
|
|
||||||
public const BAT = 19;
|
|
||||||
public const IRON_GOLEM = 20;
|
|
||||||
public const SNOW_GOLEM = 21;
|
|
||||||
public const OCELOT = 22;
|
|
||||||
public const HORSE = 23;
|
|
||||||
public const DONKEY = 24;
|
|
||||||
public const MULE = 25;
|
|
||||||
public const SKELETON_HORSE = 26;
|
|
||||||
public const ZOMBIE_HORSE = 27;
|
|
||||||
public const POLAR_BEAR = 28;
|
|
||||||
public const LLAMA = 29;
|
|
||||||
public const PARROT = 30;
|
|
||||||
public const DOLPHIN = 31;
|
|
||||||
public const ZOMBIE = 32;
|
|
||||||
public const CREEPER = 33;
|
|
||||||
public const SKELETON = 34;
|
|
||||||
public const SPIDER = 35;
|
|
||||||
public const ZOMBIE_PIGMAN = 36;
|
|
||||||
public const SLIME = 37;
|
|
||||||
public const ENDERMAN = 38;
|
|
||||||
public const SILVERFISH = 39;
|
|
||||||
public const CAVE_SPIDER = 40;
|
|
||||||
public const GHAST = 41;
|
|
||||||
public const MAGMA_CUBE = 42;
|
|
||||||
public const BLAZE = 43;
|
|
||||||
public const ZOMBIE_VILLAGER = 44;
|
|
||||||
public const WITCH = 45;
|
|
||||||
public const STRAY = 46;
|
|
||||||
public const HUSK = 47;
|
|
||||||
public const WITHER_SKELETON = 48;
|
|
||||||
public const GUARDIAN = 49;
|
|
||||||
public const ELDER_GUARDIAN = 50;
|
|
||||||
public const NPC = 51;
|
|
||||||
public const WITHER = 52;
|
|
||||||
public const ENDER_DRAGON = 53;
|
|
||||||
public const SHULKER = 54;
|
|
||||||
public const ENDERMITE = 55;
|
|
||||||
public const AGENT = 56, LEARN_TO_CODE_MASCOT = 56;
|
|
||||||
public const VINDICATOR = 57;
|
|
||||||
public const PHANTOM = 58;
|
|
||||||
|
|
||||||
public const ARMOR_STAND = 61;
|
|
||||||
public const TRIPOD_CAMERA = 62;
|
|
||||||
public const PLAYER = 63;
|
|
||||||
public const ITEM = 64;
|
|
||||||
public const TNT = 65;
|
|
||||||
public const FALLING_BLOCK = 66;
|
|
||||||
public const MOVING_BLOCK = 67;
|
|
||||||
public const XP_BOTTLE = 68;
|
|
||||||
public const XP_ORB = 69;
|
|
||||||
public const EYE_OF_ENDER_SIGNAL = 70;
|
|
||||||
public const ENDER_CRYSTAL = 71;
|
|
||||||
public const FIREWORKS_ROCKET = 72;
|
|
||||||
public const THROWN_TRIDENT = 73, TRIDENT = 73;
|
|
||||||
public const TURTLE = 74;
|
|
||||||
public const CAT = 75;
|
|
||||||
public const SHULKER_BULLET = 76;
|
|
||||||
public const FISHING_HOOK = 77;
|
|
||||||
public const CHALKBOARD = 78;
|
|
||||||
public const DRAGON_FIREBALL = 79;
|
|
||||||
public const ARROW = 80;
|
|
||||||
public const SNOWBALL = 81;
|
|
||||||
public const EGG = 82;
|
|
||||||
public const PAINTING = 83;
|
|
||||||
public const MINECART = 84;
|
|
||||||
public const FIREBALL = 85, LARGE_FIREBALL = 85;
|
|
||||||
public const SPLASH_POTION = 86;
|
|
||||||
public const ENDER_PEARL = 87;
|
|
||||||
public const LEASH_KNOT = 88;
|
|
||||||
public const WITHER_SKULL = 89;
|
|
||||||
public const BOAT = 90;
|
|
||||||
public const WITHER_SKULL_DANGEROUS = 91;
|
|
||||||
public const LIGHTNING_BOLT = 93;
|
|
||||||
public const SMALL_FIREBALL = 94;
|
|
||||||
public const AREA_EFFECT_CLOUD = 95;
|
|
||||||
public const HOPPER_MINECART = 96;
|
|
||||||
public const TNT_MINECART = 97;
|
|
||||||
public const CHEST_MINECART = 98;
|
|
||||||
|
|
||||||
public const COMMAND_BLOCK_MINECART = 100;
|
|
||||||
public const LINGERING_POTION = 101;
|
|
||||||
public const LLAMA_SPIT = 102;
|
|
||||||
public const EVOCATION_FANG = 103;
|
|
||||||
public const EVOCATION_ILLAGER = 104;
|
|
||||||
public const VEX = 105;
|
|
||||||
public const ICE_BOMB = 106;
|
|
||||||
public const BALLOON = 107;
|
|
||||||
public const PUFFERFISH = 108;
|
|
||||||
public const SALMON = 109;
|
|
||||||
public const DROWNED = 110;
|
|
||||||
public const TROPICALFISH = 111, TROPICAL_FISH = 111;
|
|
||||||
public const COD = 112, FISH = 112;
|
|
||||||
public const PANDA = 113;
|
|
||||||
|
|
||||||
private function __construct(){
|
|
||||||
//NOOP
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ use DaveRandom\CallbackValidator\CallbackType;
|
|||||||
use DaveRandom\CallbackValidator\ParameterType;
|
use DaveRandom\CallbackValidator\ParameterType;
|
||||||
use DaveRandom\CallbackValidator\ReturnType;
|
use DaveRandom\CallbackValidator\ReturnType;
|
||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
use pocketmine\data\bedrock\EntityLegacyIds as LegacyIds;
|
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
|
||||||
use pocketmine\data\bedrock\PotionTypeIdMap;
|
use pocketmine\data\bedrock\PotionTypeIdMap;
|
||||||
use pocketmine\data\bedrock\PotionTypeIds;
|
use pocketmine\data\bedrock\PotionTypeIds;
|
||||||
use pocketmine\data\SavedDataLoadingException;
|
use pocketmine\data\SavedDataLoadingException;
|
||||||
@ -86,19 +86,19 @@ final class EntityFactory{
|
|||||||
|
|
||||||
$this->register(Arrow::class, function(World $world, CompoundTag $nbt) : Arrow{
|
$this->register(Arrow::class, function(World $world, CompoundTag $nbt) : Arrow{
|
||||||
return new Arrow(Helper::parseLocation($nbt, $world), null, $nbt->getByte(Arrow::TAG_CRIT, 0) === 1, $nbt);
|
return new Arrow(Helper::parseLocation($nbt, $world), null, $nbt->getByte(Arrow::TAG_CRIT, 0) === 1, $nbt);
|
||||||
}, ['Arrow', 'minecraft:arrow'], LegacyIds::ARROW);
|
}, ['Arrow', 'minecraft:arrow']);
|
||||||
|
|
||||||
$this->register(Egg::class, function(World $world, CompoundTag $nbt) : Egg{
|
$this->register(Egg::class, function(World $world, CompoundTag $nbt) : Egg{
|
||||||
return new Egg(Helper::parseLocation($nbt, $world), null, $nbt);
|
return new Egg(Helper::parseLocation($nbt, $world), null, $nbt);
|
||||||
}, ['Egg', 'minecraft:egg'], LegacyIds::EGG);
|
}, ['Egg', 'minecraft:egg']);
|
||||||
|
|
||||||
$this->register(EnderPearl::class, function(World $world, CompoundTag $nbt) : EnderPearl{
|
$this->register(EnderPearl::class, function(World $world, CompoundTag $nbt) : EnderPearl{
|
||||||
return new EnderPearl(Helper::parseLocation($nbt, $world), null, $nbt);
|
return new EnderPearl(Helper::parseLocation($nbt, $world), null, $nbt);
|
||||||
}, ['ThrownEnderpearl', 'minecraft:ender_pearl'], LegacyIds::ENDER_PEARL);
|
}, ['ThrownEnderpearl', 'minecraft:ender_pearl']);
|
||||||
|
|
||||||
$this->register(ExperienceBottle::class, function(World $world, CompoundTag $nbt) : ExperienceBottle{
|
$this->register(ExperienceBottle::class, function(World $world, CompoundTag $nbt) : ExperienceBottle{
|
||||||
return new ExperienceBottle(Helper::parseLocation($nbt, $world), null, $nbt);
|
return new ExperienceBottle(Helper::parseLocation($nbt, $world), null, $nbt);
|
||||||
}, ['ThrownExpBottle', 'minecraft:xp_bottle'], LegacyIds::XP_BOTTLE);
|
}, ['ThrownExpBottle', 'minecraft:xp_bottle']);
|
||||||
|
|
||||||
$this->register(ExperienceOrb::class, function(World $world, CompoundTag $nbt) : ExperienceOrb{
|
$this->register(ExperienceOrb::class, function(World $world, CompoundTag $nbt) : ExperienceOrb{
|
||||||
$value = 1;
|
$value = 1;
|
||||||
@ -109,11 +109,11 @@ final class EntityFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new ExperienceOrb(Helper::parseLocation($nbt, $world), $value, $nbt);
|
return new ExperienceOrb(Helper::parseLocation($nbt, $world), $value, $nbt);
|
||||||
}, ['XPOrb', 'minecraft:xp_orb'], LegacyIds::XP_ORB);
|
}, ['XPOrb', 'minecraft:xp_orb']);
|
||||||
|
|
||||||
$this->register(FallingBlock::class, function(World $world, CompoundTag $nbt) : FallingBlock{
|
$this->register(FallingBlock::class, function(World $world, CompoundTag $nbt) : FallingBlock{
|
||||||
return new FallingBlock(Helper::parseLocation($nbt, $world), FallingBlock::parseBlockNBT(BlockFactory::getInstance(), $nbt), $nbt);
|
return new FallingBlock(Helper::parseLocation($nbt, $world), FallingBlock::parseBlockNBT(BlockFactory::getInstance(), $nbt), $nbt);
|
||||||
}, ['FallingSand', 'minecraft:falling_block'], LegacyIds::FALLING_BLOCK);
|
}, ['FallingSand', 'minecraft:falling_block']);
|
||||||
|
|
||||||
$this->register(ItemEntity::class, function(World $world, CompoundTag $nbt) : ItemEntity{
|
$this->register(ItemEntity::class, function(World $world, CompoundTag $nbt) : ItemEntity{
|
||||||
$itemTag = $nbt->getCompoundTag(ItemEntity::TAG_ITEM);
|
$itemTag = $nbt->getCompoundTag(ItemEntity::TAG_ITEM);
|
||||||
@ -126,7 +126,7 @@ final class EntityFactory{
|
|||||||
throw new SavedDataLoadingException("Item is invalid");
|
throw new SavedDataLoadingException("Item is invalid");
|
||||||
}
|
}
|
||||||
return new ItemEntity(Helper::parseLocation($nbt, $world), $item, $nbt);
|
return new ItemEntity(Helper::parseLocation($nbt, $world), $item, $nbt);
|
||||||
}, ['Item', 'minecraft:item'], LegacyIds::ITEM);
|
}, ['Item', 'minecraft:item']);
|
||||||
|
|
||||||
$this->register(Painting::class, function(World $world, CompoundTag $nbt) : Painting{
|
$this->register(Painting::class, function(World $world, CompoundTag $nbt) : Painting{
|
||||||
$motive = PaintingMotive::getMotiveByName($nbt->getString(Painting::TAG_MOTIVE));
|
$motive = PaintingMotive::getMotiveByName($nbt->getString(Painting::TAG_MOTIVE));
|
||||||
@ -143,15 +143,15 @@ final class EntityFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Painting(Helper::parseLocation($nbt, $world), $blockIn, $facing, $motive, $nbt);
|
return new Painting(Helper::parseLocation($nbt, $world), $blockIn, $facing, $motive, $nbt);
|
||||||
}, ['Painting', 'minecraft:painting'], LegacyIds::PAINTING);
|
}, ['Painting', 'minecraft:painting']);
|
||||||
|
|
||||||
$this->register(PrimedTNT::class, function(World $world, CompoundTag $nbt) : PrimedTNT{
|
$this->register(PrimedTNT::class, function(World $world, CompoundTag $nbt) : PrimedTNT{
|
||||||
return new PrimedTNT(Helper::parseLocation($nbt, $world), $nbt);
|
return new PrimedTNT(Helper::parseLocation($nbt, $world), $nbt);
|
||||||
}, ['PrimedTnt', 'PrimedTNT', 'minecraft:tnt'], LegacyIds::TNT);
|
}, ['PrimedTnt', 'PrimedTNT', 'minecraft:tnt']);
|
||||||
|
|
||||||
$this->register(Snowball::class, function(World $world, CompoundTag $nbt) : Snowball{
|
$this->register(Snowball::class, function(World $world, CompoundTag $nbt) : Snowball{
|
||||||
return new Snowball(Helper::parseLocation($nbt, $world), null, $nbt);
|
return new Snowball(Helper::parseLocation($nbt, $world), null, $nbt);
|
||||||
}, ['Snowball', 'minecraft:snowball'], LegacyIds::SNOWBALL);
|
}, ['Snowball', 'minecraft:snowball']);
|
||||||
|
|
||||||
$this->register(SplashPotion::class, function(World $world, CompoundTag $nbt) : SplashPotion{
|
$this->register(SplashPotion::class, function(World $world, CompoundTag $nbt) : SplashPotion{
|
||||||
$potionType = PotionTypeIdMap::getInstance()->fromId($nbt->getShort("PotionId", PotionTypeIds::WATER));
|
$potionType = PotionTypeIdMap::getInstance()->fromId($nbt->getShort("PotionId", PotionTypeIds::WATER));
|
||||||
@ -159,19 +159,19 @@ final class EntityFactory{
|
|||||||
throw new SavedDataLoadingException("No such potion type");
|
throw new SavedDataLoadingException("No such potion type");
|
||||||
}
|
}
|
||||||
return new SplashPotion(Helper::parseLocation($nbt, $world), null, $potionType, $nbt);
|
return new SplashPotion(Helper::parseLocation($nbt, $world), null, $potionType, $nbt);
|
||||||
}, ['ThrownPotion', 'minecraft:potion', 'thrownpotion'], LegacyIds::SPLASH_POTION);
|
}, ['ThrownPotion', 'minecraft:potion', 'thrownpotion']);
|
||||||
|
|
||||||
$this->register(Squid::class, function(World $world, CompoundTag $nbt) : Squid{
|
$this->register(Squid::class, function(World $world, CompoundTag $nbt) : Squid{
|
||||||
return new Squid(Helper::parseLocation($nbt, $world), $nbt);
|
return new Squid(Helper::parseLocation($nbt, $world), $nbt);
|
||||||
}, ['Squid', 'minecraft:squid'], LegacyIds::SQUID);
|
}, ['Squid', 'minecraft:squid']);
|
||||||
|
|
||||||
$this->register(Villager::class, function(World $world, CompoundTag $nbt) : Villager{
|
$this->register(Villager::class, function(World $world, CompoundTag $nbt) : Villager{
|
||||||
return new Villager(Helper::parseLocation($nbt, $world), $nbt);
|
return new Villager(Helper::parseLocation($nbt, $world), $nbt);
|
||||||
}, ['Villager', 'minecraft:villager'], LegacyIds::VILLAGER);
|
}, ['Villager', 'minecraft:villager']);
|
||||||
|
|
||||||
$this->register(Zombie::class, function(World $world, CompoundTag $nbt) : Zombie{
|
$this->register(Zombie::class, function(World $world, CompoundTag $nbt) : Zombie{
|
||||||
return new Zombie(Helper::parseLocation($nbt, $world), $nbt);
|
return new Zombie(Helper::parseLocation($nbt, $world), $nbt);
|
||||||
}, ['Zombie', 'minecraft:zombie'], LegacyIds::ZOMBIE);
|
}, ['Zombie', 'minecraft:zombie']);
|
||||||
|
|
||||||
$this->register(Human::class, function(World $world, CompoundTag $nbt) : Human{
|
$this->register(Human::class, function(World $world, CompoundTag $nbt) : Human{
|
||||||
return new Human(Helper::parseLocation($nbt, $world), Human::parseSkinNBT($nbt), $nbt);
|
return new Human(Helper::parseLocation($nbt, $world), Human::parseSkinNBT($nbt), $nbt);
|
||||||
@ -191,7 +191,7 @@ final class EntityFactory{
|
|||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function register(string $className, \Closure $creationFunc, array $saveNames, ?int $legacyMcpeSaveId = null) : void{
|
public function register(string $className, \Closure $creationFunc, array $saveNames) : void{
|
||||||
if(count($saveNames) === 0){
|
if(count($saveNames) === 0){
|
||||||
throw new \InvalidArgumentException("At least one save name must be provided");
|
throw new \InvalidArgumentException("At least one save name must be provided");
|
||||||
}
|
}
|
||||||
@ -205,9 +205,6 @@ final class EntityFactory{
|
|||||||
foreach($saveNames as $name){
|
foreach($saveNames as $name){
|
||||||
$this->creationFuncs[$name] = $creationFunc;
|
$this->creationFuncs[$name] = $creationFunc;
|
||||||
}
|
}
|
||||||
if($legacyMcpeSaveId !== null){
|
|
||||||
$this->creationFuncs[$legacyMcpeSaveId] = $creationFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->saveNames[$className] = reset($saveNames);
|
$this->saveNames[$className] = reset($saveNames);
|
||||||
}
|
}
|
||||||
@ -225,7 +222,8 @@ final class EntityFactory{
|
|||||||
if($saveId instanceof StringTag){
|
if($saveId instanceof StringTag){
|
||||||
$func = $this->creationFuncs[$saveId->getValue()] ?? null;
|
$func = $this->creationFuncs[$saveId->getValue()] ?? null;
|
||||||
}elseif($saveId instanceof IntTag){ //legacy MCPE format
|
}elseif($saveId instanceof IntTag){ //legacy MCPE format
|
||||||
$func = $this->creationFuncs[$saveId->getValue() & 0xff] ?? null;
|
$stringId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($saveId->getValue() & 0xff);
|
||||||
|
$func = $stringId !== null ? $this->creationFuncs[$stringId] ?? null : null;
|
||||||
}
|
}
|
||||||
if($func === null){
|
if($func === null){
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user