From 3135fe3c69eec98b41b131c190507f26b4c7e64b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 4 Aug 2017 13:02:24 +0100 Subject: [PATCH] Added API method Block->getItemId(), cleaned up excess wooden stairs and fence-gate classes, added more wooden door types --- src/pocketmine/block/AcaciaWoodStairs.php | 33 ----- src/pocketmine/block/BirchWoodStairs.php | 33 ----- src/pocketmine/block/Block.php | 127 +++++++++++------- src/pocketmine/block/BlockIds.php | 2 +- src/pocketmine/block/DarkOakWoodStairs.php | 33 ----- src/pocketmine/block/FenceGate.php | 10 -- src/pocketmine/block/FenceGateAcacia.php | 34 ----- src/pocketmine/block/FenceGateBirch.php | 34 ----- src/pocketmine/block/FenceGateDarkOak.php | 34 ----- src/pocketmine/block/FenceGateJungle.php | 34 ----- src/pocketmine/block/FenceGateSpruce.php | 34 ----- src/pocketmine/block/JungleWoodStairs.php | 33 ----- src/pocketmine/block/SpruceWoodStairs.php | 33 ----- src/pocketmine/block/WoodenDoor.php | 12 +- .../{WoodStairs.php => WoodenStairs.php} | 12 +- src/pocketmine/item/Item.php | 20 ++- 16 files changed, 87 insertions(+), 431 deletions(-) delete mode 100644 src/pocketmine/block/AcaciaWoodStairs.php delete mode 100644 src/pocketmine/block/BirchWoodStairs.php delete mode 100644 src/pocketmine/block/DarkOakWoodStairs.php delete mode 100644 src/pocketmine/block/FenceGateAcacia.php delete mode 100644 src/pocketmine/block/FenceGateBirch.php delete mode 100644 src/pocketmine/block/FenceGateDarkOak.php delete mode 100644 src/pocketmine/block/FenceGateJungle.php delete mode 100644 src/pocketmine/block/FenceGateSpruce.php delete mode 100644 src/pocketmine/block/JungleWoodStairs.php delete mode 100644 src/pocketmine/block/SpruceWoodStairs.php rename src/pocketmine/block/{WoodStairs.php => WoodenStairs.php} (84%) diff --git a/src/pocketmine/block/AcaciaWoodStairs.php b/src/pocketmine/block/AcaciaWoodStairs.php deleted file mode 100644 index 60d7f944a..000000000 --- a/src/pocketmine/block/AcaciaWoodStairs.php +++ /dev/null @@ -1,33 +0,0 @@ -id = $id; + $this->meta = $meta; + $this->fallbackName = $name; + $this->itemId = $itemId; + } + + /** + * @return string + */ + public function getName(){ + return $this->fallbackName; + } + + /** + * @return int + */ + final public function getId(){ + return $this->id; + } + + /** + * Returns the ID of the item form of the block. + * Used for drops for blocks (some blocks such as doors have a different item ID). + * + * @return int + */ + public function getItemId() : int{ + return $this->itemId ?? $this->getId(); + } + + /** + * @return int + */ + final public function getDamage(){ + return $this->meta; + } + /** - * @param int $id * @param int $meta */ - public function __construct($id, $meta = 0){ - $this->id = (int) $id; - $this->meta = (int) $meta; + final public function setDamage($meta){ + $this->meta = $meta & 0x0f; } /** @@ -514,38 +566,11 @@ class Block extends Position implements BlockIds, Metadatable{ return false; } - /** - * @return string - */ - public function getName(){ - return "Unknown"; - } - - /** - * @return int - */ - final public function getId(){ - return $this->id; - } public function addVelocityToEntity(Entity $entity, Vector3 $vector){ } - /** - * @return int - */ - final public function getDamage(){ - return $this->meta; - } - - /** - * @param int $meta - */ - final public function setDamage($meta){ - $this->meta = $meta & 0x0f; - } - /** * Sets the block position to a new Position object * @@ -571,7 +596,7 @@ class Block extends Position implements BlockIds, Metadatable{ return []; }else{ return [ - [$this->getId(), $this->getDamage(), 1], + [$this->getItemId(), $this->getDamage(), 1], ]; } } diff --git a/src/pocketmine/block/BlockIds.php b/src/pocketmine/block/BlockIds.php index db59687ab..58dfb7674 100644 --- a/src/pocketmine/block/BlockIds.php +++ b/src/pocketmine/block/BlockIds.php @@ -89,7 +89,7 @@ interface BlockIds{ const FURNACE = 61; const BURNING_FURNACE = 62, LIT_FURNACE = 62; const SIGN_POST = 63, STANDING_SIGN = 63; - const WOODEN_DOOR_BLOCK = 64; + const OAK_DOOR_BLOCK = 64, WOODEN_DOOR_BLOCK = 64; const LADDER = 65; const RAIL = 66; const COBBLESTONE_STAIRS = 67, STONE_STAIRS = 67; diff --git a/src/pocketmine/block/DarkOakWoodStairs.php b/src/pocketmine/block/DarkOakWoodStairs.php deleted file mode 100644 index b41fd0ba1..000000000 --- a/src/pocketmine/block/DarkOakWoodStairs.php +++ /dev/null @@ -1,33 +0,0 @@ -meta = $meta; - } - - public function getName(){ - return "Oak Fence Gate"; - } - public function getHardness(){ return 2; } diff --git a/src/pocketmine/block/FenceGateAcacia.php b/src/pocketmine/block/FenceGateAcacia.php deleted file mode 100644 index 5d38d1822..000000000 --- a/src/pocketmine/block/FenceGateAcacia.php +++ /dev/null @@ -1,34 +0,0 @@ -meta = $meta; - } - - public function getName(){ - return "Wooden Door Block"; - } - public function getHardness(){ return 3; } @@ -48,7 +38,7 @@ class WoodenDoor extends Door{ public function getDrops(Item $item){ return [ - [Item::WOODEN_DOOR, 0, 1], + [$this->getItemId(), 0, 1], ]; } } \ No newline at end of file diff --git a/src/pocketmine/block/WoodStairs.php b/src/pocketmine/block/WoodenStairs.php similarity index 84% rename from src/pocketmine/block/WoodStairs.php rename to src/pocketmine/block/WoodenStairs.php index 7d4207a3e..1b8034aec 100644 --- a/src/pocketmine/block/WoodStairs.php +++ b/src/pocketmine/block/WoodenStairs.php @@ -26,17 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; -class WoodStairs extends Stair{ - - protected $id = self::OAK_STAIRS; - - public function __construct($meta = 0){ - $this->meta = $meta; - } - - public function getName(){ - return "Oak Wood Stairs"; - } +class WoodenStairs extends Stair{ public function getHardness(){ return 2; diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 09cf294b4..58ae850f0 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -246,12 +246,6 @@ class Item implements ItemIds, \JsonSerializable{ self::$list[self::BEETROOT_SOUP] = BeetrootSoup::class; self::$list[self::ENCHANTED_GOLDEN_APPLE] = GoldenAppleEnchanted::class; - - for($i = 0; $i < 256; ++$i){ - if(Block::$list[$i] !== null){ - self::$list[$i] = Block::$list[$i]; - } - } } self::initCreativeItems(); @@ -333,13 +327,15 @@ class Item implements ItemIds, \JsonSerializable{ */ public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{ try{ - $class = self::$list[$id]; - if($class === null){ - return (new Item($id, $meta, $count))->setCompoundTag($tags); - }elseif($id < 256){ - return (new ItemBlock(new $class($meta), $meta, $count))->setCompoundTag($tags); + if($id < 256){ + return (new ItemBlock(Block::get($id, $meta), $meta, $count))->setCompoundTag($tags); }else{ - return (new $class($meta, $count))->setCompoundTag($tags); + $class = self::$list[$id]; + if($class === null){ + return (new Item($id, $meta, $count))->setCompoundTag($tags); + }else{ + return (new $class($meta, $count))->setCompoundTag($tags); + } } }catch(\RuntimeException $e){ return (new Item($id, $meta, $count))->setCompoundTag($tags);