mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Improved Item property handling
This commit is contained in:
parent
a98da3bab1
commit
7506f01302
@ -27,5 +27,7 @@ use pocketmine\entity\Entity;
|
|||||||
|
|
||||||
abstract class Armor extends Item{
|
abstract class Armor extends Item{
|
||||||
|
|
||||||
public $maxStackSize = 1;
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,6 +27,9 @@ class Bed extends Item{
|
|||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
$this->block = Block::get(Item::BED_BLOCK);
|
$this->block = Block::get(Item::BED_BLOCK);
|
||||||
parent::__construct(self::BED, 0, $count, "Bed");
|
parent::__construct(self::BED, 0, $count, "Bed");
|
||||||
$this->maxStackSize = 1;
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,7 +25,9 @@ namespace pocketmine\item;
|
|||||||
class BeetrootSoup extends Item{
|
class BeetrootSoup extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::BEETROOT_SOUP, 0, $count, "Beetroot Soup");
|
parent::__construct(self::BEETROOT_SOUP, 0, $count, "Beetroot Soup");
|
||||||
$this->maxStackSize = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
@ -31,8 +31,14 @@ use pocketmine\Player;
|
|||||||
class Bucket extends Item{
|
class Bucket extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::BUCKET, $meta, $count, "Bucket");
|
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){
|
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
@ -26,7 +26,10 @@ use pocketmine\block\Block;
|
|||||||
class Cake extends Item{
|
class Cake extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
$this->block = Block::get(Item::CAKE_BLOCK);
|
$this->block = Block::get(Item::CAKE_BLOCK);
|
||||||
$this->maxStackSize = 1;
|
|
||||||
parent::__construct(self::CAKE, 0, $count, "Cake");
|
parent::__construct(self::CAKE, 0, $count, "Cake");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
@ -30,7 +30,10 @@ use pocketmine\Player;
|
|||||||
class FlintSteel extends Tool{
|
class FlintSteel extends Tool{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::FLINT_STEEL, $meta, $count, "Flint and Steel");
|
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){
|
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
@ -27,6 +27,9 @@ class IronDoor extends Item{
|
|||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
$this->block = Block::get(Item::IRON_DOOR_BLOCK);
|
$this->block = Block::get(Item::IRON_DOOR_BLOCK);
|
||||||
parent::__construct(self::IRON_DOOR, 0, $count, "Iron Door");
|
parent::__construct(self::IRON_DOOR, 0, $count, "Iron Door");
|
||||||
$this->maxStackSize = 1;
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -373,7 +373,7 @@ class Item{
|
|||||||
const CARROT = 391;
|
const CARROT = 391;
|
||||||
const CARROTS = 391;
|
const CARROTS = 391;
|
||||||
const POTATO = 392;
|
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_POTATO = 393;
|
||||||
const BAKED_POTATOES = 393;
|
const BAKED_POTATOES = 393;
|
||||||
|
|
||||||
@ -396,10 +396,12 @@ class Item{
|
|||||||
protected $id;
|
protected $id;
|
||||||
protected $meta;
|
protected $meta;
|
||||||
public $count;
|
public $count;
|
||||||
protected $maxStackSize = 64;
|
|
||||||
protected $durability = 0;
|
protected $durability = 0;
|
||||||
protected $name;
|
protected $name;
|
||||||
public $isActivable = false;
|
|
||||||
|
public function canBeActivated(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function init(){
|
public static function init(){
|
||||||
if(self::$list === null){
|
if(self::$list === null){
|
||||||
@ -425,6 +427,7 @@ class Item{
|
|||||||
self::$list[self::SPAWN_EGG] = SpawnEgg::class;
|
self::$list[self::SPAWN_EGG] = SpawnEgg::class;
|
||||||
self::$list[self::DIAMOND] = Diamond::class;
|
self::$list[self::DIAMOND] = Diamond::class;
|
||||||
self::$list[self::STICK] = Stick::class;
|
self::$list[self::STICK] = Stick::class;
|
||||||
|
self::$list[self::SNOWBALL] = Snowball::class;
|
||||||
self::$list[self::BOWL] = Bowl::class;
|
self::$list[self::BOWL] = Bowl::class;
|
||||||
self::$list[self::FEATHER] = Feather::class;
|
self::$list[self::FEATHER] = Feather::class;
|
||||||
self::$list[self::BRICK] = Brick::class;
|
self::$list[self::BRICK] = Brick::class;
|
||||||
@ -514,16 +517,16 @@ class Item{
|
|||||||
if(!isset($b[1])){
|
if(!isset($b[1])){
|
||||||
$meta = 0;
|
$meta = 0;
|
||||||
}else{
|
}else{
|
||||||
$meta = ((int) $b[1]) & 0xFFFF;
|
$meta = $b[1] & 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(defined(Item::class . "::" . strtoupper($b[0]))){
|
if(defined(Item::class . "::" . strtoupper($b[0]))){
|
||||||
$item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta);
|
$item = self::get(constant(Item::class . "::" . strtoupper($b[0])), $meta);
|
||||||
if($item->getId() === self::AIR and strtoupper($b[0]) !== "AIR"){
|
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{
|
}else{
|
||||||
$item = self::get(((int) $b[0]) & 0xFFFF, $meta);
|
$item = self::get($b[0] & 0xFFFF, $meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
@ -539,9 +542,6 @@ class Item{
|
|||||||
$this->block = Block::get($this->id, $this->meta);
|
$this->block = Block::get($this->id, $this->meta);
|
||||||
$this->name = $this->block->getName();
|
$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;
|
$this->meta = $meta !== null ? $meta & 0xFFFF : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getMaxStackSize(){
|
public function getMaxStackSize(){
|
||||||
return $this->maxStackSize;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function getFuelTime(){
|
final public function getFuelTime(){
|
||||||
|
@ -28,7 +28,7 @@ use pocketmine\block\Block;
|
|||||||
*/
|
*/
|
||||||
class ItemBlock extends Item{
|
class ItemBlock extends Item{
|
||||||
public function __construct(Block $block, $meta = 0, $count = 1){
|
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());
|
parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,9 @@ namespace pocketmine\item;
|
|||||||
class MushroomStew extends Item{
|
class MushroomStew extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::MUSHROOM_STEW, 0, $count, "Mushroom Stew");
|
parent::__construct(self::MUSHROOM_STEW, 0, $count, "Mushroom Stew");
|
||||||
$this->maxStackSize = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
@ -29,7 +29,10 @@ use pocketmine\Player;
|
|||||||
class Painting extends Item{
|
class Painting extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::PAINTING, 0, $count, "Painting");
|
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){
|
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
@ -26,7 +26,10 @@ use pocketmine\block\Block;
|
|||||||
class Sign extends Item{
|
class Sign extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
$this->block = Block::get(Item::SIGN_POST);
|
$this->block = Block::get(Item::SIGN_POST);
|
||||||
$this->maxStackSize = 16;
|
|
||||||
parent::__construct(self::SIGN, 0, $count, "Sign");
|
parent::__construct(self::SIGN, 0, $count, "Sign");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
}
|
}
|
34
src/pocketmine/item/Snowball.php
Normal file
34
src/pocketmine/item/Snowball.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?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/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\item;
|
||||||
|
|
||||||
|
|
||||||
|
class Snowball extends Item{
|
||||||
|
public function __construct($meta = 0, $count = 1){
|
||||||
|
parent::__construct(self::SNOWBALL, 0, $count, "Snowball");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,9 +33,11 @@ use pocketmine\Player;
|
|||||||
|
|
||||||
class SpawnEgg extends Item{
|
class SpawnEgg extends Item{
|
||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
parent::__construct(self::SPAWN_EGG, 0, $count, "Spawn Egg");
|
parent::__construct(self::SPAWN_EGG, $meta, $count, "Spawn Egg");
|
||||||
$this->meta = $meta;
|
}
|
||||||
$this->isActivable = true;
|
|
||||||
|
public function canBeActivated(){
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
@ -34,7 +34,10 @@ abstract class Tool extends Item{
|
|||||||
|
|
||||||
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
|
public function __construct($id, $meta = 0, $count = 1, $name = "Unknown"){
|
||||||
parent::__construct($id, $meta, $count, $name);
|
parent::__construct($id, $meta, $count, $name);
|
||||||
$this->maxStackSize = 1;
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,9 @@ class WoodenDoor extends Item{
|
|||||||
public function __construct($meta = 0, $count = 1){
|
public function __construct($meta = 0, $count = 1){
|
||||||
$this->block = Block::get(Item::WOODEN_DOOR_BLOCK);
|
$this->block = Block::get(Item::WOODEN_DOOR_BLOCK);
|
||||||
parent::__construct(self::WOODEN_DOOR, 0, $count, "Wooden Door");
|
parent::__construct(self::WOODEN_DOOR, 0, $count, "Wooden Door");
|
||||||
$this->maxStackSize = 1;
|
}
|
||||||
|
|
||||||
|
public function getMaxStackSize(){
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1266,11 +1266,11 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->server->getPluginManager()->callEvent($ev);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$target->onUpdate(self::BLOCK_UPDATE_TOUCH);
|
$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;
|
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){
|
if($item->getCount() <= 0){
|
||||||
$item = Item::get(Item::AIR, 0, 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user