mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-20 20:48:06 +00:00
Removed redundant count parameter from item constructors, added some documentation and tightened safety checks
the count parameter is useless since Item ctor should now only be used for constructing item _types_, not actual items. All item creations for inventories etc, should go through the ItemFactory.
This commit is contained in:
parent
1fec16f167
commit
9e142655ea
@ -117,7 +117,10 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
* @param int $meta
|
||||
*/
|
||||
final public function setDamage(int $meta){
|
||||
$this->meta = $meta & 0x0f;
|
||||
if($meta < 0 or $meta > 0xf){
|
||||
throw new \InvalidArgumentException("Block damage values must be 0-15, not $meta");
|
||||
}
|
||||
$this->meta = $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -370,11 +370,14 @@ class BlockFactory{
|
||||
* @return Block
|
||||
*/
|
||||
public static function get(int $id, int $meta = 0, Position $pos = null) : Block{
|
||||
if($meta < 0 or $meta > 0xf){
|
||||
throw new \InvalidArgumentException("Block meta value $meta is out of bounds");
|
||||
}
|
||||
|
||||
try{
|
||||
$block = clone self::$fullList[($id << 4) | $meta];
|
||||
}catch(\RuntimeException $e){
|
||||
//TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour)
|
||||
$block = new UnknownBlock($id, $meta);
|
||||
throw new \InvalidArgumentException("Block ID $id is out of bounds");
|
||||
}
|
||||
|
||||
if($pos !== null){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Apple extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::APPLE, $meta, $count, "Apple");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::APPLE, $meta, "Apple");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Arrow extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::ARROW, $meta, $count, "Arrow");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::ARROW, $meta, "Arrow");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class BakedPotato extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BAKED_POTATO, $meta, $count, "Baked Potato");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BAKED_POTATO, $meta, "Baked Potato");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Bed extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::BED_BLOCK);
|
||||
parent::__construct(self::BED, $meta, $count, "Bed");
|
||||
parent::__construct(self::BED, $meta, "Bed");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Beetroot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BEETROOT, $meta, $count, "Beetroot");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BEETROOT, $meta, "Beetroot");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class BeetrootSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::BEETROOT_BLOCK);
|
||||
parent::__construct(self::BEETROOT_SEEDS, $meta, $count, "Beetroot Seeds");
|
||||
parent::__construct(self::BEETROOT_SEEDS, $meta, "Beetroot Seeds");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class BeetrootSoup extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BEETROOT_SOUP, $meta, $count, "Beetroot Soup");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BEETROOT_SOUP, $meta, "Beetroot Soup");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Boat extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BOAT, $meta, $count, "Boat");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BOAT, $meta, "Boat");
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Book extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BOOK, $meta, $count, "Book");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BOOK, $meta, "Book");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Bow extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BOW, $meta, $count, "Bow");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BOW, $meta, "Bow");
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Bowl extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BOWL, $meta, $count, "Bowl");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BOWL, $meta, "Bowl");
|
||||
}
|
||||
|
||||
//TODO: check fuel
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Bread extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BREAD, $meta, $count, "Bread");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BREAD, $meta, "Bread");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -26,8 +26,8 @@ namespace pocketmine\item;
|
||||
use pocketmine\block\Block;
|
||||
|
||||
class BrewingStand extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = Block::get(Block::BREWING_STAND_BLOCK);
|
||||
parent::__construct(self::BREWING_STAND, $meta, $count, "Brewing Stand");
|
||||
parent::__construct(self::BREWING_STAND, $meta, "Brewing Stand");
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Bucket extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::BUCKET, $meta, $count, "Bucket");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::BUCKET, $meta, "Bucket");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Cake extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::CAKE_BLOCK);
|
||||
parent::__construct(self::CAKE, $meta, $count, "Cake");
|
||||
parent::__construct(self::CAKE, $meta, "Cake");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Carrot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::CARROT_BLOCK);
|
||||
parent::__construct(self::CARROT, $meta, $count, "Carrot");
|
||||
parent::__construct(self::CARROT, $meta, "Carrot");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class ChainBoots extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::CHAIN_BOOTS, $meta, $count, "Chainmail Boots");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::CHAIN_BOOTS, $meta, "Chainmail Boots");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class ChainChestplate extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::CHAIN_CHESTPLATE, $meta, $count, "Chain Chestplate");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::CHAIN_CHESTPLATE, $meta, "Chain Chestplate");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class ChainHelmet extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::CHAIN_HELMET, $meta, $count, "Chainmail Helmet");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::CHAIN_HELMET, $meta, "Chainmail Helmet");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class ChainLeggings extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::CHAIN_LEGGINGS, $meta, $count, "Chain Leggings");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::CHAIN_LEGGINGS, $meta, "Chain Leggings");
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Clock extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::CLOCK, $meta, $count, "Clock");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::CLOCK, $meta, "Clock");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Coal extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COAL, $meta, $count, "Coal");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COAL, $meta, "Coal");
|
||||
if($this->meta === 1){
|
||||
$this->name = "Charcoal";
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Compass extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COMPASS, $meta, $count, "Compass");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COMPASS, $meta, "Compass");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedChicken extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_CHICKEN, $meta, $count, "Cooked Chicken");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COOKED_CHICKEN, $meta, "Cooked Chicken");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedFish extends Fish{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
Food::__construct(self::COOKED_FISH, $meta, $count, $meta === self::FISH_SALMON ? "Cooked Salmon" : "Cooked Fish");
|
||||
public function __construct(int $meta = 0){
|
||||
Food::__construct(self::COOKED_FISH, $meta, $meta === self::FISH_SALMON ? "Cooked Salmon" : "Cooked Fish");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedPorkchop extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_PORKCHOP, $meta, $count, "Cooked Porkchop");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COOKED_PORKCHOP, $meta, "Cooked Porkchop");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class CookedRabbit extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKED_RABBIT, $meta, $count, "Cooked Rabbit");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COOKED_RABBIT, $meta, "Cooked Rabbit");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Cookie extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::COOKIE, $meta, $count, "Cookie");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::COOKIE, $meta, "Cookie");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondAxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_AXE, $meta, $count, "Diamond Axe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_AXE, $meta, "Diamond Axe");
|
||||
}
|
||||
|
||||
public function isAxe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondBoots extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_BOOTS, $meta, $count, "Diamond Boots");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_BOOTS, $meta, "Diamond Boots");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondChestplate extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_CHESTPLATE, $meta, $count, "Diamond Chestplate");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_CHESTPLATE, $meta, "Diamond Chestplate");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondHelmet extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_HELMET, $meta, $count, "Diamond Helmet");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_HELMET, $meta, "Diamond Helmet");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondHoe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_HOE, $meta, $count, "Diamond Hoe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_HOE, $meta, "Diamond Hoe");
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondLeggings extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_LEGGINGS, $meta, $count, "Diamond Leggings");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_LEGGINGS, $meta, "Diamond Leggings");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondPickaxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_PICKAXE, $meta, $count, "Diamond Pickaxe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_PICKAXE, $meta, "Diamond Pickaxe");
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondShovel extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_SHOVEL, $meta, "Diamond Shovel");
|
||||
}
|
||||
|
||||
public function isShovel(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class DiamondSword extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DIAMOND_SWORD, $meta, $count, "Diamond Sword");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DIAMOND_SWORD, $meta, "Diamond Sword");
|
||||
}
|
||||
|
||||
public function isSword(){
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Dye extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::DYE, $meta, $count, "Dye");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::DYE, $meta, "Dye");
|
||||
}
|
||||
|
||||
//TODO: names
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Egg extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::EGG, $meta, $count, "Egg");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::EGG, $meta, "Egg");
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
@ -31,7 +31,7 @@ class Fish extends Food{
|
||||
const FISH_CLOWNFISH = 2;
|
||||
const FISH_PUFFERFISH = 3;
|
||||
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$name = "Raw Fish";
|
||||
if($this->meta === self::FISH_SALMON){
|
||||
$name = "Raw Salmon";
|
||||
@ -40,7 +40,7 @@ class Fish extends Food{
|
||||
}elseif($this->meta === self::FISH_PUFFERFISH){
|
||||
$name = "Pufferfish";
|
||||
}
|
||||
parent::__construct(self::RAW_FISH, $meta, $count, $name);
|
||||
parent::__construct(self::RAW_FISH, $meta, $name);
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class FishingRod extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::FISHING_ROD, $meta, $count, "Fishing Rod");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::FISHING_ROD, $meta, "Fishing Rod");
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
@ -31,8 +31,8 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
|
||||
class FlintSteel extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::FLINT_STEEL, $meta, "Flint and Steel");
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
||||
@ -40,7 +40,7 @@ class FlintSteel extends Tool{
|
||||
$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));
|
||||
$player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 0));
|
||||
}else{
|
||||
$this->meta++;
|
||||
$player->getInventory()->setItemInHand($this);
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class FlowerPot extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::FLOWER_POT_BLOCK);
|
||||
parent::__construct(self::FLOWER_POT, $meta, $count, "Flower Pot");
|
||||
parent::__construct(self::FLOWER_POT, $meta, "Flower Pot");
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class GlassBottle extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GLASS_BOTTLE, $meta, $count, "Glass Bottle");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GLASS_BOTTLE, $meta, "Glass Bottle");
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldAxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_AXE, $meta, $count, "Gold Axe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_AXE, $meta, "Gold Axe");
|
||||
}
|
||||
|
||||
public function isAxe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldBoots extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_BOOTS, $meta, $count, "Gold Boots");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_BOOTS, $meta, "Gold Boots");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldChestplate extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_CHESTPLATE, $meta, $count, "Gold Chestplate");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_CHESTPLATE, $meta, "Gold Chestplate");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldHelmet extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_HELMET, $meta, $count, "Gold Helmet");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_HELMET, $meta, "Gold Helmet");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldHoe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_HOE, $meta, $count, "Gold Hoe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_HOE, $meta, "Gold Hoe");
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldLeggings extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_LEGGINGS, $meta, $count, "Gold Leggings");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_LEGGINGS, $meta, "Gold Leggings");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldPickaxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_PICKAXE, $meta, $count, "Gold Pickaxe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_PICKAXE, $meta, "Gold Pickaxe");
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldShovel extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_SHOVEL, $meta, $count, "Gold Shovel");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_SHOVEL, $meta, "Gold Shovel");
|
||||
}
|
||||
|
||||
public function isShovel(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class GoldSword extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLD_SWORD, $meta, $count, "Gold Sword");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLD_SWORD, $meta, "Gold Sword");
|
||||
}
|
||||
|
||||
public function isSword(){
|
||||
|
@ -29,8 +29,8 @@ use pocketmine\entity\Human;
|
||||
|
||||
class GoldenApple extends Food{
|
||||
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLDEN_APPLE, $meta, $count, "Golden Apple");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLDEN_APPLE, $meta, "Golden Apple");
|
||||
}
|
||||
|
||||
public function canBeConsumedBy(Entity $entity) : bool{
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\entity\Effect;
|
||||
|
||||
class GoldenAppleEnchanted extends GoldenApple{
|
||||
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
Food::__construct(self::ENCHANTED_GOLDEN_APPLE, $meta, $count, "Enchanted Golden Apple"); //skip parent constructor
|
||||
public function __construct(int $meta = 0){
|
||||
Food::__construct(self::ENCHANTED_GOLDEN_APPLE, $meta, "Enchanted Golden Apple"); //skip parent constructor
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class GoldenCarrot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::GOLDEN_CARROT, $meta, $count, "Golden Carrot");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::GOLDEN_CARROT, $meta, "Golden Carrot");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronAxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_AXE, $meta, $count, "Iron Axe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_AXE, $meta, "Iron Axe");
|
||||
}
|
||||
|
||||
public function isAxe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronBoots extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_BOOTS, $meta, $count, "Iron Boots");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_BOOTS, $meta, "Iron Boots");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronChestplate extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_CHESTPLATE, $meta, $count, "Iron Chestplate");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_CHESTPLATE, $meta, "Iron Chestplate");
|
||||
}
|
||||
}
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class IronDoor extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::IRON_DOOR_BLOCK);
|
||||
parent::__construct(self::IRON_DOOR, $meta, $count, "Iron Door");
|
||||
parent::__construct(self::IRON_DOOR, $meta, "Iron Door");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronHelmet extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_HELMET, $meta, $count, "Iron Helmet");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_HELMET, $meta, "Iron Helmet");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronHoe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_HOE, $meta, $count, "Iron Hoe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_HOE, $meta, "Iron Hoe");
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronLeggings extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_LEGGINGS, $meta, $count, "Iron Leggings");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_LEGGINGS, $meta, "Iron Leggings");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronPickaxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_PICKAXE, $meta, $count, "Iron Pickaxe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_PICKAXE, $meta, "Iron Pickaxe");
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronShovel extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_SHOVEL, $meta, $count, "Iron Shovel");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_SHOVEL, $meta, "Iron Shovel");
|
||||
}
|
||||
|
||||
public function isShovel(){
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class IronSword extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::IRON_SWORD, $meta, $count, "Iron Sword");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::IRON_SWORD, $meta, "Iron Sword");
|
||||
}
|
||||
|
||||
public function isSword(){
|
||||
|
@ -183,20 +183,24 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
/** @var CompoundTag|null */
|
||||
private $cachedNBT = null;
|
||||
/** @var int */
|
||||
public $count;
|
||||
public $count = 1;
|
||||
/** @var string */
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param int $count
|
||||
* Constructs a new Item type. This constructor should ONLY be used when constructing a new item TYPE to register
|
||||
* into the index.
|
||||
*
|
||||
* NOTE: This should NOT BE USED for creating items to set into an inventory. Use {@link ItemFactory#get} for that
|
||||
* purpose.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(int $id, int $meta = 0, int $count = 1, string $name = "Unknown"){
|
||||
public function __construct(int $id, int $meta = 0, string $name = "Unknown"){
|
||||
$this->id = $id & 0xffff;
|
||||
$this->meta = $meta !== -1 ? $meta & 0xffff : -1;
|
||||
$this->count = $count;
|
||||
$this->name = $name;
|
||||
if(!isset($this->block) and $this->id <= 0xff and isset(BlockFactory::$list[$this->id])){
|
||||
$this->block = BlockFactory::get($this->id, $this->meta);
|
||||
@ -631,9 +635,12 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return $this
|
||||
*/
|
||||
public function setCount(int $count){
|
||||
$this->count = $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -705,9 +712,12 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
|
||||
/**
|
||||
* @param int $meta
|
||||
* @return $this
|
||||
*/
|
||||
public function setDamage(int $meta){
|
||||
$this->meta = $meta !== -1 ? $meta & 0xFFFF : -1;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,13 +29,18 @@ use pocketmine\block\Block;
|
||||
* Class used for Items that can be Blocks
|
||||
*/
|
||||
class ItemBlock extends Item{
|
||||
public function __construct(Block $block, $meta = 0, int $count = 1){
|
||||
|
||||
/**
|
||||
* @param Block $block
|
||||
* @param int $meta Used in crafting recipes for any-damage ingredients (blocks must have meta values 0-15)
|
||||
*/
|
||||
public function __construct(Block $block, int $meta = 0){
|
||||
$this->block = $block;
|
||||
parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName());
|
||||
parent::__construct($block->getId(), $meta, $block->getName());
|
||||
}
|
||||
|
||||
public function setDamage(int $meta){
|
||||
$this->meta = $meta !== -1 ? $meta & 0xf : -1;
|
||||
$this->meta = $meta;
|
||||
$this->block->setDamage($this->meta !== -1 ? $this->meta : 0);
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ class ItemFactory{
|
||||
self::registerItem(new Bow());
|
||||
self::registerItem(new Arrow());
|
||||
self::registerItem(new Coal());
|
||||
self::registerItem(new Item(Item::DIAMOND, 0, 1, "Diamond"));
|
||||
self::registerItem(new Item(Item::IRON_INGOT, 0, 1, "Iron Ingot"));
|
||||
self::registerItem(new Item(Item::GOLD_INGOT, 0, 1, "Gold Ingot"));
|
||||
self::registerItem(new Item(Item::DIAMOND, 0, "Diamond"));
|
||||
self::registerItem(new Item(Item::IRON_INGOT, 0, "Iron Ingot"));
|
||||
self::registerItem(new Item(Item::GOLD_INGOT, 0, "Gold Ingot"));
|
||||
self::registerItem(new IronSword());
|
||||
self::registerItem(new WoodenSword());
|
||||
self::registerItem(new WoodenShovel());
|
||||
@ -70,15 +70,15 @@ class ItemFactory{
|
||||
self::registerItem(new GoldPickaxe());
|
||||
self::registerItem(new GoldAxe());
|
||||
self::registerItem(new StringItem());
|
||||
self::registerItem(new Item(Item::FEATHER, 0, 1, "Feather"));
|
||||
self::registerItem(new Item(Item::GUNPOWDER, 0, 1, "Gunpowder"));
|
||||
self::registerItem(new Item(Item::FEATHER, 0, "Feather"));
|
||||
self::registerItem(new Item(Item::GUNPOWDER, 0, "Gunpowder"));
|
||||
self::registerItem(new WoodenHoe());
|
||||
self::registerItem(new StoneHoe());
|
||||
self::registerItem(new IronHoe());
|
||||
self::registerItem(new DiamondHoe());
|
||||
self::registerItem(new GoldHoe());
|
||||
self::registerItem(new WheatSeeds());
|
||||
self::registerItem(new Item(Item::WHEAT, 0, 1, "Wheat"));
|
||||
self::registerItem(new Item(Item::WHEAT, 0, "Wheat"));
|
||||
self::registerItem(new Bread());
|
||||
self::registerItem(new LeatherCap());
|
||||
self::registerItem(new LeatherTunic());
|
||||
@ -100,7 +100,7 @@ class ItemFactory{
|
||||
self::registerItem(new GoldChestplate());
|
||||
self::registerItem(new GoldLeggings());
|
||||
self::registerItem(new GoldBoots());
|
||||
self::registerItem(new Item(Item::FLINT, 0, 1, "Flint"));
|
||||
self::registerItem(new Item(Item::FLINT, 0, "Flint"));
|
||||
self::registerItem(new RawPorkchop());
|
||||
self::registerItem(new CookedPorkchop());
|
||||
self::registerItem(new Painting());
|
||||
@ -115,26 +115,26 @@ class ItemFactory{
|
||||
self::registerItem(new Redstone());
|
||||
self::registerItem(new Snowball());
|
||||
self::registerItem(new Boat());
|
||||
self::registerItem(new Item(Item::LEATHER, 0, 1, "Leather"));
|
||||
self::registerItem(new Item(Item::LEATHER, 0, "Leather"));
|
||||
|
||||
self::registerItem(new Item(Item::BRICK, 0, 1, "Brick"));
|
||||
self::registerItem(new Item(Item::CLAY_BALL, 0, 1, "Clay"));
|
||||
self::registerItem(new Item(Item::BRICK, 0, "Brick"));
|
||||
self::registerItem(new Item(Item::CLAY_BALL, 0, "Clay"));
|
||||
self::registerItem(new Sugarcane());
|
||||
self::registerItem(new Item(Item::PAPER, 0, 1, "Paper"));
|
||||
self::registerItem(new Item(Item::PAPER, 0, "Paper"));
|
||||
self::registerItem(new Book());
|
||||
self::registerItem(new Item(Item::SLIME_BALL, 0, 1, "Slimeball"));
|
||||
self::registerItem(new Item(Item::SLIME_BALL, 0, "Slimeball"));
|
||||
//TODO: CHEST_MINECART
|
||||
|
||||
self::registerItem(new Egg());
|
||||
self::registerItem(new Compass());
|
||||
self::registerItem(new FishingRod());
|
||||
self::registerItem(new Clock());
|
||||
self::registerItem(new Item(Item::GLOWSTONE_DUST, 0, 1, "Glowstone Dust"));
|
||||
self::registerItem(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust"));
|
||||
self::registerItem(new Fish());
|
||||
self::registerItem(new CookedFish());
|
||||
self::registerItem(new Dye());
|
||||
self::registerItem(new Item(Item::BONE, 0, 1, "Bone"));
|
||||
self::registerItem(new Item(Item::SUGAR, 0, 1, "Sugar"));
|
||||
self::registerItem(new Item(Item::BONE, 0, "Bone"));
|
||||
self::registerItem(new Item(Item::SUGAR, 0, "Sugar"));
|
||||
self::registerItem(new Cake());
|
||||
self::registerItem(new Bed());
|
||||
//TODO: REPEATER
|
||||
@ -152,23 +152,23 @@ class ItemFactory{
|
||||
//TODO: ENDER_PEARL
|
||||
//TODO: BLAZE_ROD
|
||||
//TODO: GHAST_TEAR
|
||||
self::registerItem(new Item(Item::GOLD_NUGGET, 0, 1, "Gold Nugget"));
|
||||
self::registerItem(new Item(Item::GOLD_NUGGET, 0, "Gold Nugget"));
|
||||
self::registerItem(new NetherWart());
|
||||
self::registerItem(new Potion());
|
||||
self::registerItem(new GlassBottle());
|
||||
self::registerItem(new SpiderEye());
|
||||
self::registerItem(new Item(Item::FERMENTED_SPIDER_EYE, 0, 1, "Fermented Spider Eye"));
|
||||
self::registerItem(new Item(Item::BLAZE_POWDER, 0, 1, "Blaze Powder"));
|
||||
self::registerItem(new Item(Item::MAGMA_CREAM, 0, 1, "Magma Cream"));
|
||||
self::registerItem(new Item(Item::FERMENTED_SPIDER_EYE, 0, "Fermented Spider Eye"));
|
||||
self::registerItem(new Item(Item::BLAZE_POWDER, 0, "Blaze Powder"));
|
||||
self::registerItem(new Item(Item::MAGMA_CREAM, 0, "Magma Cream"));
|
||||
self::registerItem(new BrewingStand());
|
||||
//TODO: CAULDRON
|
||||
//TODO: ENDER_EYE
|
||||
self::registerItem(new Item(Item::GLISTERING_MELON, 0, 1, "Glistering Melon"));
|
||||
self::registerItem(new Item(Item::GLISTERING_MELON, 0, "Glistering Melon"));
|
||||
self::registerItem(new SpawnEgg());
|
||||
//TODO: BOTTLE_O_ENCHANTING
|
||||
//TODO: FIREBALL
|
||||
|
||||
self::registerItem(new Item(Item::EMERALD, 0, 1, "Emerald"));
|
||||
self::registerItem(new Item(Item::EMERALD, 0, "Emerald"));
|
||||
self::registerItem(new ItemFrame());
|
||||
self::registerItem(new FlowerPot());
|
||||
self::registerItem(new Carrot());
|
||||
@ -179,16 +179,16 @@ class ItemFactory{
|
||||
self::registerItem(new GoldenCarrot());
|
||||
self::registerItem(new Skull());
|
||||
//TODO: CARROTONASTICK
|
||||
self::registerItem(new Item(Item::NETHER_STAR, 0, 1, "Nether Star"));
|
||||
self::registerItem(new Item(Item::NETHER_STAR, 0, "Nether Star"));
|
||||
self::registerItem(new PumpkinPie());
|
||||
|
||||
//TODO: ENCHANTED_BOOK
|
||||
//TODO: COMPARATOR
|
||||
self::registerItem(new Item(Item::NETHER_BRICK, 0, 1, "Nether Brick"));
|
||||
self::registerItem(new Item(Item::NETHER_QUARTZ, 0, 1, "Nether Quartz"));
|
||||
self::registerItem(new Item(Item::NETHER_BRICK, 0, "Nether Brick"));
|
||||
self::registerItem(new Item(Item::NETHER_QUARTZ, 0, "Nether Quartz"));
|
||||
//TODO: MINECART_WITH_TNT
|
||||
//TODO: HOPPER_MINECART
|
||||
self::registerItem(new Item(Item::PRISMARINE_SHARD, 0, 1, "Prismarine Shard"));
|
||||
self::registerItem(new Item(Item::PRISMARINE_SHARD, 0, "Prismarine Shard"));
|
||||
//TODO: HOPPER
|
||||
//TODO: RABBIT
|
||||
self::registerItem(new CookedRabbit());
|
||||
@ -201,7 +201,7 @@ class ItemFactory{
|
||||
//TODO: DIAMOND_HORSE_ARMOR
|
||||
//TODO: LEAD
|
||||
//TODO: NAMETAG
|
||||
self::registerItem(new Item(Item::PRISMARINE_CRYSTALS, 0, 1, "Prismarine Crystals"));
|
||||
self::registerItem(new Item(Item::PRISMARINE_CRYSTALS, 0, "Prismarine Crystals"));
|
||||
//TODO: MUTTONRAW
|
||||
//TODO: COOKED_MUTTON
|
||||
|
||||
@ -272,28 +272,36 @@ class ItemFactory{
|
||||
* @param CompoundTag|string $tags
|
||||
*
|
||||
* @return Item
|
||||
* @throws \TypeError
|
||||
*/
|
||||
public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{
|
||||
if(!is_string($tags) and !($tags instanceof CompoundTag)){
|
||||
throw new \TypeError("`tags` argument must be a string or CompoundTag instance, " . (is_object($tags) ? "instance of " . get_class($tags) : gettype($tags)) . " given");
|
||||
}
|
||||
|
||||
$item = null;
|
||||
try{
|
||||
if($id < 256){
|
||||
return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags);
|
||||
/* Blocks must have a damage value 0-15, but items can have damage value -1 to indicate that they are
|
||||
* crafting ingredients with any-damage. */
|
||||
$item = new ItemBlock(BlockFactory::get($id, $meta !== -1 ? $meta : 0), $meta);
|
||||
}else{
|
||||
/** @var Item|null $item */
|
||||
$item = self::$list[$id];
|
||||
if($item === null){
|
||||
return (new Item($id, $meta, $count))->setCompoundTag($tags);
|
||||
}else{
|
||||
$item = clone $item;
|
||||
$item->setDamage($meta);
|
||||
$item->setCount($count);
|
||||
$item->setCompoundTag($tags);
|
||||
|
||||
return $item;
|
||||
/** @var Item|null $listed */
|
||||
$listed = self::$list[$id];
|
||||
if($listed !== null){
|
||||
$item = clone $listed;
|
||||
}
|
||||
}
|
||||
}catch(\RuntimeException $e){
|
||||
return (new Item($id, $meta, $count))->setCompoundTag($tags);
|
||||
throw new \InvalidArgumentException("Item ID $id is invalid or out of bounds");
|
||||
}
|
||||
|
||||
$item = ($item ?? new Item($id, $meta));
|
||||
|
||||
$item->setDamage($meta);
|
||||
$item->setCount($count);
|
||||
$item->setCompoundTag($tags);
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class ItemFrame extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::ITEM_FRAME_BLOCK);
|
||||
parent::__construct(self::ITEM_FRAME, $meta, $count, "Item Frame");
|
||||
parent::__construct(self::ITEM_FRAME, $meta, "Item Frame");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class LeatherBoots extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::LEATHER_BOOTS, $meta, $count, "Leather Boots");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::LEATHER_BOOTS, $meta, "Leather Boots");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class LeatherCap extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::LEATHER_CAP, $meta, $count, "Leather Cap");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::LEATHER_CAP, $meta, "Leather Cap");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class LeatherPants extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::LEATHER_PANTS, $meta, $count, "Leather Pants");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::LEATHER_PANTS, $meta, "Leather Pants");
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class LeatherTunic extends Armor{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::LEATHER_TUNIC, $meta, $count, "Leather Tunic");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::LEATHER_TUNIC, $meta, "Leather Tunic");
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Melon extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::MELON, $meta, $count, "Melon");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::MELON, $meta, "Melon");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class MelonSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::MELON_STEM);
|
||||
parent::__construct(self::MELON_SEEDS, $meta, $count, "Melon Seeds");
|
||||
parent::__construct(self::MELON_SEEDS, $meta, "Melon Seeds");
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Minecart extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::MINECART, $meta, $count, "Minecart");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::MINECART, $meta, "Minecart");
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class MushroomStew extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::MUSHROOM_STEW, $meta, $count, "Mushroom Stew");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::MUSHROOM_STEW, $meta, "Mushroom Stew");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class NetherWart extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::NETHER_WART_PLANT);
|
||||
parent::__construct(self::NETHER_WART, $meta, $count, "Nether Wart");
|
||||
parent::__construct(self::NETHER_WART, $meta, "Nether Wart");
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Painting extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::PAINTING, $meta, $count, "Painting");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::PAINTING, $meta, "Painting");
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Potato extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::POTATO_BLOCK);
|
||||
parent::__construct(self::POTATO, $meta, $count, "Potato");
|
||||
parent::__construct(self::POTATO, $meta, "Potato");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -26,8 +26,8 @@ namespace pocketmine\item;
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
class Potion extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::POTION, $meta, $count, "Potion");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::POTION, $meta, "Potion");
|
||||
}
|
||||
|
||||
public function canBeConsumed() : bool{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class PumpkinPie extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::PUMPKIN_PIE, $meta, $count, "Pumpkin Pie");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::PUMPKIN_PIE, $meta, "Pumpkin Pie");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class PumpkinSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::PUMPKIN_STEM);
|
||||
parent::__construct(self::PUMPKIN_SEEDS, $meta, $count, "Pumpkin Seeds");
|
||||
parent::__construct(self::PUMPKIN_SEEDS, $meta, "Pumpkin Seeds");
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class RawBeef extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_BEEF, $meta, $count, "Raw Beef");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::RAW_BEEF, $meta, "Raw Beef");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -26,8 +26,8 @@ namespace pocketmine\item;
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class RawChicken extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_CHICKEN, $meta, $count, "Raw Chicken");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::RAW_CHICKEN, $meta, "Raw Chicken");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class RawPorkchop extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::RAW_PORKCHOP, $meta, $count, "Raw Porkchop");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::RAW_PORKCHOP, $meta, "Raw Porkchop");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Redstone extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::REDSTONE_WIRE);
|
||||
parent::__construct(self::REDSTONE, $meta, $count, "Redstone");
|
||||
parent::__construct(self::REDSTONE, $meta, "Redstone");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Shears extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::SHEARS, $meta, $count, "Shears");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::SHEARS, $meta, "Shears");
|
||||
}
|
||||
|
||||
public function getMaxDurability(){
|
||||
|
@ -27,9 +27,9 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Sign extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::SIGN_POST);
|
||||
parent::__construct(self::SIGN, $meta, $count, "Sign");
|
||||
parent::__construct(self::SIGN, $meta, "Sign");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -27,8 +27,8 @@ use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Skull extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
public function __construct(int $meta = 0){
|
||||
$this->block = BlockFactory::get(Block::SKULL_BLOCK);
|
||||
parent::__construct(self::SKULL, $meta, $count, "Mob Head");
|
||||
parent::__construct(self::SKULL, $meta, "Mob Head");
|
||||
}
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Snowball extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::SNOWBALL, $meta, $count, "Snowball");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::SNOWBALL, $meta, "Snowball");
|
||||
}
|
||||
|
||||
public function getMaxStackSize(){
|
||||
|
@ -35,8 +35,8 @@ use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\Player;
|
||||
|
||||
class SpawnEgg extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::SPAWN_EGG, $meta, $count, "Spawn Egg");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::SPAWN_EGG, $meta, "Spawn Egg");
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
||||
|
@ -26,8 +26,8 @@ namespace pocketmine\item;
|
||||
use pocketmine\entity\Effect;
|
||||
|
||||
class SpiderEye extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::SPIDER_EYE, $meta, $count, "Spider Eye");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::SPIDER_EYE, $meta, "Spider Eye");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
class Steak extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::STEAK, $meta, $count, "Steak");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::STEAK, $meta, "Steak");
|
||||
}
|
||||
|
||||
public function getFoodRestore() : int{
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class Stick extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::STICK, $meta, $count, "Stick");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::STICK, $meta, "Stick");
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class StoneAxe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::STONE_AXE, $meta, $count, "Stone Axe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::STONE_AXE, $meta, "Stone Axe");
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,8 +25,8 @@ namespace pocketmine\item;
|
||||
|
||||
|
||||
class StoneHoe extends Tool{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(self::STONE_HOE, $meta, $count, "Stone Hoe");
|
||||
public function __construct(int $meta = 0){
|
||||
parent::__construct(self::STONE_HOE, $meta, "Stone Hoe");
|
||||
}
|
||||
|
||||
public function isHoe(){
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user