mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 11:16:57 +00:00
Constify a bunch of NBT keys, pass 1
This commit is contained in:
@ -40,6 +40,7 @@ class ExperienceOrb extends Entity{
|
||||
|
||||
public const TAG_VALUE_PC = "Value"; //short
|
||||
public const TAG_VALUE_PE = "experience value"; //int (WTF?)
|
||||
private const TAG_AGE = "Age"; //TAG_Short
|
||||
|
||||
/** Max distance an orb will follow a player across. */
|
||||
public const MAX_TARGET_DISTANCE = 8.0;
|
||||
@ -109,13 +110,13 @@ class ExperienceOrb extends Entity{
|
||||
protected function initEntity(CompoundTag $nbt) : void{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
$this->age = $nbt->getShort("Age", 0);
|
||||
$this->age = $nbt->getShort(self::TAG_AGE, 0);
|
||||
}
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
|
||||
$nbt->setShort("Age", $this->age);
|
||||
$nbt->setShort(self::TAG_AGE, $this->age);
|
||||
|
||||
$nbt->setShort(self::TAG_VALUE_PC, $this->getXpValue());
|
||||
$nbt->setInt(self::TAG_VALUE_PE, $this->getXpValue());
|
||||
|
@ -44,6 +44,10 @@ use function abs;
|
||||
|
||||
class FallingBlock extends Entity{
|
||||
|
||||
private const TAG_TILE_ID = "TileID"; //TAG_Int
|
||||
private const TAG_TILE = "Tile"; //TAG_Byte
|
||||
private const TAG_DATA = "Data"; //TAG_Byte
|
||||
|
||||
public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; }
|
||||
|
||||
protected $gravity = 0.04;
|
||||
@ -65,9 +69,9 @@ class FallingBlock extends Entity{
|
||||
$blockId = 0;
|
||||
|
||||
//TODO: 1.8+ save format
|
||||
if(($tileIdTag = $nbt->getTag("TileID")) instanceof IntTag){
|
||||
if(($tileIdTag = $nbt->getTag(self::TAG_TILE_ID)) instanceof IntTag){
|
||||
$blockId = $tileIdTag->getValue();
|
||||
}elseif(($tileTag = $nbt->getTag("Tile")) instanceof ByteTag){
|
||||
}elseif(($tileTag = $nbt->getTag(self::TAG_TILE)) instanceof ByteTag){
|
||||
$blockId = $tileTag->getValue();
|
||||
}
|
||||
|
||||
@ -75,7 +79,7 @@ class FallingBlock extends Entity{
|
||||
throw new SavedDataLoadingException("Missing block info from NBT");
|
||||
}
|
||||
|
||||
$damage = $nbt->getByte("Data", 0);
|
||||
$damage = $nbt->getByte(self::TAG_DATA, 0);
|
||||
|
||||
return $factory->get($blockId, $damage);
|
||||
}
|
||||
@ -138,8 +142,8 @@ class FallingBlock extends Entity{
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setInt("TileID", $this->block->getId());
|
||||
$nbt->setByte("Data", $this->block->getMeta());
|
||||
$nbt->setInt(self::TAG_TILE_ID, $this->block->getId());
|
||||
$nbt->setByte(self::TAG_DATA, $this->block->getMeta());
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
|
@ -43,6 +43,13 @@ use function max;
|
||||
|
||||
class ItemEntity extends Entity{
|
||||
|
||||
private const TAG_HEALTH = "Health"; //TAG_Short
|
||||
private const TAG_AGE = "Age"; //TAG_Short
|
||||
private const TAG_PICKUP_DELAY = "PickupDelay"; //TAG_Short
|
||||
private const TAG_OWNER = "Owner"; //TAG_String
|
||||
private const TAG_THROWER = "Thrower"; //TAG_String
|
||||
public const TAG_ITEM = "Item"; //TAG_Compound
|
||||
|
||||
public static function getNetworkTypeId() : string{ return EntityIds::ITEM; }
|
||||
|
||||
public const MERGE_CHECK_PERIOD = 2; //0.1 seconds
|
||||
@ -81,17 +88,17 @@ class ItemEntity extends Entity{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
$this->setMaxHealth(5);
|
||||
$this->setHealth($nbt->getShort("Health", (int) $this->getHealth()));
|
||||
$this->setHealth($nbt->getShort(self::TAG_HEALTH, (int) $this->getHealth()));
|
||||
|
||||
$age = $nbt->getShort("Age", 0);
|
||||
$age = $nbt->getShort(self::TAG_AGE, 0);
|
||||
if($age === -32768){
|
||||
$this->despawnDelay = self::NEVER_DESPAWN;
|
||||
}else{
|
||||
$this->despawnDelay = max(0, self::DEFAULT_DESPAWN_DELAY - $age);
|
||||
}
|
||||
$this->pickupDelay = $nbt->getShort("PickupDelay", $this->pickupDelay);
|
||||
$this->owner = $nbt->getString("Owner", $this->owner);
|
||||
$this->thrower = $nbt->getString("Thrower", $this->thrower);
|
||||
$this->pickupDelay = $nbt->getShort(self::TAG_PICKUP_DELAY, $this->pickupDelay);
|
||||
$this->owner = $nbt->getString(self::TAG_OWNER, $this->owner);
|
||||
$this->thrower = $nbt->getString(self::TAG_THROWER, $this->thrower);
|
||||
}
|
||||
|
||||
protected function onFirstUpdate(int $currentTick) : void{
|
||||
@ -195,20 +202,20 @@ class ItemEntity extends Entity{
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setTag("Item", $this->item->nbtSerialize());
|
||||
$nbt->setShort("Health", (int) $this->getHealth());
|
||||
$nbt->setTag(self::TAG_ITEM, $this->item->nbtSerialize());
|
||||
$nbt->setShort(self::TAG_HEALTH, (int) $this->getHealth());
|
||||
if($this->despawnDelay === self::NEVER_DESPAWN){
|
||||
$age = -32768;
|
||||
}else{
|
||||
$age = self::DEFAULT_DESPAWN_DELAY - $this->despawnDelay;
|
||||
}
|
||||
$nbt->setShort("Age", $age);
|
||||
$nbt->setShort("PickupDelay", $this->pickupDelay);
|
||||
$nbt->setShort(self::TAG_AGE, $age);
|
||||
$nbt->setShort(self::TAG_PICKUP_DELAY, $this->pickupDelay);
|
||||
if($this->owner !== null){
|
||||
$nbt->setString("Owner", $this->owner);
|
||||
$nbt->setString(self::TAG_OWNER, $this->owner);
|
||||
}
|
||||
if($this->thrower !== null){
|
||||
$nbt->setString("Thrower", $this->thrower);
|
||||
$nbt->setString(self::TAG_THROWER, $this->thrower);
|
||||
}
|
||||
|
||||
return $nbt;
|
||||
|
@ -41,6 +41,13 @@ use pocketmine\world\World;
|
||||
use function ceil;
|
||||
|
||||
class Painting extends Entity{
|
||||
public const TAG_TILE_X = "TileX"; //TAG_Int
|
||||
public const TAG_TILE_Y = "TileY"; //TAG_Int
|
||||
public const TAG_TILE_Z = "TileZ"; //TAG_Int
|
||||
public const TAG_FACING_JE = "Facing"; //TAG_Byte
|
||||
public const TAG_DIRECTION_BE = "Direction"; //TAG_Byte
|
||||
public const TAG_MOTIVE = "Motive"; //TAG_String
|
||||
|
||||
public static function getNetworkTypeId() : string{ return EntityIds::PAINTING; }
|
||||
|
||||
public const DATA_TO_FACING = [
|
||||
@ -88,14 +95,14 @@ class Painting extends Entity{
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setInt("TileX", (int) $this->blockIn->x);
|
||||
$nbt->setInt("TileY", (int) $this->blockIn->y);
|
||||
$nbt->setInt("TileZ", (int) $this->blockIn->z);
|
||||
$nbt->setInt(self::TAG_TILE_X, (int) $this->blockIn->x);
|
||||
$nbt->setInt(self::TAG_TILE_Y, (int) $this->blockIn->y);
|
||||
$nbt->setInt(self::TAG_TILE_Z, (int) $this->blockIn->z);
|
||||
|
||||
$nbt->setByte("Facing", self::FACING_TO_DATA[$this->facing]);
|
||||
$nbt->setByte("Direction", self::FACING_TO_DATA[$this->facing]); //Save both for full compatibility
|
||||
$nbt->setByte(self::TAG_FACING_JE, self::FACING_TO_DATA[$this->facing]);
|
||||
$nbt->setByte(self::TAG_DIRECTION_BE, self::FACING_TO_DATA[$this->facing]); //Save both for full compatibility
|
||||
|
||||
$nbt->setString("Motive", $this->motive->getName());
|
||||
$nbt->setString(self::TAG_MOTIVE, $this->motive->getName());
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ use pocketmine\world\Position;
|
||||
|
||||
class PrimedTNT extends Entity implements Explosive{
|
||||
|
||||
private const TAG_FUSE = "Fuse"; //TAG_Short
|
||||
|
||||
public static function getNetworkTypeId() : string{ return EntityIds::TNT; }
|
||||
|
||||
protected $gravity = 0.04;
|
||||
@ -81,7 +83,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
protected function initEntity(CompoundTag $nbt) : void{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
$this->fuse = $nbt->getShort("Fuse", 80);
|
||||
$this->fuse = $nbt->getShort(self::TAG_FUSE, 80);
|
||||
}
|
||||
|
||||
public function canCollideWith(Entity $entity) : bool{
|
||||
@ -90,7 +92,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setShort("Fuse", $this->fuse);
|
||||
$nbt->setShort(self::TAG_FUSE, $this->fuse);
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
|
Reference in New Issue
Block a user