From 9a5ffbe56c85e19ed6b7e8e7c0ccfe1fb649dcb0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 2 Apr 2014 04:26:53 +0200 Subject: [PATCH] Added Tool for Items, new items --- src/pocketmine/item/Bow.php | 30 ++++ src/pocketmine/item/DiamondAxe.php | 30 ++++ src/pocketmine/item/DiamondHoe.php | 30 ++++ src/pocketmine/item/DiamondPickaxe.php | 30 ++++ src/pocketmine/item/DiamondShovel.php | 30 ++++ src/pocketmine/item/DiamondSword.php | 30 ++++ src/pocketmine/item/FlintSteel.php | 3 +- src/pocketmine/item/GoldAxe.php | 30 ++++ src/pocketmine/item/GoldHoe.php | 30 ++++ src/pocketmine/item/GoldPickaxe.php | 30 ++++ src/pocketmine/item/GoldShovel.php | 30 ++++ src/pocketmine/item/GoldSword.php | 30 ++++ src/pocketmine/item/IronAxe.php | 2 +- src/pocketmine/item/IronHoe.php | 2 +- src/pocketmine/item/IronPickaxe.php | 2 +- src/pocketmine/item/IronShovel.php | 2 +- src/pocketmine/item/Item.php | 198 ++++++++----------------- src/pocketmine/item/Shears.php | 29 ++++ src/pocketmine/item/StoneAxe.php | 30 ++++ src/pocketmine/item/StoneHoe.php | 30 ++++ src/pocketmine/item/StonePickaxe.php | 30 ++++ src/pocketmine/item/StoneShovel.php | 30 ++++ src/pocketmine/item/StoneSword.php | 30 ++++ src/pocketmine/item/Tool.php | 177 ++++++++++++++++++++++ src/pocketmine/item/WoodenAxe.php | 2 +- src/pocketmine/item/WoodenHoe.php | 30 ++++ src/pocketmine/item/WoodenPickaxe.php | 2 +- src/pocketmine/item/WoodenShovel.php | 2 +- src/pocketmine/item/WoodenSword.php | 2 +- 29 files changed, 788 insertions(+), 145 deletions(-) create mode 100644 src/pocketmine/item/Bow.php create mode 100644 src/pocketmine/item/DiamondAxe.php create mode 100644 src/pocketmine/item/DiamondHoe.php create mode 100644 src/pocketmine/item/DiamondPickaxe.php create mode 100644 src/pocketmine/item/DiamondShovel.php create mode 100644 src/pocketmine/item/DiamondSword.php create mode 100644 src/pocketmine/item/GoldAxe.php create mode 100644 src/pocketmine/item/GoldHoe.php create mode 100644 src/pocketmine/item/GoldPickaxe.php create mode 100644 src/pocketmine/item/GoldShovel.php create mode 100644 src/pocketmine/item/GoldSword.php create mode 100644 src/pocketmine/item/Shears.php create mode 100644 src/pocketmine/item/StoneAxe.php create mode 100644 src/pocketmine/item/StoneHoe.php create mode 100644 src/pocketmine/item/StonePickaxe.php create mode 100644 src/pocketmine/item/StoneShovel.php create mode 100644 src/pocketmine/item/StoneSword.php create mode 100644 src/pocketmine/item/Tool.php create mode 100644 src/pocketmine/item/WoodenHoe.php diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php new file mode 100644 index 000000000..60cfbf8de --- /dev/null +++ b/src/pocketmine/item/Bow.php @@ -0,0 +1,30 @@ +isActivable = true; - $this->maxStackSize = 1; } public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ diff --git a/src/pocketmine/item/GoldAxe.php b/src/pocketmine/item/GoldAxe.php new file mode 100644 index 000000000..35998e2df --- /dev/null +++ b/src/pocketmine/item/GoldAxe.php @@ -0,0 +1,30 @@ + new IronPickaxe(), self::IRON_AXE => new IronAxe(), self::IRON_HOE => new IronHoe(), + self::DIAMOND_SWORD => new DiamondSword(), + self::DIAMOND_SHOVEL => new DiamondShovel(), + self::DIAMOND_PICKAXE => new DiamondPickaxe(), + self::DIAMOND_AXE => new DiamondAxe(), + self::DIAMOND_HOE => new DiamondHoe(), + self::GOLD_SWORD => new GoldSword(), + self::GOLD_SHOVEL => new GoldShovel(), + self::GOLD_PICKAXE => new GoldPickaxe(), + self::GOLD_AXE => new GoldAxe(), + self::GOLD_HOE => new GoldHoe(), + self::STONE_SWORD => new StoneSword(), + self::STONE_SHOVEL => new StoneShovel(), + self::STONE_PICKAXE => new StonePickaxe(), + self::STONE_AXE => new StoneAxe(), + self::STONE_HOE => new StoneHoe(), self::WOODEN_SWORD => new WoodenSword(), self::WOODEN_SHOVEL => new WoodenShovel(), self::WOODEN_PICKAXE => new WoodenPickaxe(), self::WOODEN_AXE => new WoodenAxe(), + self::WOODEN_HOE => new WoodenHoe(), self::FLINT_STEEL => new FlintSteel(), + self::SHEARS => new Shears(), + self::BOW => new Bow(), ); foreach(Block::$list as $id => $class){ self::$list[$id] = new ItemBlock($class); @@ -538,142 +557,51 @@ class Item{ } - public function useOn($object, $force = false){ - if($this->isTool() or $force === true){ - if(($object instanceof Entity) and !$this->isSword()){ - $this->meta += 2; - }else{ - $this->meta++; - } - - return true; - }elseif($this->isHoe()){ - if(($object instanceof Block) and ($object->getID() === self::GRASS or $object->getID() === self::DIRT)){ - $this->meta++; - } - } - + /** + * @param Entity|Block $object + * + * @return bool + */ + public function useOn($object){ return false; } - final public function isTool(){ - return ($this->id === self::FLINT_STEEL or $this->id === self::SHEARS or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false); + /** + * @return bool + */ + public function isTool(){ + return false; } - final public function getMaxDurability(){ - if(!$this->isTool() and $this->isHoe() === false and $this->id !== self::BOW){ - return false; - } - - $levels = array( - 2 => 33, - 1 => 60, - 3 => 132, - 4 => 251, - 5 => 1562, - self::FLINT_STEEL => 65, - self::SHEARS => 239, - self::BOW => 385, - ); - - if(($type = $this->isPickaxe()) === false){ - if(($type = $this->isAxe()) === false){ - if(($type = $this->isSword()) === false){ - if(($type = $this->isShovel()) === false){ - if(($type = $this->isHoe()) === false){ - $type = $this->id; - } - } - } - } - } - - return $levels[$type]; + /** + * @return int|bool + */ + public function getMaxDurability(){ + return false; } - final public function isPickaxe(){ //Returns false or level of the pickaxe - switch($this->id){ - case self::IRON_PICKAXE: - return 4; - case self::WOODEN_PICKAXE: - return 1; - case self::STONE_PICKAXE: - return 3; - case self::DIAMOND_PICKAXE: - return 5; - case self::GOLD_PICKAXE: - return 2; - default: - return false; - } + public function isPickaxe(){ + return false; } - final public function isAxe(){ - switch($this->id){ - case self::IRON_AXE: - return 4; - case self::WOODEN_AXE: - return 1; - case self::STONE_AXE: - return 3; - case self::DIAMOND_AXE: - return 5; - case self::GOLD_AXE: - return 2; - default: - return false; - } + public function isAxe(){ + return false; } - final public function isSword(){ - switch($this->id){ - case self::IRON_SWORD: - return 4; - case self::WOODEN_SWORD: - return 1; - case self::STONE_SWORD: - return 3; - case self::DIAMOND_SWORD: - return 5; - case self::GOLD_SWORD: - return 2; - default: - return false; - } + public function isSword(){ + return false; } - final public function isShovel(){ - switch($this->id){ - case self::IRON_SHOVEL: - return 4; - case self::WOODEN_SHOVEL: - return 1; - case self::STONE_SHOVEL: - return 3; - case self::DIAMOND_SHOVEL: - return 5; - case self::GOLD_SHOVEL: - return 2; - default: - return false; - } + public function isShovel(){ + return false; } public function isHoe(){ - switch($this->id){ - case self::IRON_HOE: - case self::WOODEN_HOE: - case self::STONE_HOE: - case self::DIAMOND_HOE: - case self::GOLD_HOE: - return true; - default: - return false; - } + return false; } public function isShears(){ - return ($this->id === self::SHEARS); + return false; } final public function __toString(){ diff --git a/src/pocketmine/item/Shears.php b/src/pocketmine/item/Shears.php new file mode 100644 index 000000000..963086ba0 --- /dev/null +++ b/src/pocketmine/item/Shears.php @@ -0,0 +1,29 @@ +maxStackSize = 1; + } + + /** + * TODO: Move this to each item + * + * @param Entity|Block $object + * + * @return bool + */ + public function useOn($object){ + if($this->isHoe()){ + if(($object instanceof Block) and ($object->getID() === self::GRASS or $object->getID() === self::DIRT)){ + $this->meta++; + } + }elseif(($object instanceof Entity) and !$this->isSword()){ + $this->meta += 2; + }else{ + $this->meta++; + } + + return true; + } + + /** + * TODO: Move this to each item + * + * @return int|bool + */ + public function getMaxDurability(){ + + $levels = array( + 2 => 33, + 1 => 60, + 3 => 132, + 4 => 251, + 5 => 1562, + self::FLINT_STEEL => 65, + self::SHEARS => 239, + self::BOW => 385, + ); + + if(($type = $this->isPickaxe()) === false){ + if(($type = $this->isAxe()) === false){ + if(($type = $this->isSword()) === false){ + if(($type = $this->isShovel()) === false){ + if(($type = $this->isHoe()) === false){ + $type = $this->id; + } + } + } + } + } + + return $levels[$type]; + } + + public function isPickaxe(){ + switch($this->id){ + case self::IRON_PICKAXE: + return 4; + case self::WOODEN_PICKAXE: + return 1; + case self::STONE_PICKAXE: + return 3; + case self::DIAMOND_PICKAXE: + return 5; + case self::GOLD_PICKAXE: + return 2; + default: + return false; + } + } + + final public function isAxe(){ + switch($this->id){ + case self::IRON_AXE: + return 4; + case self::WOODEN_AXE: + return 1; + case self::STONE_AXE: + return 3; + case self::DIAMOND_AXE: + return 5; + case self::GOLD_AXE: + return 2; + default: + return false; + } + } + + final public function isSword(){ + switch($this->id){ + case self::IRON_SWORD: + return 4; + case self::WOODEN_SWORD: + return 1; + case self::STONE_SWORD: + return 3; + case self::DIAMOND_SWORD: + return 5; + case self::GOLD_SWORD: + return 2; + default: + return false; + } + } + + final public function isShovel(){ + switch($this->id){ + case self::IRON_SHOVEL: + return 4; + case self::WOODEN_SHOVEL: + return 1; + case self::STONE_SHOVEL: + return 3; + case self::DIAMOND_SHOVEL: + return 5; + case self::GOLD_SHOVEL: + return 2; + default: + return false; + } + } + + public function isHoe(){ + switch($this->id){ + case self::IRON_HOE: + case self::WOODEN_HOE: + case self::STONE_HOE: + case self::DIAMOND_HOE: + case self::GOLD_HOE: + return true; + default: + return false; + } + } + + public function isShears(){ + return ($this->id === self::SHEARS); + } + + public function isTool(){ + return false; + return ($this->id === self::FLINT_STEEL or $this->id === self::SHEARS or $this->id === self::BOW or $this->isPickaxe() !== false or $this->isAxe() !== false or $this->isShovel() !== false or $this->isSword() !== false); + } +} \ No newline at end of file diff --git a/src/pocketmine/item/WoodenAxe.php b/src/pocketmine/item/WoodenAxe.php index 59b7d3d7c..dabcecd83 100644 --- a/src/pocketmine/item/WoodenAxe.php +++ b/src/pocketmine/item/WoodenAxe.php @@ -22,7 +22,7 @@ namespace pocketmine\item; -class WoodenAxe extends Item{ +class WoodenAxe extends Tool{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::WOODEN_AXE, 0, $count, "Wooden Axe"); } diff --git a/src/pocketmine/item/WoodenHoe.php b/src/pocketmine/item/WoodenHoe.php new file mode 100644 index 000000000..d1540f0dd --- /dev/null +++ b/src/pocketmine/item/WoodenHoe.php @@ -0,0 +1,30 @@ +