Move a giant heap of network garbage out of Entity

This commit is contained in:
Dylan K. Taylor
2019-04-26 18:52:38 +01:00
parent ea8c723092
commit 854a2f5135
19 changed files with 488 additions and 339 deletions

View File

@ -26,7 +26,6 @@ namespace pocketmine\network\mcpe;
#include <rules/DataPacket.h>
use pocketmine\entity\Attribute;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemIds;
@ -36,6 +35,7 @@ use pocketmine\nbt\TreeRoot;
use pocketmine\network\BadPacketException;
use pocketmine\network\mcpe\protocol\types\CommandOriginData;
use pocketmine\network\mcpe\protocol\types\EntityLink;
use pocketmine\network\mcpe\protocol\types\EntityMetadataTypes;
use pocketmine\utils\BinaryDataException;
use pocketmine\utils\BinaryStream;
use pocketmine\utils\UUID;
@ -177,32 +177,32 @@ class NetworkBinaryStream extends BinaryStream{
$type = $this->getUnsignedVarInt();
$value = null;
switch($type){
case Entity::DATA_TYPE_BYTE:
case EntityMetadataTypes::BYTE:
$value = $this->getByte();
break;
case Entity::DATA_TYPE_SHORT:
case EntityMetadataTypes::SHORT:
$value = $this->getSignedLShort();
break;
case Entity::DATA_TYPE_INT:
case EntityMetadataTypes::INT:
$value = $this->getVarInt();
break;
case Entity::DATA_TYPE_FLOAT:
case EntityMetadataTypes::FLOAT:
$value = $this->getLFloat();
break;
case Entity::DATA_TYPE_STRING:
case EntityMetadataTypes::STRING:
$value = $this->getString();
break;
case Entity::DATA_TYPE_SLOT:
case EntityMetadataTypes::SLOT:
$value = $this->getSlot();
break;
case Entity::DATA_TYPE_POS:
case EntityMetadataTypes::POS:
$value = new Vector3();
$this->getSignedBlockPosition($value->x, $value->y, $value->z);
break;
case Entity::DATA_TYPE_LONG:
case EntityMetadataTypes::LONG:
$value = $this->getVarLong();
break;
case Entity::DATA_TYPE_VECTOR3F:
case EntityMetadataTypes::VECTOR3F:
$value = $this->getVector3();
break;
default:
@ -229,25 +229,25 @@ class NetworkBinaryStream extends BinaryStream{
$this->putUnsignedVarInt($key); //data key
$this->putUnsignedVarInt($d[0]); //data type
switch($d[0]){
case Entity::DATA_TYPE_BYTE:
case EntityMetadataTypes::BYTE:
$this->putByte($d[1]);
break;
case Entity::DATA_TYPE_SHORT:
case EntityMetadataTypes::SHORT:
$this->putLShort($d[1]); //SIGNED short!
break;
case Entity::DATA_TYPE_INT:
case EntityMetadataTypes::INT:
$this->putVarInt($d[1]);
break;
case Entity::DATA_TYPE_FLOAT:
case EntityMetadataTypes::FLOAT:
$this->putLFloat($d[1]);
break;
case Entity::DATA_TYPE_STRING:
case EntityMetadataTypes::STRING:
$this->putString($d[1]);
break;
case Entity::DATA_TYPE_SLOT:
case EntityMetadataTypes::SLOT:
$this->putSlot($d[1]);
break;
case Entity::DATA_TYPE_POS:
case EntityMetadataTypes::POS:
$v = $d[1];
if($v !== null){
$this->putSignedBlockPosition($v->x, $v->y, $v->z);
@ -255,10 +255,10 @@ class NetworkBinaryStream extends BinaryStream{
$this->putSignedBlockPosition(0, 0, 0);
}
break;
case Entity::DATA_TYPE_LONG:
case EntityMetadataTypes::LONG:
$this->putVarLong($d[1]);
break;
case Entity::DATA_TYPE_VECTOR3F:
case EntityMetadataTypes::VECTOR3F:
$this->putVector3Nullable($d[1]);
break;
default:

View File

@ -0,0 +1,120 @@
<?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;
final class EntityMetadataFlags{
private function __construct(){
//NOOP
}
public const ONFIRE = 0;
public const SNEAKING = 1;
public const RIDING = 2;
public const SPRINTING = 3;
public const ACTION = 4;
public const INVISIBLE = 5;
public const TEMPTED = 6;
public const INLOVE = 7;
public const SADDLED = 8;
public const POWERED = 9;
public const IGNITED = 10;
public const BABY = 11;
public const CONVERTING = 12;
public const CRITICAL = 13;
public const CAN_SHOW_NAMETAG = 14;
public const ALWAYS_SHOW_NAMETAG = 15;
public const IMMOBILE = 16, NO_AI = 16;
public const SILENT = 17;
public const WALLCLIMBING = 18;
public const CAN_CLIMB = 19;
public const SWIMMER = 20;
public const CAN_FLY = 21;
public const WALKER = 22;
public const RESTING = 23;
public const SITTING = 24;
public const ANGRY = 25;
public const INTERESTED = 26;
public const CHARGED = 27;
public const TAMED = 28;
public const ORPHANED = 29;
public const LEASHED = 30;
public const SHEARED = 31;
public const GLIDING = 32;
public const ELDER = 33;
public const MOVING = 34;
public const BREATHING = 35;
public const CHESTED = 36;
public const STACKABLE = 37;
public const SHOWBASE = 38;
public const REARING = 39;
public const VIBRATING = 40;
public const IDLING = 41;
public const EVOKER_SPELL = 42;
public const CHARGE_ATTACK = 43;
public const WASD_CONTROLLED = 44;
public const CAN_POWER_JUMP = 45;
public const LINGER = 46;
public const HAS_COLLISION = 47;
public const AFFECTED_BY_GRAVITY = 48;
public const FIRE_IMMUNE = 49;
public const DANCING = 50;
public const ENCHANTED = 51;
public const SHOW_TRIDENT_ROPE = 52; // tridents show an animated rope when enchanted with loyalty after they are thrown and return to their owner. To be combined with DATA_OWNER_EID
public const CONTAINER_PRIVATE = 53; //inventory is private, doesn't drop contents when killed if true
public const TRANSFORMING = 54;
public const SPIN_ATTACK = 55;
public const SWIMMING = 56;
public const BRIBED = 57; //dolphins have this set when they go to find treasure for the player
public const PREGNANT = 58;
public const LAYING_EGG = 59;
public const RIDER_CAN_PICK = 60; //???
public const TRANSITION_SITTING = 61;
public const EATING = 62;
public const LAYING_DOWN = 63;
public const SNEEZING = 64;
public const TRUSTING = 65;
public const ROLLING = 66;
public const SCARED = 67;
public const IN_SCAFFOLDING = 68;
public const OVER_SCAFFOLDING = 69;
public const FALL_THROUGH_SCAFFOLDING = 70;
public const BLOCKING = 71; //shield
public const DISABLE_BLOCKING = 72;
//73 is set when a player is attacked while using shield, unclear on purpose
//74 related to shield usage, needs further investigation
public const SLEEPING = 75;
//76 related to sleeping, unclear usage
public const TRADE_INTEREST = 77;
public const DOOR_BREAKER = 78; //...
public const BREAKING_OBSTRUCTION = 79;
public const DOOR_OPENER = 80; //...
public const ILLAGER_CAPTAIN = 81;
public const STUNNED = 82;
public const ROARING = 83;
public const DELAYED_ATTACKING = 84;
public const AVOIDING_MOBS = 85;
//86 used by RangedAttackGoal
//87 used by NearestAttackableTargetGoal
}

View File

@ -0,0 +1,143 @@
<?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;
final class EntityMetadataProperties{
private function __construct(){
//NOOP
}
/*
* Readers beware: this isn't a nice list. Some of the properties have different types for different entities, and
* are used for entirely different things.
*/
public const FLAGS = 0;
public const HEALTH = 1; //int (minecart/boat)
public const VARIANT = 2; //int
public const COLOR = 3, COLOUR = 3; //byte
public const NAMETAG = 4; //string
public const OWNER_EID = 5; //long
public const TARGET_EID = 6; //long
public const AIR = 7; //short
public const POTION_COLOR = 8; //int (ARGB!)
public const POTION_AMBIENT = 9; //byte
/* 10 (byte) */
public const HURT_TIME = 11; //int (minecart/boat)
public const HURT_DIRECTION = 12; //int (minecart/boat)
public const PADDLE_TIME_LEFT = 13; //float
public const PADDLE_TIME_RIGHT = 14; //float
public const EXPERIENCE_VALUE = 15; //int (xp orb)
public const MINECART_DISPLAY_BLOCK = 16; //int (id | (data << 16))
public const HORSE_FLAGS = 16; //int
/* 16 (byte) used by wither skull */
public const MINECART_DISPLAY_OFFSET = 17; //int
public const SHOOTER_ID = 17; //long (used by arrows)
public const MINECART_HAS_DISPLAY = 18; //byte (must be 1 for minecart to show block inside)
public const HORSE_TYPE = 19; //byte
/* 20 (unknown)
* 21 (unknown) */
public const CHARGE_AMOUNT = 22; //int8, used for ghasts and also crossbow charging
public const ENDERMAN_HELD_ITEM_ID = 23; //short
public const ENTITY_AGE = 24; //short
/* 25 (int) used by horse, (byte) used by witch */
public const PLAYER_FLAGS = 26; //byte
public const PLAYER_INDEX = 27; //int, used for marker colours and agent nametag colours
public const PLAYER_BED_POSITION = 28; //blockpos
public const FIREBALL_POWER_X = 29; //float
public const FIREBALL_POWER_Y = 30;
public const FIREBALL_POWER_Z = 31;
/* 32 (unknown)
* 33 (float) fishing bobber
* 34 (float) fishing bobber
* 35 (float) fishing bobber */
public const POTION_AUX_VALUE = 36; //short
public const LEAD_HOLDER_EID = 37; //long
public const SCALE = 38; //float
public const HAS_NPC_COMPONENT = 39; //byte (???)
public const SKIN_ID = 40; //string
public const NPC_SKIN_ID = 41; //string
public const URL_TAG = 42; //string
public const MAX_AIR = 43; //short
public const MARK_VARIANT = 44; //int
public const CONTAINER_TYPE = 45; //byte (ContainerComponent)
public const CONTAINER_BASE_SIZE = 46; //int (ContainerComponent)
public const CONTAINER_EXTRA_SLOTS_PER_STRENGTH = 47; //int (used for llamas, inventory size is baseSize + thisProp * strength)
public const BLOCK_TARGET = 48; //block coords (ender crystal)
public const WITHER_INVULNERABLE_TICKS = 49; //int
public const WITHER_TARGET_1 = 50; //long
public const WITHER_TARGET_2 = 51; //long
public const WITHER_TARGET_3 = 52; //long
/* 53 (short) */
public const BOUNDING_BOX_WIDTH = 54; //float
public const BOUNDING_BOX_HEIGHT = 55; //float
public const FUSE_LENGTH = 56; //int
public const RIDER_SEAT_POSITION = 57; //vector3f
public const RIDER_ROTATION_LOCKED = 58; //byte
public const RIDER_MAX_ROTATION = 59; //float
public const RIDER_MIN_ROTATION = 60; //float
public const AREA_EFFECT_CLOUD_RADIUS = 61; //float
public const AREA_EFFECT_CLOUD_WAITING = 62; //int
public const AREA_EFFECT_CLOUD_PARTICLE_ID = 63; //int
/* 64 (int) shulker-related */
public const SHULKER_ATTACH_FACE = 65; //byte
/* 66 (short) shulker-related */
public const SHULKER_ATTACH_POS = 67; //block coords
public const TRADING_PLAYER_EID = 68; //long
/* 70 (byte) command-block */
public const COMMAND_BLOCK_COMMAND = 71; //string
public const COMMAND_BLOCK_LAST_OUTPUT = 72; //string
public const COMMAND_BLOCK_TRACK_OUTPUT = 73; //byte
public const CONTROLLING_RIDER_SEAT_NUMBER = 74; //byte
public const STRENGTH = 75; //int
public const MAX_STRENGTH = 76; //int
/* 77 (int) */
public const LIMITED_LIFE = 78;
public const ARMOR_STAND_POSE_INDEX = 79; //int
public const ENDER_CRYSTAL_TIME_OFFSET = 80; //int
public const ALWAYS_SHOW_NAMETAG = 81; //byte: -1 = default, 0 = only when looked at, 1 = always
public const COLOR_2 = 82; //byte
/* 83 (unknown) */
public const SCORE_TAG = 84; //string
public const BALLOON_ATTACHED_ENTITY = 85; //int64, entity unique ID of owner
public const PUFFERFISH_SIZE = 86; //byte
public const BOAT_BUBBLE_TIME = 87; //int (time in bubble column)
public const PLAYER_AGENT_EID = 88; //long
/* 89 (float) related to panda sitting
* 90 (float) related to panda sitting */
public const EAT_COUNTER = 91; //int (used by pandas)
public const FLAGS2 = 92; //long (extended data flags)
/* 93 (float) related to panda lying down
* 94 (float) related to panda lying down */
public const AREA_EFFECT_CLOUD_DURATION = 95; //int
public const AREA_EFFECT_CLOUD_SPAWN_TIME = 96; //int
public const AREA_EFFECT_CLOUD_RADIUS_PER_TICK = 97; //float, usually negative
public const AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP = 98; //float
public const AREA_EFFECT_CLOUD_PICKUP_COUNT = 99; //int
public const INTERACTIVE_TAG = 100; //string (button text)
public const TRADE_TIER = 101; //int
public const MAX_TRADE_TIER = 102; //int
public const TRADE_XP = 103; //int
}

View File

@ -0,0 +1,41 @@
<?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;
final class EntityMetadataTypes{
private function __construct(){
//NOOP
}
public const BYTE = 0;
public const SHORT = 1;
public const INT = 2;
public const FLOAT = 3;
public const STRING = 4;
public const SLOT = 5;
public const POS = 6;
public const LONG = 7;
public const VECTOR3F = 8;
}

View File

@ -0,0 +1,34 @@
<?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;
final class PlayerMetadataFlags{
private function __construct(){
//NOOP
}
public const SLEEP = 1;
public const DEAD = 2; //TODO: CHECK
}