Added Bed tile and support for coloured beds

This commit is contained in:
Dylan K. Taylor 2017-05-22 19:20:37 +01:00
parent 6ae24c5c19
commit 1f4e6535bb
3 changed files with 91 additions and 4 deletions

View File

@ -27,7 +27,13 @@ use pocketmine\event\TranslationContainer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\Level; use pocketmine\level\Level;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\Bed as TileBed;
use pocketmine\tile\Tile;
use pocketmine\utils\TextFormat; use pocketmine\utils\TextFormat;
class Bed extends Transparent{ class Bed extends Transparent{
@ -116,6 +122,21 @@ class Bed extends Transparent{
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true); $this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, true); $this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, true);
$nbt = new CompoundTag("", [
new StringTag("id", Tile::BED),
new ByteTag("color", $item->getDamage() & 0x0f),
new IntTag("x", $block->x),
new IntTag("y", $block->y),
new IntTag("z", $block->z),
]);
$nbt2 = clone $nbt;
$nbt2["x"] = $next->x;
$nbt2["z"] = $next->z;
Tile::createTile(Tile::BED, $this->getLevel(), $nbt);
Tile::createTile(Tile::BED, $this->getLevel(), $nbt2);
return true; return true;
} }
} }
@ -156,9 +177,16 @@ class Bed extends Transparent{
} }
public function getDrops(Item $item){ public function getDrops(Item $item){
$tile = $this->getLevel()->getTile($this);
if($tile instanceof TileBed){
return [ return [
[Item::BED, 0, 1], [Item::BED, $tile->getColor(), 1]
]; ];
}else{
return [
[Item::BED, 14, 1] //Red
];
}
} }
} }

View File

@ -0,0 +1,58 @@
<?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/
*
*
*/
namespace pocketmine\tile;
use pocketmine\level\Level;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
class Bed extends Spawnable{
public function __construct(Level $level, CompoundTag $nbt){
if(!isset($nbt->color) or !($nbt->color instanceof ByteTag)){
$nbt->color = new ByteTag("color", 14); //default to old red
}
parent::__construct($level, $nbt);
}
public function getColor() : int{
return $this->namedtag->color->getValue();
}
public function setColor(int $color){
$this->namedtag["color"] = $color & 0x0f;
$this->onChanged();
}
public function getSpawnCompound() : CompoundTag{
return new CompoundTag("", [
new StringTag("id", Tile::BED),
new IntTag("x", (int) $this->x),
new IntTag("y", (int) $this->y),
new IntTag("z", (int) $this->z),
$this->namedtag->color
]);
}
}

View File

@ -47,6 +47,7 @@ abstract class Tile extends Position{
const MOB_SPAWNER = "MobSpawner"; const MOB_SPAWNER = "MobSpawner";
const SIGN = "Sign"; const SIGN = "Sign";
const SKULL = "Skull"; const SKULL = "Skull";
const BED = "Bed";
public static $tileCount = 1; public static $tileCount = 1;
@ -69,6 +70,7 @@ abstract class Tile extends Position{
public $tickTimer; public $tickTimer;
public static function init(){ public static function init(){
self::registerTile(Bed::class);
self::registerTile(Chest::class); self::registerTile(Chest::class);
self::registerTile(EnchantTable::class); self::registerTile(EnchantTable::class);
self::registerTile(FlowerPot::class); self::registerTile(FlowerPot::class);
@ -113,7 +115,6 @@ abstract class Tile extends Position{
/** /**
* Returns the short save name * Returns the short save name
*
* @return string * @return string
*/ */
public function getSaveId() : string{ public function getSaveId() : string{