diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 70bee6363..7285c206e 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -107,6 +107,7 @@ use pocketmine\tile\Chest; use pocketmine\tile\EnchantTable; use pocketmine\tile\FlowerPot; use pocketmine\tile\Furnace; +use pocketmine\tile\ItemFrame; use pocketmine\tile\Sign; use pocketmine\tile\Skull; use pocketmine\tile\Tile; @@ -2452,6 +2453,7 @@ class Server{ Tile::registerTile(EnchantTable::class); Tile::registerTile(FlowerPot::class); Tile::registerTile(Furnace::class); + Tile::registerTile(ItemFrame::class); Tile::registerTile(Sign::class); Tile::registerTile(Skull::class); } diff --git a/src/pocketmine/tile/FlowerPot.php b/src/pocketmine/tile/FlowerPot.php index 2a2d33668..49561c214 100644 --- a/src/pocketmine/tile/FlowerPot.php +++ b/src/pocketmine/tile/FlowerPot.php @@ -31,10 +31,10 @@ use pocketmine\nbt\tag\StringTag; class FlowerPot extends Spawnable{ public function __construct(Chunk $chunk, CompoundTag $nbt){ - if(!isset($nbt->Item)){ + if(!isset($nbt->item)){ $nbt->item = new ShortTag("item", 0); } - if(!isset($nbt->Data)){ + if(!isset($nbt->mData)){ $nbt->mData = new IntTag("mData", 0); } parent::__construct($chunk, $nbt); @@ -69,12 +69,7 @@ class FlowerPot extends Spawnable{ public function setItem(Item $item){ $this->namedtag["item"] = $item->getId(); $this->namedtag["mData"] = $item->getDamage(); - $this->spawnToAll(); - - if($this->chunk){ - $this->chunk->setChanged(); - $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ()); - } + $this->onChanged(); } public function removeItem(){ @@ -91,8 +86,8 @@ class FlowerPot extends Spawnable{ new IntTag("x", (int) $this->x), new IntTag("y", (int) $this->y), new IntTag("z", (int) $this->z), - new ShortTag("item", (int) $this->namedtag["item"]), - new IntTag("mData", (int) $this->namedtag["mData"]) + $this->namedtag->item, + $this->namedtag->mData ]); } } \ No newline at end of file diff --git a/src/pocketmine/tile/ItemFrame.php b/src/pocketmine/tile/ItemFrame.php new file mode 100644 index 000000000..a902d83dc --- /dev/null +++ b/src/pocketmine/tile/ItemFrame.php @@ -0,0 +1,106 @@ +ItemRotation)){ + $nbt->ItemRotation = new ByteTag("ItemRotation", 0); + } + + if(!isset($nbt->ItemDropChance)){ + $nbt->ItemDropChance = new FloatTag("ItemDropChance", 1.0); + } + + parent::__construct($chunk, $nbt); + } + + public function dropItem(){ + if(lcg_value() < $this->getDropChance() and $this->hasItem()){ + $this->level->dropItem($this, $this->getItem()); + } + $this->setItem(null); + } + + public function hasItem() : bool{ + return $this->getItem()->getId() !== Item::AIR; + } + + public function getItem() : Item{ + if(isset($this->namedtag->Item)){ + return Item::nbtDeserialize($this->namedtag->Item); + }else{ + return Item::get(Item::AIR); + } + } + + public function setItem(Item $item = null){ + if($item !== null and $item->getId() !== Item::AIR){ + $this->namedtag->Item = $item->nbtSerialize(-1, "Item"); + }else{ + unset($this->namedtag->Item); + } + $this->onChanged(); + } + + public function getItemRotation() : int{ + return $this->namedtag->ItemRotation->getValue(); + } + + public function setItemRotation(int $rotation){ + $this->namedtag->ItemRotation = new ByteTag("ItemRotation", $rotation); + $this->onChanged(); + } + + public function getItemDropChance() : float{ + return $this->namedtag->ItemDropChance->getValue(); + } + + public function setItemDropChance(float $chance){ + $this->namedtag->ItemDropChance = new FloatTag("ItemDropChance", $chance); + $this->onChanged(); + } + + public function getSpawnCompound(){ + $tag = new CompoundTag("", [ + new StringTag("id", Tile::ITEM_FRAME), + new IntTag("x", (int) $this->x), + new IntTag("y", (int) $this->y), + new IntTag("z", (int) $this->z), + $this->namedtag->ItemDropChance, + $this->namedtag->ItemRotation, + ]); + if($this->hasItem()){ + $tag->Item = $this->namedtag->Item; + } + return $tag; + } +} \ No newline at end of file diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index 3ec735630..7d7671de7 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -55,12 +55,7 @@ class Sign extends Spawnable{ $this->namedtag->Text2 = new StringTag("Text2", $line2); $this->namedtag->Text3 = new StringTag("Text3", $line3); $this->namedtag->Text4 = new StringTag("Text4", $line4); - $this->spawnToAll(); - - if($this->chunk){ - $this->chunk->setChanged(); - $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ()); - } + $this->onChanged(); return true; } diff --git a/src/pocketmine/tile/Skull.php b/src/pocketmine/tile/Skull.php index a65cb11a2..d0066b6b5 100644 --- a/src/pocketmine/tile/Skull.php +++ b/src/pocketmine/tile/Skull.php @@ -47,12 +47,7 @@ class Skull extends Spawnable{ public function setType($type){ if($type >= 0 && $type <= 4){ $this->namedtag->SkullType = new ByteTag("SkullType", $type); - $this->spawnToAll(); - - if($this->chunk){ - $this->chunk->setChanged(); - $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ()); - } + $this->onChanged(); return true; } return false; diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index b76f0a164..8d6e25070 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -67,4 +67,13 @@ abstract class Spawnable extends Tile{ } } } + + protected function onChanged(){ + $this->spawnToAll(); + + if($this->chunk !== null){ + $this->chunk->setChanged(); + $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ()); + } + } } diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index cbe2d0300..b2f2e9e52 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -33,14 +33,16 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\StringTag; abstract class Tile extends Position{ - const SIGN = "Sign"; - const CHEST = "Chest"; - const FURNACE = "Furnace"; - const FLOWER_POT = "FlowerPot"; - const MOB_SPAWNER = "MobSpawner"; - const SKULL = "Skull"; + const BREWING_STAND = "BrewingStand"; + const CHEST = "Chest"; const ENCHANT_TABLE = "EnchantTable"; + const FLOWER_POT = "FlowerPot"; + const FURNACE = "Furnace"; + const ITEM_FRAME = "ItemFrame"; + const MOB_SPAWNER = "MobSpawner"; + const SIGN = "Sign"; + const SKULL = "Skull"; public static $tileCount = 1;