Merge branch 'master' into mcpe-1.2

This commit is contained in:
Dylan K. Taylor
2017-08-27 16:09:23 +01:00
205 changed files with 1131 additions and 1493 deletions

View File

@ -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{

View File

@ -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");
}
}

View File

@ -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{

View File

@ -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(){

View File

@ -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{

View File

@ -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");
}
}

View File

@ -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(){

View File

@ -1,30 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class BlazePowder extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::BLAZE_POWDER, $meta, $count, "Blaze Powder");
}
}

View File

@ -24,11 +24,13 @@ 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{
return 1200; //400 in PC
}
//TODO
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Bone extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::BONE, $meta, $count, "Bone");
}
}

View File

@ -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");
}
}

View File

@ -23,14 +23,103 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\Entity;
use pocketmine\entity\Projectile;
use pocketmine\event\entity\EntityShootBowEvent;
use pocketmine\event\entity\ProjectileLaunchEvent;
use pocketmine\level\sound\LaunchSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\Player;
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{
return 200;
}
public function getMaxDurability(){
return 385;
}
public function onReleaseUsing(Player $player) : bool{
if($player->isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){
$player->getInventory()->sendContents($player);
}
$nbt = new CompoundTag("", [
new ListTag("Pos", [
new DoubleTag("", $player->x),
new DoubleTag("", $player->y + $player->getEyeHeight()),
new DoubleTag("", $player->z)
]),
new ListTag("Motion", [
new DoubleTag("", -sin($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI)),
new DoubleTag("", -sin($player->pitch / 180 * M_PI)),
new DoubleTag("", cos($player->yaw / 180 * M_PI) * cos($player->pitch / 180 * M_PI))
]),
new ListTag("Rotation", [
//yaw/pitch for arrows taken crosswise, not along the arrow shaft.
new FloatTag("", ($player->yaw > 180 ? 360 : 0) - $player->yaw), //arrow yaw must range from -180 to +180
new FloatTag("", -$player->pitch)
]),
new ShortTag("Fire", $player->isOnFire() ? 45 * 60 : 0)
]);
$diff = $player->getItemUseDuration();
$p = $diff / 20;
$force = min((($p ** 2) + $p * 2) / 3, 1) * 2;
$entity = Entity::createEntity("Arrow", $player->getLevel(), $nbt, $player, $force == 2);
if($entity instanceof Projectile){
$ev = new EntityShootBowEvent($player, $this, $entity, $force);
if($force < 0.1 or $diff < 5){
$ev->setCancelled();
}
$player->getServer()->getPluginManager()->callEvent($ev);
$entity = $ev->getProjectile(); //This might have been changed by plugins
if($ev->isCancelled()){
$entity->kill();
$player->getInventory()->sendContents($player);
}else{
$entity->setMotion($entity->getMotion()->multiply($ev->getForce()));
if($player->isSurvival()){
$player->getInventory()->removeItem(ItemFactory::get(Item::ARROW, 0, 1));
$this->setDamage($this->getDamage() + 1);
if($this->getDamage() >= $this->getMaxDurability()){
$player->getInventory()->setItemInHand(ItemFactory::get(Item::AIR, 0, 0));
}else{
$player->getInventory()->setItemInHand($this);
}
}
if($entity instanceof Projectile){
$player->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($entity));
if($projectileEv->isCancelled()){
$ev->getProjectile()->kill();
}else{
$ev->getProjectile()->spawnToAll();
$player->level->addSound(new LaunchSound($player), $player->getViewers());
}
}else{
$entity->spawnToAll();
}
}
}else{
$entity->spawnToAll();
}
return true;
}
}

View File

@ -25,8 +25,9 @@ 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
}

View File

@ -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{

View File

@ -23,8 +23,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
class BrewingStand extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::BREWING_STAND, $meta, $count, "Brewing Stand");
public function __construct(int $meta = 0){
$this->block = Block::get(Block::BREWING_STAND_BLOCK);
parent::__construct(self::BREWING_STAND, $meta, "Brewing Stand");
}
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Brick extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::BRICK, $meta, $count, "Brick");
}
}

View File

@ -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(){

View File

@ -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(){

View File

@ -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{

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 4;
}
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Clay extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::CLAY, $meta, $count, "Clay");
}
}

View File

@ -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");
}
}

View File

@ -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";
}

View File

@ -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");
}
}

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Diamond extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::DIAMOND, $meta, $count, "Diamond");
}
}

View File

@ -25,12 +25,15 @@ 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(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 7;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 8;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -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(){

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 6;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 6;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 8;
}
}

View File

@ -24,9 +24,10 @@ 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
}

View File

@ -24,9 +24,11 @@ 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
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Emerald extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::EMERALD, $meta, $count, "Emerald");
}
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Feather extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::FEATHER, $meta, $count, "Feather");
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class FermentedSpiderEye extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::FERMENTED_SPIDER_EYE, $meta, $count, "Fermented Spider Eye");
}
}

View File

@ -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{

View File

@ -24,7 +24,9 @@ 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
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Flint extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::FLINT, $meta, $count, "Flint");
}
}

View File

@ -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);
@ -52,4 +52,8 @@ class FlintSteel extends Tool{
return false;
}
public function getMaxDurability(){
return 65;
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class GlisteringMelon extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::GLISTERING_MELON, $meta, $count, "Glistering Melon");
}
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class GlowstoneDust extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::GLOWSTONE_DUST, $meta, $count, "Glowstone Dust");
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -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(){

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class GoldIngot extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::GOLD_INGOT, $meta, $count, "Gold Ingot");
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class GoldNugget extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::GOLD_NUGGET, $meta, $count, "Gold Nugget");
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 3;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 2;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Gunpowder extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::GUNPOWDER, $meta, $count, "Gunpowder");
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 6;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 6;
}
}

View File

@ -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(){

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -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(){

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class IronIngot extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::IRON_INGOT, $meta, $count, "Iron Ingot");
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -25,11 +25,15 @@ 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(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 7;
}
}

View File

@ -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;
}
public function isNull() : bool{
@ -709,9 +716,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;
}
/**
@ -740,6 +750,22 @@ class Item implements ItemIds, \JsonSerializable{
return 0;
}
/**
* Returns how many points of damage this item will deal to an entity when used as a weapon.
* @return int
*/
public function getAttackPoints() : int{
return 1;
}
/**
* Returns how many armor points can be gained by wearing this item.
* @return int
*/
public function getDefensePoints() : int{
return 0;
}
/**
* @param Entity|Block $object
*
@ -807,6 +833,16 @@ class Item implements ItemIds, \JsonSerializable{
return false;
}
/**
* Called when a player is using this item and releases it. Used to handle bow shoot actions.
*
* @param Player $player
* @return bool
*/
public function onReleaseUsing(Player $player) : bool{
return false;
}
/**
* Compares an Item to this Item and check if they match.
*

View File

@ -29,14 +29,19 @@ 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->block->setDamage($this->meta !== -1 ? $this->meta : 0);
$this->meta = $meta;
$this->block->setDamage($this->meta !== -1 ? $this->meta & 0xf : 0);
}
public function getBlock() : Block{

View File

@ -46,9 +46,9 @@ class ItemFactory{
self::registerItem(new Bow());
self::registerItem(new Arrow());
self::registerItem(new Coal());
self::registerItem(new Diamond());
self::registerItem(new IronIngot());
self::registerItem(new GoldIngot());
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 Feather());
self::registerItem(new 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 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 Flint());
self::registerItem(new Item(Item::FLINT, 0, "Flint"));
self::registerItem(new RawPorkchop());
self::registerItem(new CookedPorkchop());
self::registerItem(new Painting());
@ -110,35 +110,36 @@ class ItemFactory{
self::registerItem(new Bucket());
self::registerItem(new Minecart());
//TODO: SADDLE
self::registerItem(new IronDoor());
self::registerItem(new Redstone());
self::registerItem(new Snowball());
self::registerItem(new Boat());
self::registerItem(new Leather());
self::registerItem(new Item(Item::LEATHER, 0, "Leather"));
self::registerItem(new Brick());
self::registerItem(new 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 Paper());
self::registerItem(new Item(Item::PAPER, 0, "Paper"));
self::registerItem(new Book());
self::registerItem(new 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 GlowstoneDust());
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 Bone());
self::registerItem(new 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
self::registerItem(new Cookie());
//TODO: FILLED_MAP
self::registerItem(new Shears());
self::registerItem(new Melon());
self::registerItem(new PumpkinSeeds());
@ -147,45 +148,92 @@ class ItemFactory{
self::registerItem(new Steak());
self::registerItem(new RawChicken());
self::registerItem(new CookedChicken());
self::registerItem(new GoldNugget());
//TODO: ROTTEN_FLESH
//TODO: ENDER_PEARL
//TODO: BLAZE_ROD
//TODO: GHAST_TEAR
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 FermentedSpiderEye());
self::registerItem(new BlazePowder());
self::registerItem(new MagmaCream());
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());
self::registerItem(new GlisteringMelon());
//TODO: CAULDRON
//TODO: ENDER_EYE
self::registerItem(new Item(Item::GLISTERING_MELON, 0, "Glistering Melon"));
self::registerItem(new SpawnEgg());
//TODO: BOTTLE_O_ENCHANTING
//TODO: FIREBALL
self::registerItem(new Emerald());
self::registerItem(new Item(Item::EMERALD, 0, "Emerald"));
self::registerItem(new ItemFrame());
self::registerItem(new FlowerPot());
self::registerItem(new Carrot());
self::registerItem(new Potato());
self::registerItem(new BakedPotato());
//TODO: POISONOUS_POTATO
//TODO: EMPTYMAP
self::registerItem(new GoldenCarrot());
self::registerItem(new Skull());
self::registerItem(new NetherStar());
//TODO: CARROTONASTICK
self::registerItem(new Item(Item::NETHER_STAR, 0, "Nether Star"));
self::registerItem(new PumpkinPie());
self::registerItem(new NetherBrick());
self::registerItem(new NetherQuartz());
self::registerItem(new PrismarineShard());
//TODO: ENCHANTED_BOOK
//TODO: COMPARATOR
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, "Prismarine Shard"));
//TODO: HOPPER
//TODO: RABBIT
self::registerItem(new CookedRabbit());
//TODO: RABBIT_STEW
//TODO: RABBIT_FOOT
//TODO: RABBIT_HIDE
//TODO: HORSEARMORLEATHER
//TODO: HORSEARMORIRON
//TODO: GOLD_HORSE_ARMOR
//TODO: DIAMOND_HORSE_ARMOR
//TODO: LEAD
//TODO: NAMETAG
self::registerItem(new Item(Item::PRISMARINE_CRYSTALS, 0, "Prismarine Crystals"));
//TODO: MUTTONRAW
//TODO: COOKED_MUTTON
self::registerItem(new PrismarineCrystals());
//TODO: END_CRYSTAL
//TODO: SPRUCE_DOOR
//TODO: BIRCH_DOOR
//TODO: JUNGLE_DOOR
//TODO: ACACIA_DOOR
//TODO: DARK_OAK_DOOR
//TODO: CHORUS_FRUIT
//TODO: CHORUS_FRUIT_POPPED
//TODO: DRAGON_BREATH
//TODO: SPLASH_POTION
//TODO: LINGERING_POTION
//TODO: COMMAND_BLOCK_MINECART
//TODO: ELYTRA
//TODO: SHULKER_SHELL
//TODO: TOTEM
//TODO: IRON_NUGGET
self::registerItem(new Beetroot());
self::registerItem(new BeetrootSeeds());
self::registerItem(new BeetrootSoup());
//TODO: RAW_SALMON
//TODO: CLOWNFISH
//TODO: PUFFERFISH
//TODO: COOKED_SALMON
self::registerItem(new GoldenAppleEnchanted());
}
@ -224,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 & 0xf : 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;
}
/**

View File

@ -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");
}
}

View File

@ -175,7 +175,7 @@ interface ItemIds extends BlockIds{
const FIREWORKSCHARGE = 402, FIREWORKS_CHARGE = 402;
const ENCHANTED_BOOK = 403;
const COMPARATOR = 404;
const NETHERBRICK = 405;
const NETHERBRICK = 405, NETHER_BRICK = 405;
const NETHER_QUARTZ = 406, QUARTZ = 406;
const MINECART_WITH_TNT = 407, TNT_MINECART = 407;
const HOPPER_MINECART = 408, MINECART_WITH_HOPPER = 408;

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class Leather extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::LEATHER, $meta, $count, "Leather");
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -25,7 +25,11 @@ 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");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -1,30 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class MagmaCream extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::MAGMA_CREAM, $meta, $count, "Magma Cream");
}
}

View File

@ -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{

View File

@ -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");
}
}

View File

@ -24,9 +24,10 @@ 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
}

View File

@ -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(){

View File

@ -1,32 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class NetherBrick extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::NETHER_BRICK, $meta, $count, "Nether Brick");
}
}

View File

@ -1,31 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class NetherQuartz extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::NETHER_QUARTZ, $meta, $count, "Nether Quartz");
}
}

View File

@ -1,31 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\item;
class NetherStar extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(self::NETHER_STAR, $meta, $count, "Nether Star");
}
}

View File

@ -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");
}
}

Some files were not shown because too many files have changed in this diff Show More