Some cleanup to how tiles are created

This commit is contained in:
Dylan K. Taylor
2017-10-11 18:07:20 +01:00
parent be2d134994
commit b7a9e10d49
17 changed files with 155 additions and 205 deletions

View File

@ -26,9 +26,6 @@ namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\{
ByteTag, CompoundTag, FloatTag, IntTag, StringTag
};
use pocketmine\Player;
use pocketmine\tile\ItemFrame as TileItemFrame;
use pocketmine\tile\Tile;
@ -49,15 +46,7 @@ class ItemFrame extends Flowable{
public function onActivate(Item $item, Player $player = null) : bool{
$tile = $this->level->getTile($this);
if(!($tile instanceof TileItemFrame)){
$nbt = new CompoundTag("", [
new StringTag("id", Tile::ITEM_FRAME),
new IntTag("x", $this->x),
new IntTag("y", $this->y),
new IntTag("z", $this->z),
new FloatTag("ItemDropChance", 1.0),
new ByteTag("ItemRotation", 0)
]);
$tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), $nbt);
$tile = Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this));
}
if($tile->hasItem()){
@ -111,22 +100,7 @@ class ItemFrame extends Flowable{
$this->meta = $faces[$face];
$this->level->setBlock($blockReplace, $this, true, true);
$nbt = new CompoundTag("", [
new StringTag("id", Tile::ITEM_FRAME),
new IntTag("x", $blockReplace->x),
new IntTag("y", $blockReplace->y),
new IntTag("z", $blockReplace->z),
new FloatTag("ItemDropChance", 1.0),
new ByteTag("ItemRotation", 0)
]);
if($item->hasCustomBlockData()){
foreach($item->getCustomBlockData() as $key => $v){
$nbt->{$key} = $v;
}
}
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), $nbt);
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel(), TileItemFrame::createNBT($this, $face, $item, $player));
return true;