Move block registration to its own class

This commit is contained in:
Dylan K. Taylor
2017-08-20 18:05:01 +01:00
committed by GitHub
parent 9451dd361e
commit 02f42eba48
62 changed files with 560 additions and 482 deletions

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Bed extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::BED_BLOCK);
$this->block = BlockFactory::get(Block::BED_BLOCK);
parent::__construct(self::BED, $meta, $count, "Bed");
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class BeetrootSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::BEETROOT_BLOCK);
$this->block = BlockFactory::get(Block::BEETROOT_BLOCK);
parent::__construct(self::BEETROOT_SEEDS, $meta, $count, "Beetroot Seeds");
}
}

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\block\Air;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\Liquid;
use pocketmine\event\player\PlayerBucketFillEvent;
use pocketmine\level\Level;
@ -49,7 +50,7 @@ class Bucket extends Item{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
$targetBlock = Block::get($this->meta);
$targetBlock = BlockFactory::get($this->meta);
if($targetBlock instanceof Air){
if($target instanceof Liquid and $target->getDamage() === 0){
@ -57,7 +58,7 @@ class Bucket extends Item{
$result->setDamage($target->getId());
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if(!$ev->isCancelled()){
$player->getLevel()->setBlock($target, Block::get(Block::AIR), true, true);
$player->getLevel()->setBlock($target, BlockFactory::get(Block::AIR), true, true);
if($player->isSurvival()){
$player->getInventory()->setItemInHand($ev->getItem());
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Cake extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::CAKE_BLOCK);
$this->block = BlockFactory::get(Block::CAKE_BLOCK);
parent::__construct(self::CAKE, $meta, $count, "Cake");
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Carrot extends Food{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::CARROT_BLOCK);
$this->block = BlockFactory::get(Block::CARROT_BLOCK);
parent::__construct(self::CARROT, $meta, $count, "Carrot");
}

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\Fire;
use pocketmine\block\Solid;
use pocketmine\level\Level;
@ -37,7 +38,7 @@ class FlintSteel extends Tool{
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
if($block->getId() === self::AIR and ($target instanceof Solid)){
$level->setBlock($block, Block::get(Block::FIRE), true);
$level->setBlock($block, BlockFactory::get(Block::FIRE), true);
if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){
if($this->getDamage() >= $this->getMaxDurability()){
$player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class FlowerPot extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::FLOWER_POT_BLOCK);
$this->block = BlockFactory::get(Block::FLOWER_POT_BLOCK);
parent::__construct(self::FLOWER_POT, $meta, $count, "Flower Pot");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class IronDoor extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::IRON_DOOR_BLOCK);
$this->block = BlockFactory::get(Block::IRON_DOOR_BLOCK);
parent::__construct(self::IRON_DOOR, $meta, $count, "Iron Door");
}

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\entity\Entity;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\level\Level;
@ -328,7 +329,7 @@ class Item implements ItemIds, \JsonSerializable{
public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{
try{
if($id < 256){
return (new ItemBlock(Block::get($id, $meta), $meta, $count))->setCompoundTag($tags);
return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags);
}else{
$class = self::$list[$id];
if($class === null){
@ -388,8 +389,8 @@ class Item implements ItemIds, \JsonSerializable{
$this->meta = $meta !== -1 ? $meta & 0xffff : -1;
$this->count = $count;
$this->name = $name;
if(!isset($this->block) and $this->id <= 0xff and isset(Block::$list[$this->id])){
$this->block = Block::get($this->id, $this->meta);
if(!isset($this->block) and $this->id <= 0xff and isset(BlockFactory::$list[$this->id])){
$this->block = BlockFactory::get($this->id, $this->meta);
$this->name = $this->block->getName();
}
}
@ -874,7 +875,7 @@ class Item implements ItemIds, \JsonSerializable{
if($this->block instanceof Block){
return clone $this->block;
}else{
return Block::get(self::AIR);
return BlockFactory::get(self::AIR);
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class ItemFrame extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::ITEM_FRAME_BLOCK);
$this->block = BlockFactory::get(Block::ITEM_FRAME_BLOCK);
parent::__construct(self::ITEM_FRAME, $meta, $count, "Item Frame");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class MelonSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::MELON_STEM);
$this->block = BlockFactory::get(Block::MELON_STEM);
parent::__construct(self::MELON_SEEDS, $meta, $count, "Melon Seeds");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class NetherWart extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::NETHER_WART_PLANT);
$this->block = BlockFactory::get(Block::NETHER_WART_PLANT);
parent::__construct(self::NETHER_WART, $meta, $count, "Nether Wart");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Potato extends Food{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::POTATO_BLOCK);
$this->block = BlockFactory::get(Block::POTATO_BLOCK);
parent::__construct(self::POTATO, $meta, $count, "Potato");
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class PumpkinSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::PUMPKIN_STEM);
$this->block = BlockFactory::get(Block::PUMPKIN_STEM);
parent::__construct(self::PUMPKIN_SEEDS, $meta, $count, "Pumpkin Seeds");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Sign extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::SIGN_POST);
$this->block = BlockFactory::get(Block::SIGN_POST);
parent::__construct(self::SIGN, $meta, $count, "Sign");
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Skull extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::SKULL_BLOCK);
$this->block = BlockFactory::get(Block::SKULL_BLOCK);
parent::__construct(self::SKULL, $meta, $count, "Mob Head");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Sugarcane extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::SUGARCANE_BLOCK);
$this->block = BlockFactory::get(Block::SUGARCANE_BLOCK);
parent::__construct(self::SUGARCANE, $meta, $count, "Sugar Cane");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class WheatSeeds extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::WHEAT_BLOCK);
$this->block = BlockFactory::get(Block::WHEAT_BLOCK);
parent::__construct(self::WHEAT_SEEDS, $meta, $count, "Wheat Seeds");
}
}

View File

@ -24,10 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class WoodenDoor extends Item{
public function __construct($meta = 0, $count = 1){
$this->block = Block::get(Block::WOODEN_DOOR_BLOCK);
$this->block = BlockFactory::get(Block::WOODEN_DOOR_BLOCK);
parent::__construct(self::WOODEN_DOOR, $meta, $count, "Wooden Door");
}