diff --git a/src/pocketmine/item/Armor.php b/src/pocketmine/item/Armor.php index f625e7cea..b368837f5 100644 --- a/src/pocketmine/item/Armor.php +++ b/src/pocketmine/item/Armor.php @@ -27,5 +27,7 @@ use pocketmine\entity\Entity; abstract class Armor extends Item{ - public $maxStackSize = 1; + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Bed.php b/src/pocketmine/item/Bed.php index e4abebc1b..9ad66d2f2 100644 --- a/src/pocketmine/item/Bed.php +++ b/src/pocketmine/item/Bed.php @@ -27,6 +27,9 @@ class Bed extends Item{ public function __construct($meta = 0, $count = 1){ $this->block = Block::get(Item::BED_BLOCK); parent::__construct(self::BED, 0, $count, "Bed"); - $this->maxStackSize = 1; } + + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/BeetrootSoup.php b/src/pocketmine/item/BeetrootSoup.php index 323ec397e..217b76e09 100644 --- a/src/pocketmine/item/BeetrootSoup.php +++ b/src/pocketmine/item/BeetrootSoup.php @@ -25,7 +25,9 @@ namespace pocketmine\item; class BeetrootSoup extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::BEETROOT_SOUP, 0, $count, "Beetroot Soup"); - $this->maxStackSize = 1; } + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 04863381c..855bf713b 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -31,10 +31,16 @@ use pocketmine\Player; class Bucket extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::BUCKET, $meta, $count, "Bucket"); - $this->isActivable = true; - $this->maxStackSize = 1; } + public function getMaxStackSize(){ + return 1; + } + + public function canBeActivated(){ + return true; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $targetBlock = Block::get($this->meta); diff --git a/src/pocketmine/item/Cake.php b/src/pocketmine/item/Cake.php index dc0710d97..3001c137b 100644 --- a/src/pocketmine/item/Cake.php +++ b/src/pocketmine/item/Cake.php @@ -26,7 +26,10 @@ use pocketmine\block\Block; class Cake extends Item{ public function __construct($meta = 0, $count = 1){ $this->block = Block::get(Item::CAKE_BLOCK); - $this->maxStackSize = 1; parent::__construct(self::CAKE, 0, $count, "Cake"); } + + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index 731bb7174..94f9a18a7 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -30,9 +30,12 @@ use pocketmine\Player; class FlintSteel extends Tool{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel"); - $this->isActivable = true; } + public function canBeActivated(){ + return true; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getDamage() >= $this->getMaxDurability()){ $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0)); diff --git a/src/pocketmine/item/IronDoor.php b/src/pocketmine/item/IronDoor.php index 5cf28b3f8..32a3f21f1 100644 --- a/src/pocketmine/item/IronDoor.php +++ b/src/pocketmine/item/IronDoor.php @@ -27,6 +27,9 @@ class IronDoor extends Item{ public function __construct($meta = 0, $count = 1){ $this->block = Block::get(Item::IRON_DOOR_BLOCK); parent::__construct(self::IRON_DOOR, 0, $count, "Iron Door"); - $this->maxStackSize = 1; } + + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 4304cf30f..fee49f924 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -373,7 +373,7 @@ class Item{ const CARROT = 391; const CARROTS = 391; const POTATO = 392; - const POTATOES = 392; //@shoghicp Why the heck do we need plural redundant Item ID here???? + const POTATOES = 392; const BAKED_POTATO = 393; const BAKED_POTATOES = 393; @@ -396,10 +396,12 @@ class Item{ protected $id; protected $meta; public $count; - protected $maxStackSize = 64; protected $durability = 0; protected $name; - public $isActivable = false; + + public function canBeActivated(){ + return false; + } public static function init(){ if(self::$list === null){ @@ -425,6 +427,7 @@ class Item{ self::$list[self::SPAWN_EGG] = SpawnEgg::class; self::$list[self::DIAMOND] = Diamond::class; self::$list[self::STICK] = Stick::class; + self::$list[self::SNOWBALL] = Snowball::class; self::$list[self::BOWL] = Bowl::class; self::$list[self::FEATHER] = Feather::class; self::$list[self::BRICK] = Brick::class; @@ -514,16 +517,16 @@ class Item{ if(!isset($b[1])){ $meta = 0; }else{ - $meta = ((int) $b[1]) & 0xFFFF; + $meta = $b[1] & 0xFFFF; } if(defined(Item::class . "::" . strtoupper($b[0]))){ $item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta); if($item->getId() === self::AIR and strtoupper($b[0]) !== "AIR"){ - $item = self::get(((int) $b[0]) & 0xFFFF, $meta); + $item = self::get($b[0] & 0xFFFF, $meta); } }else{ - $item = self::get(((int) $b[0]) & 0xFFFF, $meta); + $item = self::get($b[0] & 0xFFFF, $meta); } return $item; @@ -539,9 +542,6 @@ class Item{ $this->block = Block::get($this->id, $this->meta); $this->name = $this->block->getName(); } - if($this->isTool() !== false){ - $this->maxStackSize = 1; - } } @@ -581,8 +581,8 @@ class Item{ $this->meta = $meta !== null ? $meta & 0xFFFF : null; } - final public function getMaxStackSize(){ - return $this->maxStackSize; + public function getMaxStackSize(){ + return 64; } final public function getFuelTime(){ diff --git a/src/pocketmine/item/ItemBlock.php b/src/pocketmine/item/ItemBlock.php index 7734961be..fcbc18ea5 100644 --- a/src/pocketmine/item/ItemBlock.php +++ b/src/pocketmine/item/ItemBlock.php @@ -28,7 +28,7 @@ use pocketmine\block\Block; */ class ItemBlock extends Item{ public function __construct(Block $block, $meta = 0, $count = 1){ - $this->block = clone $block; + $this->block = $block; parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName()); } diff --git a/src/pocketmine/item/MushroomStew.php b/src/pocketmine/item/MushroomStew.php index 61a9b610a..96813a44a 100644 --- a/src/pocketmine/item/MushroomStew.php +++ b/src/pocketmine/item/MushroomStew.php @@ -25,7 +25,9 @@ namespace pocketmine\item; class MushroomStew extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::MUSHROOM_STEW, 0, $count, "Mushroom Stew"); - $this->maxStackSize = 1; } + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Painting.php b/src/pocketmine/item/Painting.php index 5ab5ac95d..21325adb9 100644 --- a/src/pocketmine/item/Painting.php +++ b/src/pocketmine/item/Painting.php @@ -29,9 +29,12 @@ use pocketmine\Player; class Painting extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::PAINTING, 0, $count, "Painting"); - $this->isActivable = true; } + public function canBeActivated(){ + return true; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($target->isTransparent() === false and $face > 1 and $block->isSolid() === false){ $faces = [ diff --git a/src/pocketmine/item/Sign.php b/src/pocketmine/item/Sign.php index ed06c6a16..5c3cd393c 100644 --- a/src/pocketmine/item/Sign.php +++ b/src/pocketmine/item/Sign.php @@ -26,7 +26,10 @@ use pocketmine\block\Block; class Sign extends Item{ public function __construct($meta = 0, $count = 1){ $this->block = Block::get(Item::SIGN_POST); - $this->maxStackSize = 16; parent::__construct(self::SIGN, 0, $count, "Sign"); } + + public function getMaxStackSize(){ + return 16; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Snowball.php b/src/pocketmine/item/Snowball.php new file mode 100644 index 000000000..4c5ff7986 --- /dev/null +++ b/src/pocketmine/item/Snowball.php @@ -0,0 +1,34 @@ +meta = $meta; - $this->isActivable = true; + parent::__construct(self::SPAWN_EGG, $meta, $count, "Spawn Egg"); } + public function canBeActivated(){ + return true; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $entity = null; $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4); diff --git a/src/pocketmine/item/Tool.php b/src/pocketmine/item/Tool.php index c6c08131d..140cc2c38 100644 --- a/src/pocketmine/item/Tool.php +++ b/src/pocketmine/item/Tool.php @@ -34,9 +34,12 @@ abstract class Tool extends Item{ public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){ parent::__construct($id, $meta, $count, $name); - $this->maxStackSize = 1; } + public function getMaxStackSize(){ + return 1; + } + /** * TODO: Move this to each item * diff --git a/src/pocketmine/item/WoodenDoor.php b/src/pocketmine/item/WoodenDoor.php index 251ba68bc..678d8328f 100644 --- a/src/pocketmine/item/WoodenDoor.php +++ b/src/pocketmine/item/WoodenDoor.php @@ -27,6 +27,9 @@ class WoodenDoor extends Item{ public function __construct($meta = 0, $count = 1){ $this->block = Block::get(Item::WOODEN_DOOR_BLOCK); parent::__construct(self::WOODEN_DOOR, 0, $count, "Wooden Door"); - $this->maxStackSize = 1; } + + public function getMaxStackSize(){ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 45e56ad9f..dad6c164c 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1266,11 +1266,11 @@ class Level implements ChunkManager, Metadatable{ $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $target->onUpdate(self::BLOCK_UPDATE_TOUCH); - if($target->isActivable === true and $target->onActivate($item, $player) === true){ + if($target->canBeActivated() === true and $target->onActivate($item, $player) === true){ return true; } - if($item->isActivable and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ + if($item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)){ if($item->getCount() <= 0){ $item = Item::get(Item::AIR, 0, 0); @@ -1278,7 +1278,7 @@ class Level implements ChunkManager, Metadatable{ } } } - }elseif($target->isActivable === true and $target->onActivate($item, $player) === true){ + }elseif($target->canBeActivated() === true and $target->onActivate($item, $player) === true){ return true; }