Properly switch to string entity IDs

This commit is contained in:
Dylan K. Taylor 2020-06-20 13:43:31 +01:00
parent a988578ee0
commit d38c17835d
20 changed files with 179 additions and 43 deletions

View File

@ -28,7 +28,6 @@ namespace pocketmine\entity;
use pocketmine\block\Block;
use pocketmine\block\Water;
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\entity\animation\Animation;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDespawnEvent;
@ -1475,7 +1474,7 @@ abstract class Entity{
return $this->hasSpawned;
}
abstract public static function getNetworkTypeId() : int;
abstract public static function getNetworkTypeId() : string;
/**
* Called by spawnTo() to send whatever packets needed to spawn the entity to the client.
@ -1483,7 +1482,7 @@ abstract class Entity{
protected function sendSpawnPacket(Player $player) : void{
$pk = new AddActorPacket();
$pk->entityRuntimeId = $this->getId();
$pk->type = LegacyEntityIdToStringIdMap::getInstance()->legacyToString(static::getNetworkTypeId());
$pk->type = static::getNetworkTypeId();
$pk->position = $this->location->asVector3();
$pk->motion = $this->getMotion();
$pk->yaw = $this->location->yaw;

View File

@ -48,6 +48,7 @@ use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
use pocketmine\network\mcpe\protocol\PlayerListPacket;
use pocketmine\network\mcpe\protocol\PlayerSkinPacket;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty;
use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
@ -63,9 +64,7 @@ use function random_int;
class Human extends Living implements ProjectileSource, InventoryHolder{
public static function getNetworkTypeId() : int{
return -1; //TODO: ideally we shouldn't have to specify this at all here ...
}
public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; }
/** @var PlayerInventory */
protected $inventory;

View File

@ -29,7 +29,7 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\VanillaItems;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use function atan2;
use function mt_rand;
use function sqrt;
@ -37,7 +37,7 @@ use const M_PI;
class Squid extends WaterAnimal{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::SQUID; }
public static function getNetworkTypeId() : string{ return EntityIds::SQUID; }
public $width = 0.95;
public $height = 0.95;

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
@ -36,7 +36,7 @@ class Villager extends Living implements Ageable{
public const PROFESSION_BLACKSMITH = 3;
public const PROFESSION_BUTCHER = 4;
public static function getNetworkTypeId() : int{ return EntityLegacyIds::VILLAGER; }
public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; }
public $width = 0.6;
public $height = 1.8;

View File

@ -24,12 +24,12 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\item\VanillaItems;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use function mt_rand;
class Zombie extends Living{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ZOMBIE; }
public static function getNetworkTypeId() : string{ return EntityIds::ZOMBIE; }
public $width = 0.6;
public $height = 1.8;

View File

@ -28,7 +28,7 @@ use pocketmine\entity\Human;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\player\Player;
@ -36,7 +36,7 @@ use function sqrt;
class ExperienceOrb extends Entity{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::XP_ORB; }
public static function getNetworkTypeId() : string{ return EntityIds::XP_ORB; }
public const TAG_VALUE_PC = "Value"; //short
public const TAG_VALUE_PE = "experience value"; //int (WTF?)

View File

@ -33,14 +33,14 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use function abs;
class FallingBlock extends Entity{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::FALLING_BLOCK; }
public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; }
public $width = 0.98;
public $height = 0.98;

View File

@ -32,13 +32,13 @@ use pocketmine\item\Item;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\AddItemActorPacket;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\player\Player;
use function max;
class ItemEntity extends Entity{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ITEM; }
public static function getNetworkTypeId() : string{ return EntityIds::ITEM; }
public const DEFAULT_DESPAWN_DELAY = 6000; //5 minutes
public const NEVER_DESPAWN = -1;

View File

@ -33,14 +33,14 @@ use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\player\Player;
use pocketmine\world\particle\DestroyBlockParticle;
use pocketmine\world\World;
use function ceil;
class Painting extends Entity{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::PAINTING; }
public static function getNetworkTypeId() : string{ return EntityIds::PAINTING; }
public const DATA_TO_FACING = [
0 => Facing::SOUTH,

View File

@ -28,7 +28,7 @@ use pocketmine\entity\Explosive;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ExplosionPrimeEvent;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
@ -38,7 +38,7 @@ use pocketmine\world\sound\IgniteSound;
class PrimedTNT extends Entity implements Explosive{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::TNT; }
public static function getNetworkTypeId() : string{ return EntityIds::TNT; }
public $width = 0.98;
public $height = 0.98;

View File

@ -32,7 +32,7 @@ use pocketmine\event\inventory\InventoryPickupArrowEvent;
use pocketmine\item\VanillaItems;
use pocketmine\math\RayTraceResult;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\player\Player;
@ -42,7 +42,7 @@ use function sqrt;
class Arrow extends Projectile{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ARROW; }
public static function getNetworkTypeId() : string{ return EntityIds::ARROW; }
public const PICKUP_NONE = 0;
public const PICKUP_ANY = 1;

View File

@ -25,11 +25,11 @@ namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\VanillaItems;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\ItemBreakParticle;
class Egg extends Throwable{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::EGG; }
public static function getNetworkTypeId() : string{ return EntityIds::EGG; }
//TODO: spawn chickens on collision

View File

@ -25,12 +25,12 @@ namespace pocketmine\entity\projectile;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\EndermanTeleportParticle;
use pocketmine\world\sound\EndermanTeleportSound;
class EnderPearl extends Throwable{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::ENDER_PEARL; }
public static function getNetworkTypeId() : string{ return EntityIds::ENDER_PEARL; }
protected function onHit(ProjectileHitEvent $event) : void{
$owner = $this->getOwningEntity();

View File

@ -24,13 +24,13 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\PotionSplashParticle;
use pocketmine\world\sound\PotionSplashSound;
use function mt_rand;
class ExperienceBottle extends Throwable{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::XP_BOTTLE; }
public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; }
protected $gravity = 0.07;

View File

@ -24,11 +24,11 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\world\particle\SnowballPoofParticle;
class Snowball extends Throwable{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::SNOWBALL; }
public static function getNetworkTypeId() : string{ return EntityIds::SNOWBALL; }
protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){

View File

@ -34,7 +34,7 @@ use pocketmine\event\entity\ProjectileHitEntityEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\Potion;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
@ -46,7 +46,7 @@ use function sqrt;
class SplashPotion extends Throwable{
public static function getNetworkTypeId() : int{ return EntityLegacyIds::SPLASH_POTION; }
public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; }
protected $gravity = 0.05;
protected $drag = 0.01;

View File

@ -0,0 +1,144 @@
<?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\network\mcpe\protocol\types\entity;
/**
* This file is directly generated from the entity definitions provided by the client. The entities listed in this file
* are expected to always have the same IDs.
*
* This file is automatically generated; do NOT edit it by hand.
*/
final class EntityIds{
private function __construct(){
//NOOP
}
public const AGENT = "minecraft:agent";
public const AREA_EFFECT_CLOUD = "minecraft:area_effect_cloud";
public const ARMOR_STAND = "minecraft:armor_stand";
public const ARROW = "minecraft:arrow";
public const BALLOON = "minecraft:balloon";
public const BAT = "minecraft:bat";
public const BEE = "minecraft:bee";
public const BLAZE = "minecraft:blaze";
public const BOAT = "minecraft:boat";
public const CAT = "minecraft:cat";
public const CAVE_SPIDER = "minecraft:cave_spider";
public const CHEST_MINECART = "minecraft:chest_minecart";
public const CHICKEN = "minecraft:chicken";
public const COD = "minecraft:cod";
public const COMMAND_BLOCK_MINECART = "minecraft:command_block_minecart";
public const COW = "minecraft:cow";
public const CREEPER = "minecraft:creeper";
public const DOLPHIN = "minecraft:dolphin";
public const DONKEY = "minecraft:donkey";
public const DRAGON_FIREBALL = "minecraft:dragon_fireball";
public const DROWNED = "minecraft:drowned";
public const EGG = "minecraft:egg";
public const ELDER_GUARDIAN = "minecraft:elder_guardian";
public const ELDER_GUARDIAN_GHOST = "minecraft:elder_guardian_ghost";
public const ENDER_CRYSTAL = "minecraft:ender_crystal";
public const ENDER_DRAGON = "minecraft:ender_dragon";
public const ENDER_PEARL = "minecraft:ender_pearl";
public const ENDERMAN = "minecraft:enderman";
public const ENDERMITE = "minecraft:endermite";
public const EVOCATION_FANG = "minecraft:evocation_fang";
public const EVOCATION_ILLAGER = "minecraft:evocation_illager";
public const EYE_OF_ENDER_SIGNAL = "minecraft:eye_of_ender_signal";
public const FALLING_BLOCK = "minecraft:falling_block";
public const FIREBALL = "minecraft:fireball";
public const FIREWORKS_ROCKET = "minecraft:fireworks_rocket";
public const FISHING_HOOK = "minecraft:fishing_hook";
public const FOX = "minecraft:fox";
public const GHAST = "minecraft:ghast";
public const GUARDIAN = "minecraft:guardian";
public const HOPPER_MINECART = "minecraft:hopper_minecart";
public const HORSE = "minecraft:horse";
public const HUSK = "minecraft:husk";
public const ICE_BOMB = "minecraft:ice_bomb";
public const IRON_GOLEM = "minecraft:iron_golem";
public const ITEM = "minecraft:item";
public const LEASH_KNOT = "minecraft:leash_knot";
public const LIGHTNING_BOLT = "minecraft:lightning_bolt";
public const LINGERING_POTION = "minecraft:lingering_potion";
public const LLAMA = "minecraft:llama";
public const LLAMA_SPIT = "minecraft:llama_spit";
public const MAGMA_CUBE = "minecraft:magma_cube";
public const MINECART = "minecraft:minecart";
public const MOOSHROOM = "minecraft:mooshroom";
public const MULE = "minecraft:mule";
public const NPC = "minecraft:npc";
public const OCELOT = "minecraft:ocelot";
public const PAINTING = "minecraft:painting";
public const PANDA = "minecraft:panda";
public const PARROT = "minecraft:parrot";
public const PHANTOM = "minecraft:phantom";
public const PIG = "minecraft:pig";
public const PILLAGER = "minecraft:pillager";
public const PLAYER = "minecraft:player";
public const POLAR_BEAR = "minecraft:polar_bear";
public const PUFFERFISH = "minecraft:pufferfish";
public const RABBIT = "minecraft:rabbit";
public const RAVAGER = "minecraft:ravager";
public const SALMON = "minecraft:salmon";
public const SHEEP = "minecraft:sheep";
public const SHULKER = "minecraft:shulker";
public const SHULKER_BULLET = "minecraft:shulker_bullet";
public const SILVERFISH = "minecraft:silverfish";
public const SKELETON = "minecraft:skeleton";
public const SKELETON_HORSE = "minecraft:skeleton_horse";
public const SLIME = "minecraft:slime";
public const SMALL_FIREBALL = "minecraft:small_fireball";
public const SNOW_GOLEM = "minecraft:snow_golem";
public const SNOWBALL = "minecraft:snowball";
public const SPIDER = "minecraft:spider";
public const SPLASH_POTION = "minecraft:splash_potion";
public const SQUID = "minecraft:squid";
public const STRAY = "minecraft:stray";
public const THROWN_TRIDENT = "minecraft:thrown_trident";
public const TNT = "minecraft:tnt";
public const TNT_MINECART = "minecraft:tnt_minecart";
public const TRIPOD_CAMERA = "minecraft:tripod_camera";
public const TROPICALFISH = "minecraft:tropicalfish";
public const TURTLE = "minecraft:turtle";
public const VEX = "minecraft:vex";
public const VILLAGER = "minecraft:villager";
public const VILLAGER_V2 = "minecraft:villager_v2";
public const VINDICATOR = "minecraft:vindicator";
public const WANDERING_TRADER = "minecraft:wandering_trader";
public const WITCH = "minecraft:witch";
public const WITHER = "minecraft:wither";
public const WITHER_SKELETON = "minecraft:wither_skeleton";
public const WITHER_SKULL = "minecraft:wither_skull";
public const WITHER_SKULL_DANGEROUS = "minecraft:wither_skull_dangerous";
public const WOLF = "minecraft:wolf";
public const XP_BOTTLE = "minecraft:xp_bottle";
public const XP_ORB = "minecraft:xp_orb";
public const ZOMBIE = "minecraft:zombie";
public const ZOMBIE_HORSE = "minecraft:zombie_horse";
public const ZOMBIE_PIGMAN = "minecraft:zombie_pigman";
public const ZOMBIE_VILLAGER = "minecraft:zombie_villager";
public const ZOMBIE_VILLAGER_V2 = "minecraft:zombie_villager_v2";
}

View File

@ -24,11 +24,9 @@ declare(strict_types=1);
namespace pocketmine\world\sound;
use pocketmine\block\Block;
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\player\Player;
/**
* Played when an entity hits the ground after falling a distance that doesn't cause damage, e.g. due to jumping.
@ -50,7 +48,7 @@ class EntityLandSound implements Sound{
LevelSoundEventPacket::SOUND_LAND,
$pos,
$this->blockLandedOn->getRuntimeId(),
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
$this->entity::getNetworkTypeId()
//TODO: does isBaby have any relevance here?
);
}

View File

@ -23,11 +23,9 @@ declare(strict_types=1);
namespace pocketmine\world\sound;
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\player\Player;
/**
* Played when an entity hits ground after falling a long distance (damage).
@ -47,7 +45,7 @@ class EntityLongFallSound implements Sound{
LevelSoundEventPacket::SOUND_FALL_BIG,
$pos,
-1,
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
$this->entity::getNetworkTypeId()
//TODO: is isBaby relevant here?
);
}

View File

@ -23,11 +23,9 @@ declare(strict_types=1);
namespace pocketmine\world\sound;
use pocketmine\data\bedrock\LegacyEntityIdToStringIdMap;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\player\Player;
/**
* Played when an entity hits the ground after falling a short distance.
@ -46,7 +44,7 @@ class EntityShortFallSound implements Sound{
LevelSoundEventPacket::SOUND_FALL_SMALL,
$pos,
-1,
$this->entity instanceof Player ? "minecraft:player" : LegacyEntityIdToStringIdMap::getInstance()->legacyToString($this->entity::getNetworkTypeId()) //TODO: bad hack, stuff depends on players having a -1 network ID :(
$this->entity::getNetworkTypeId()
//TODO: does isBaby have any relevance here?
);
}