more constants in Tile

This commit is contained in:
Dylan K. Taylor 2017-11-08 10:49:15 +00:00
parent 733e61f815
commit 827ee5ff33
2 changed files with 22 additions and 17 deletions

View File

@ -107,10 +107,10 @@ abstract class Spawnable extends Tile{
*/ */
final public function getSpawnCompound() : CompoundTag{ final public function getSpawnCompound() : CompoundTag{
$nbt = new CompoundTag("", [ $nbt = new CompoundTag("", [
$this->namedtag->getTag("id"), $this->namedtag->getTag(self::TAG_ID),
$this->namedtag->getTag("x"), $this->namedtag->getTag(self::TAG_X),
$this->namedtag->getTag("y"), $this->namedtag->getTag(self::TAG_Y),
$this->namedtag->getTag("z") $this->namedtag->getTag(self::TAG_Z)
]); ]);
$this->addAdditionalSpawnData($nbt); $this->addAdditionalSpawnData($nbt);
return $nbt; return $nbt;

View File

@ -44,6 +44,11 @@ use pocketmine\Server;
abstract class Tile extends Position{ abstract class Tile extends Position{
const TAG_ID = "id";
const TAG_X = "x";
const TAG_Y = "y";
const TAG_Z = "z";
const BREWING_STAND = "BrewingStand"; const BREWING_STAND = "BrewingStand";
const CHEST = "Chest"; const CHEST = "Chest";
const ENCHANT_TABLE = "EnchantTable"; const ENCHANT_TABLE = "EnchantTable";
@ -136,14 +141,14 @@ abstract class Tile extends Position{
$this->namedtag = $nbt; $this->namedtag = $nbt;
$this->server = $level->getServer(); $this->server = $level->getServer();
$this->setLevel($level); $this->setLevel($level);
$this->chunk = $level->getChunk($this->namedtag->getInt("x") >> 4, $this->namedtag->getInt("z") >> 4, false); $this->chunk = $level->getChunk($this->namedtag->getInt(self::TAG_X) >> 4, $this->namedtag->getInt(self::TAG_Z) >> 4, false);
assert($this->chunk !== null); assert($this->chunk !== null);
$this->name = ""; $this->name = "";
$this->id = Tile::$tileCount++; $this->id = Tile::$tileCount++;
$this->x = $this->namedtag->getInt("x"); $this->x = $this->namedtag->getInt(self::TAG_X);
$this->y = $this->namedtag->getInt("y"); $this->y = $this->namedtag->getInt(self::TAG_Y);
$this->z = $this->namedtag->getInt("z"); $this->z = $this->namedtag->getInt(self::TAG_Z);
$this->chunk->addTile($this); $this->chunk->addTile($this);
$this->getLevel()->addTile($this); $this->getLevel()->addTile($this);
@ -154,10 +159,10 @@ abstract class Tile extends Position{
} }
public function saveNBT() : void{ public function saveNBT() : void{
$this->namedtag->setString("id", static::getSaveId()); $this->namedtag->setString(self::TAG_ID, static::getSaveId());
$this->namedtag->setInt("x", $this->x); $this->namedtag->setInt(self::TAG_X, $this->x);
$this->namedtag->setInt("y", $this->y); $this->namedtag->setInt(self::TAG_Y, $this->y);
$this->namedtag->setInt("z", $this->z); $this->namedtag->setInt(self::TAG_Z, $this->z);
} }
public function getNBT() : CompoundTag{ public function getNBT() : CompoundTag{
@ -167,7 +172,7 @@ abstract class Tile extends Position{
public function getCleanedNBT() : ?CompoundTag{ public function getCleanedNBT() : ?CompoundTag{
$this->saveNBT(); $this->saveNBT();
$tag = clone $this->namedtag; $tag = clone $this->namedtag;
$tag->removeTag("x", "y", "z", "id"); $tag->removeTag(self::TAG_X, self::TAG_Y, self::TAG_Z, self::TAG_ID);
if($tag->getCount() > 0){ if($tag->getCount() > 0){
return $tag; return $tag;
}else{ }else{
@ -187,10 +192,10 @@ abstract class Tile extends Position{
*/ */
public static function createNBT(Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : CompoundTag{ public static function createNBT(Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : CompoundTag{
$nbt = new CompoundTag("", [ $nbt = new CompoundTag("", [
new StringTag("id", static::getSaveId()), new StringTag(self::TAG_ID, static::getSaveId()),
new IntTag("x", (int) $pos->x), new IntTag(self::TAG_X, (int) $pos->x),
new IntTag("y", (int) $pos->y), new IntTag(self::TAG_Y, (int) $pos->y),
new IntTag("z", (int) $pos->z) new IntTag(self::TAG_Z, (int) $pos->z)
]); ]);
static::createAdditionalNBT($nbt, $pos, $face, $item, $player); static::createAdditionalNBT($nbt, $pos, $face, $item, $player);