Fixed spawning of Tile entities via chunk packets

This commit is contained in:
Shoghi Cervantes 2014-06-22 18:05:42 +02:00
parent 0d5eb149ab
commit 279a438ae6
33 changed files with 58 additions and 87 deletions

View File

@ -525,21 +525,15 @@ 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);
}
}
}
}
}
}

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\utils\TextFormat;
class MeCommand extends VanillaCommand{

View File

@ -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{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class PardonCommand extends VanillaCommand{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class PardonIpCommand extends VanillaCommand{

View File

@ -22,7 +22,6 @@
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class PluginsCommand extends VanillaCommand{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class ReloadCommand extends VanillaCommand{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -22,7 +22,6 @@
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class StatusCommand extends VanillaCommand{

View File

@ -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{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\utils\TextFormat;
class TellCommand extends VanillaCommand{

View File

@ -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{

View File

@ -23,7 +23,6 @@ namespace pocketmine\command\defaults;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\utils\TextFormat;
class WhitelistCommand extends VanillaCommand{

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -22,8 +22,8 @@
namespace pocketmine\item;
use pocketmine\entity\Entity;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
abstract class Tool extends Item{

View File

@ -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);

View File

@ -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 = [];

View File

@ -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){

View File

@ -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;
}
}

View File

@ -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;
));
}
}

View File

@ -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);