From 279a438ae6ca4217d71b7050ac632490c4f863f2 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 22 Jun 2014 18:05:42 +0200 Subject: [PATCH] Fixed spawning of Tile entities via chunk packets --- src/pocketmine/Player.php | 20 +++++--------- .../command/defaults/BanCommand.php | 1 - .../command/defaults/BanIpCommand.php | 1 - .../command/defaults/DeopCommand.php | 1 - .../command/defaults/GiveCommand.php | 1 - .../command/defaults/HelpCommand.php | 1 - .../command/defaults/KickCommand.php | 1 - src/pocketmine/command/defaults/MeCommand.php | 1 - src/pocketmine/command/defaults/OpCommand.php | 1 - .../command/defaults/PardonCommand.php | 1 - .../command/defaults/PardonIpCommand.php | 1 - .../command/defaults/PluginsCommand.php | 1 - .../command/defaults/ReloadCommand.php | 1 - .../command/defaults/SayCommand.php | 1 - .../command/defaults/SetWorldSpawnCommand.php | 1 - .../command/defaults/SpawnpointCommand.php | 1 - .../command/defaults/StatusCommand.php | 1 - .../command/defaults/TeleportCommand.php | 1 - .../command/defaults/TellCommand.php | 1 - .../command/defaults/VersionCommand.php | 1 - .../command/defaults/WhitelistCommand.php | 1 - src/pocketmine/entity/Entity.php | 3 +-- src/pocketmine/entity/Human.php | 2 +- .../event/player/PlayerItemHeldEvent.php | 2 +- .../event/server/DataPacketReceiveEvent.php | 2 +- .../event/server/DataPacketSendEvent.php | 2 +- src/pocketmine/item/Tool.php | 2 +- src/pocketmine/level/Level.php | 14 ++++++++-- src/pocketmine/level/format/anvil/Chunk.php | 3 +-- .../level/format/generic/BaseChunk.php | 2 +- src/pocketmine/tile/Chest.php | 26 ++++--------------- src/pocketmine/tile/Sign.php | 25 ++++-------------- src/pocketmine/tile/Spawnable.php | 22 +++++++++++++++- 33 files changed, 58 insertions(+), 87 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 0f6448e5c..e69e2648c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -525,19 +525,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ unset($this->chunkACK[$identifier]); if(isset($this->usedChunks[$index])){ $this->usedChunks[$index][0] = true; - if($this->spawned === true){ - $X = null; - $Z = null; - Level::getXZ($index, $X, $Z); - foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ - if($entity !== $this){ - $entity->spawnTo($this); - } - } - foreach($this->getLevel()->getChunkTiles($X, $Z) as $tile){ - if($tile instanceof Spawnable){ - $tile->spawnTo($this); - } + $X = null; + $Z = null; + Level::getXZ($index, $X, $Z); + + foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){ + if($entity !== $this){ + $entity->spawnTo($this); } } } diff --git a/src/pocketmine/command/defaults/BanCommand.php b/src/pocketmine/command/defaults/BanCommand.php index 73c2f0368..39eb8321b 100644 --- a/src/pocketmine/command/defaults/BanCommand.php +++ b/src/pocketmine/command/defaults/BanCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class BanCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/BanIpCommand.php b/src/pocketmine/command/defaults/BanIpCommand.php index 2583a8337..85876bd1f 100644 --- a/src/pocketmine/command/defaults/BanIpCommand.php +++ b/src/pocketmine/command/defaults/BanIpCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class BanIpCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/DeopCommand.php b/src/pocketmine/command/defaults/DeopCommand.php index 7f823ea9e..8a192f6cb 100644 --- a/src/pocketmine/command/defaults/DeopCommand.php +++ b/src/pocketmine/command/defaults/DeopCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class DeopCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/GiveCommand.php b/src/pocketmine/command/defaults/GiveCommand.php index e7b69f0ca..a0989f056 100644 --- a/src/pocketmine/command/defaults/GiveCommand.php +++ b/src/pocketmine/command/defaults/GiveCommand.php @@ -25,7 +25,6 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\item\Item; use pocketmine\Player; - use pocketmine\utils\TextFormat; class GiveCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/HelpCommand.php b/src/pocketmine/command/defaults/HelpCommand.php index 4445b33ee..8334ececf 100644 --- a/src/pocketmine/command/defaults/HelpCommand.php +++ b/src/pocketmine/command/defaults/HelpCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; - use pocketmine\utils\TextFormat; class HelpCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/KickCommand.php b/src/pocketmine/command/defaults/KickCommand.php index d90b46ba6..18b43f26e 100644 --- a/src/pocketmine/command/defaults/KickCommand.php +++ b/src/pocketmine/command/defaults/KickCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class KickCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/MeCommand.php b/src/pocketmine/command/defaults/MeCommand.php index a8e90853e..28acf25b1 100644 --- a/src/pocketmine/command/defaults/MeCommand.php +++ b/src/pocketmine/command/defaults/MeCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class MeCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/OpCommand.php b/src/pocketmine/command/defaults/OpCommand.php index 3f61e7935..7c8396c14 100644 --- a/src/pocketmine/command/defaults/OpCommand.php +++ b/src/pocketmine/command/defaults/OpCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class OpCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/PardonCommand.php b/src/pocketmine/command/defaults/PardonCommand.php index f75632930..acd93dc8c 100644 --- a/src/pocketmine/command/defaults/PardonCommand.php +++ b/src/pocketmine/command/defaults/PardonCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class PardonCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/PardonIpCommand.php b/src/pocketmine/command/defaults/PardonIpCommand.php index fae0062a1..fe4c80f10 100644 --- a/src/pocketmine/command/defaults/PardonIpCommand.php +++ b/src/pocketmine/command/defaults/PardonIpCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class PardonIpCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/PluginsCommand.php b/src/pocketmine/command/defaults/PluginsCommand.php index ab77a5908..ead49ecaa 100644 --- a/src/pocketmine/command/defaults/PluginsCommand.php +++ b/src/pocketmine/command/defaults/PluginsCommand.php @@ -22,7 +22,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class PluginsCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/ReloadCommand.php b/src/pocketmine/command/defaults/ReloadCommand.php index ffcdc5e1b..04814518f 100644 --- a/src/pocketmine/command/defaults/ReloadCommand.php +++ b/src/pocketmine/command/defaults/ReloadCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class ReloadCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/SayCommand.php b/src/pocketmine/command/defaults/SayCommand.php index 6da4731c8..b55e8c7c4 100644 --- a/src/pocketmine/command/defaults/SayCommand.php +++ b/src/pocketmine/command/defaults/SayCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\command\ConsoleCommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class SayCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php index 4c3d2b1c4..43dfc268a 100644 --- a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php +++ b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php @@ -25,7 +25,6 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\math\Vector3; use pocketmine\Player; - use pocketmine\utils\TextFormat; class SetWorldSpawnCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/SpawnpointCommand.php b/src/pocketmine/command/defaults/SpawnpointCommand.php index 091e98961..42acf1868 100644 --- a/src/pocketmine/command/defaults/SpawnpointCommand.php +++ b/src/pocketmine/command/defaults/SpawnpointCommand.php @@ -25,7 +25,6 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\level\Position; use pocketmine\Player; - use pocketmine\utils\TextFormat; class SpawnpointCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/StatusCommand.php b/src/pocketmine/command/defaults/StatusCommand.php index 39da13edb..dd30520c5 100644 --- a/src/pocketmine/command/defaults/StatusCommand.php +++ b/src/pocketmine/command/defaults/StatusCommand.php @@ -22,7 +22,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class StatusCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/TeleportCommand.php b/src/pocketmine/command/defaults/TeleportCommand.php index 878037f1f..1689fa2e7 100644 --- a/src/pocketmine/command/defaults/TeleportCommand.php +++ b/src/pocketmine/command/defaults/TeleportCommand.php @@ -26,7 +26,6 @@ use pocketmine\command\CommandSender; use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\Player; - use pocketmine\utils\TextFormat; class TeleportCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/TellCommand.php b/src/pocketmine/command/defaults/TellCommand.php index 6ace8fb25..ea33be1b6 100644 --- a/src/pocketmine/command/defaults/TellCommand.php +++ b/src/pocketmine/command/defaults/TellCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\Player; - use pocketmine\utils\TextFormat; class TellCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/VersionCommand.php b/src/pocketmine/command/defaults/VersionCommand.php index f22775f2c..9103d918a 100644 --- a/src/pocketmine/command/defaults/VersionCommand.php +++ b/src/pocketmine/command/defaults/VersionCommand.php @@ -24,7 +24,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\network\protocol\Info; use pocketmine\plugin\Plugin; - use pocketmine\utils\TextFormat; class VersionCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/WhitelistCommand.php b/src/pocketmine/command/defaults/WhitelistCommand.php index d84e7a1e4..7227322ae 100644 --- a/src/pocketmine/command/defaults/WhitelistCommand.php +++ b/src/pocketmine/command/defaults/WhitelistCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; - use pocketmine\utils\TextFormat; class WhitelistCommand extends VanillaCommand{ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index ef1be8c62..4ab604613 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -32,7 +32,6 @@ use pocketmine\event\entity\EntityMoveEvent; use pocketmine\event\entity\EntitySpawnEvent; use pocketmine\event\entity\EntityTeleportEvent; use pocketmine\level\format\Chunk; - use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; @@ -43,13 +42,13 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Float; use pocketmine\nbt\tag\Short; -use pocketmine\Network; use pocketmine\network\protocol\MoveEntityPacket_PosRot; use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\UnloadChunkPacket; +use pocketmine\Network; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 6a7a4184b..5d9f2781c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -29,10 +29,10 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Short; -use pocketmine\Network; use pocketmine\network\protocol\AddPlayerPacket; use pocketmine\network\protocol\RemovePlayerPacket; use pocketmine\network\protocol\SetEntityMotionPacket; +use pocketmine\Network; use pocketmine\Player; use pocketmine\utils\TextFormat; diff --git a/src/pocketmine/event/player/PlayerItemHeldEvent.php b/src/pocketmine/event/player/PlayerItemHeldEvent.php index fb359ecb5..2802e5492 100644 --- a/src/pocketmine/event/player/PlayerItemHeldEvent.php +++ b/src/pocketmine/event/player/PlayerItemHeldEvent.php @@ -21,8 +21,8 @@ namespace pocketmine\event\player; -use pocketmine\Event; use pocketmine\event\Cancellable; +use pocketmine\Event; use pocketmine\item\Item; use pocketmine\Player; diff --git a/src/pocketmine/event/server/DataPacketReceiveEvent.php b/src/pocketmine/event/server/DataPacketReceiveEvent.php index 7de47696c..b8bc6392a 100644 --- a/src/pocketmine/event/server/DataPacketReceiveEvent.php +++ b/src/pocketmine/event/server/DataPacketReceiveEvent.php @@ -21,8 +21,8 @@ namespace pocketmine\event\server; -use pocketmine\event\Cancellable; use pocketmine\event; +use pocketmine\event\Cancellable; use pocketmine\network\protocol\DataPacket; use pocketmine\Player; diff --git a/src/pocketmine/event/server/DataPacketSendEvent.php b/src/pocketmine/event/server/DataPacketSendEvent.php index 805354abb..eefaa0ee7 100644 --- a/src/pocketmine/event/server/DataPacketSendEvent.php +++ b/src/pocketmine/event/server/DataPacketSendEvent.php @@ -21,8 +21,8 @@ namespace pocketmine\event\server; -use pocketmine\event\Cancellable; use pocketmine\event; +use pocketmine\event\Cancellable; use pocketmine\network\protocol\DataPacket; use pocketmine\Player; diff --git a/src/pocketmine/item/Tool.php b/src/pocketmine/item/Tool.php index eb622018a..5eece0020 100644 --- a/src/pocketmine/item/Tool.php +++ b/src/pocketmine/item/Tool.php @@ -22,8 +22,8 @@ namespace pocketmine\item; -use pocketmine\entity\Entity; use pocketmine\block\Block; +use pocketmine\entity\Entity; abstract class Tool extends Item{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 50c75849b..91c495e13 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -37,13 +37,13 @@ use pocketmine\level\format\Chunk; use pocketmine\level\format\LevelProvider; use pocketmine\level\format\SimpleChunk; use pocketmine\level\generator\Generator; - use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector2; use pocketmine\math\Vector3; use pocketmine\metadata\BlockMetadataStore; use pocketmine\metadata\Metadatable; use pocketmine\metadata\MetadataValue; +use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Double; @@ -58,6 +58,7 @@ use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; use pocketmine\tile\Sign; +use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; use pocketmine\utils\Cache; use pocketmine\utils\ReversePriorityQueue; @@ -1266,7 +1267,16 @@ class Level implements ChunkManager, Metadatable{ } } - $ordered = zlib_encode(Binary::writeLInt($X) . Binary::writeLInt($Z) . $orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $biomeIds . $biomeColors, ZLIB_ENCODING_DEFLATE, self::$COMPRESSION_LEVEL); + $tiles = ""; + $nbt = new NBT(NBT::LITTLE_ENDIAN); + foreach($chunk->getTiles() as $tile){ + if($tile instanceof Spawnable){ + $nbt->setData($tile->getSpawnCompound()); + $tiles .= $nbt->write(); + } + } + + $ordered = zlib_encode(Binary::writeLInt($X) . Binary::writeLInt($Z) . $orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $biomeIds . $biomeColors . $tiles, ZLIB_ENCODING_DEFLATE, self::$COMPRESSION_LEVEL); if(ADVANCED_CACHE == true and $Yndex === 0xff){ Cache::add($identifier, $ordered, 60); diff --git a/src/pocketmine/level/format/anvil/Chunk.php b/src/pocketmine/level/format/anvil/Chunk.php index 2a95eee55..01d79f252 100644 --- a/src/pocketmine/level/format/anvil/Chunk.php +++ b/src/pocketmine/level/format/anvil/Chunk.php @@ -29,7 +29,6 @@ use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Enum; - use pocketmine\nbt\tag\IntArray; use pocketmine\utils\Binary; @@ -74,7 +73,7 @@ class Chunk extends BaseChunk{ } if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){ - $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x01\x85\xb2\x4a"))); + $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x00\x85\xb2\x4a"))); } $sections = []; diff --git a/src/pocketmine/level/format/generic/BaseChunk.php b/src/pocketmine/level/format/generic/BaseChunk.php index 835b2e385..037d835f2 100644 --- a/src/pocketmine/level/format/generic/BaseChunk.php +++ b/src/pocketmine/level/format/generic/BaseChunk.php @@ -206,7 +206,7 @@ abstract class BaseChunk implements Chunk{ } public function setBiomeColor($x, $z, $R, $G, $B){ - $this->biomeColors[($z << 4) + $x] = 0x01000000 | (($R & 0xFF) << 16) | (($G & 0xFF) << 8) | ($B & 0xFF); + $this->biomeColors[($z << 4) + $x] = 0 | (($R & 0xFF) << 16) | (($G & 0xFF) << 8) | ($B & 0xFF); } public function getHighestBlockAt($x, $z){ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 3565fb651..f6bf1d01f 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -34,8 +34,6 @@ use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\String; -use pocketmine\network\protocol\EntityDataPacket; -use pocketmine\Player; class Chest extends Spawnable implements InventoryHolder, Container{ @@ -220,37 +218,23 @@ class Chest extends Spawnable implements InventoryHolder, Container{ return true; } - public function spawnTo(Player $player){ - if($this->closed){ - return false; - } - - $nbt = new NBT(NBT::LITTLE_ENDIAN); + public function getSpawnCompound(){ if($this->isPaired()){ - $nbt->setData(new Compound("", array( + return new Compound("", array( new String("id", Tile::CHEST), new Int("x", (int) $this->x), new Int("y", (int) $this->y), new Int("z", (int) $this->z), new Int("pairx", (int) $this->namedtag->pairx), new Int("pairz", (int) $this->namedtag->pairz) - ))); + )); }else{ - $nbt->setData(new Compound("", array( + return new Compound("", array( new String("id", Tile::CHEST), new Int("x", (int) $this->x), new Int("y", (int) $this->y), new Int("z", (int) $this->z) - ))); + )); } - - $pk = new EntityDataPacket; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->namedtag = $nbt->write(); - $player->dataPacket($pk); - - return true; } } \ No newline at end of file diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index d893551c7..1d7ceee32 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -22,12 +22,9 @@ namespace pocketmine\tile; use pocketmine\level\format\Chunk; -use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\String; -use pocketmine\network\protocol\EntityDataPacket; -use pocketmine\Player; class Sign extends Spawnable{ @@ -45,6 +42,7 @@ class Sign extends Spawnable{ if(!isset($nbt->Text4)){ $nbt->Text4 = new String("Text4", ""); } + parent::__construct($chunk, $nbt); } @@ -67,30 +65,17 @@ class Sign extends Spawnable{ ); } - public function spawnTo(Player $player){ - if($this->closed){ - return false; - } - - $nbt = new NBT(NBT::LITTLE_ENDIAN); - $nbt->setData(new Compound("", array( + public function getSpawnCompound(){ + return new Compound("", array( new String("Text1", $this->namedtag["Text1"]), new String("Text2", $this->namedtag["Text2"]), - new String("Text3", $this->namedtag["Text4"]), + new String("Text3", $this->namedtag["Text3"]), new String("Text4", $this->namedtag["Text4"]), new String("id", Tile::SIGN), new Int("x", (int) $this->x), new Int("y", (int) $this->y), new Int("z", (int) $this->z) - ))); - $pk = new EntityDataPacket; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->namedtag = $nbt->write(); - $player->dataPacket($pk); - - return true; + )); } } diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index bfed78c25..062bea682 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -22,11 +22,31 @@ namespace pocketmine\tile; use pocketmine\level\format\Chunk; +use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; +use pocketmine\network\protocol\EntityDataPacket; use pocketmine\Player; abstract class Spawnable extends Tile{ - public abstract function spawnTo(Player $player); + + public function spawnTo(Player $player){ + if($this->closed){ + return false; + } + + $nbt = new NBT(NBT::LITTLE_ENDIAN); + $nbt->setData($this->getSpawnCompound()); + $pk = new EntityDataPacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->namedtag = $nbt->write(); + $player->dataPacket($pk); + + return true; + } + + public abstract function getSpawnCompound(); public function __construct(Chunk $chunk, Compound $nbt){ parent::__construct($chunk, $nbt);