diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 0c62c12db..e06be33f7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2232,35 +2232,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ break; } - $item = $this->inventory->getItemInHand(); - $damageTable = [ - Item::WOODEN_SWORD => 4, - Item::GOLDEN_SWORD => 4, - Item::STONE_SWORD => 5, - Item::IRON_SWORD => 6, - Item::DIAMOND_SWORD => 7, - - Item::WOODEN_AXE => 3, - Item::GOLDEN_AXE => 3, - Item::STONE_AXE => 3, - Item::IRON_AXE => 5, - Item::DIAMOND_AXE => 6, - - Item::WOODEN_PICKAXE => 2, - Item::GOLDEN_PICKAXE => 2, - Item::STONE_PICKAXE => 3, - Item::IRON_PICKAXE => 4, - Item::DIAMOND_PICKAXE => 5, - - Item::WOODEN_SHOVEL => 1, - Item::GOLDEN_SHOVEL => 1, - Item::STONE_SHOVEL => 2, - Item::IRON_SHOVEL => 3, - Item::DIAMOND_SHOVEL => 4, - ]; + $heldItem = $this->inventory->getItemInHand(); $damage = [ - EntityDamageEvent::MODIFIER_BASE => $damageTable[$item->getId()] ?? 1, + EntityDamageEvent::MODIFIER_BASE => $heldItem->getAttackPoints(), ]; if(!$this->canInteract($target, 8)){ @@ -2272,33 +2247,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $cancelled = true; } - $armorValues = [ - Item::LEATHER_CAP => 1, - Item::LEATHER_TUNIC => 3, - Item::LEATHER_PANTS => 2, - Item::LEATHER_BOOTS => 1, - Item::CHAINMAIL_HELMET => 1, - Item::CHAINMAIL_CHESTPLATE => 5, - Item::CHAINMAIL_LEGGINGS => 4, - Item::CHAINMAIL_BOOTS => 1, - Item::GOLDEN_HELMET => 1, - Item::GOLDEN_CHESTPLATE => 5, - Item::GOLDEN_LEGGINGS => 3, - Item::GOLDEN_BOOTS => 1, - Item::IRON_HELMET => 2, - Item::IRON_CHESTPLATE => 6, - Item::IRON_LEGGINGS => 5, - Item::IRON_BOOTS => 2, - Item::DIAMOND_HELMET => 3, - Item::DIAMOND_CHESTPLATE => 8, - Item::DIAMOND_LEGGINGS => 6, - Item::DIAMOND_BOOTS => 3, - ]; $points = 0; - foreach($target->getInventory()->getArmorContents() as $index => $i){ - if(isset($armorValues[$i->getId()])){ - $points += $armorValues[$i->getId()]; - } + foreach($target->getInventory()->getArmorContents() as $armorItem){ + $points += $armorItem->getDefensePoints(); } $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); @@ -2312,18 +2263,18 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $target->attack($ev); if($ev->isCancelled()){ - if($item->isTool() and $this->isSurvival()){ + if($heldItem->isTool() and $this->isSurvival()){ $this->inventory->sendContents($this); } break; } if($this->isSurvival()){ - if($item->isTool()){ - if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ + if($heldItem->isTool()){ + if($heldItem->useOn($target) and $heldItem->getDamage() >= $heldItem->getMaxDurability()){ $this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1)); }else{ - $this->inventory->setItemInHand($item); + $this->inventory->setItemInHand($heldItem); } } diff --git a/src/pocketmine/item/ChainBoots.php b/src/pocketmine/item/ChainBoots.php index 8caf1be6d..d75db7e1c 100644 --- a/src/pocketmine/item/ChainBoots.php +++ b/src/pocketmine/item/ChainBoots.php @@ -28,4 +28,8 @@ class ChainBoots extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::CHAIN_BOOTS, $meta, "Chainmail Boots"); } + + public function getDefensePoints() : int{ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainChestplate.php b/src/pocketmine/item/ChainChestplate.php index 2a78b3d89..edc866f98 100644 --- a/src/pocketmine/item/ChainChestplate.php +++ b/src/pocketmine/item/ChainChestplate.php @@ -28,4 +28,8 @@ class ChainChestplate extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::CHAIN_CHESTPLATE, $meta, "Chain Chestplate"); } + + public function getDefensePoints() : int{ + return 5; + } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainHelmet.php b/src/pocketmine/item/ChainHelmet.php index e81aca216..9a217fb0d 100644 --- a/src/pocketmine/item/ChainHelmet.php +++ b/src/pocketmine/item/ChainHelmet.php @@ -28,4 +28,8 @@ class ChainHelmet extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::CHAIN_HELMET, $meta, "Chainmail Helmet"); } + + public function getDefensePoints() : int{ + return 2; + } } \ No newline at end of file diff --git a/src/pocketmine/item/ChainLeggings.php b/src/pocketmine/item/ChainLeggings.php index 32215ef55..c7245e054 100644 --- a/src/pocketmine/item/ChainLeggings.php +++ b/src/pocketmine/item/ChainLeggings.php @@ -28,4 +28,8 @@ class ChainLeggings extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::CHAIN_LEGGINGS, $meta, "Chain Leggings"); } + + public function getDefensePoints() : int{ + return 4; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondAxe.php b/src/pocketmine/item/DiamondAxe.php index 1a8d8a5fb..7904cd470 100644 --- a/src/pocketmine/item/DiamondAxe.php +++ b/src/pocketmine/item/DiamondAxe.php @@ -33,4 +33,7 @@ class DiamondAxe extends Tool{ return Tool::TIER_DIAMOND; } + public function getAttackPoints() : int{ + return 7; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondBoots.php b/src/pocketmine/item/DiamondBoots.php index 89d233435..eef1e3056 100644 --- a/src/pocketmine/item/DiamondBoots.php +++ b/src/pocketmine/item/DiamondBoots.php @@ -28,4 +28,8 @@ class DiamondBoots extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::DIAMOND_BOOTS, $meta, "Diamond Boots"); } + + public function getDefensePoints() : int{ + return 3; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondChestplate.php b/src/pocketmine/item/DiamondChestplate.php index dd77d3b92..f7824e37b 100644 --- a/src/pocketmine/item/DiamondChestplate.php +++ b/src/pocketmine/item/DiamondChestplate.php @@ -28,4 +28,8 @@ class DiamondChestplate extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::DIAMOND_CHESTPLATE, $meta, "Diamond Chestplate"); } + + public function getDefensePoints() : int{ + return 8; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondHelmet.php b/src/pocketmine/item/DiamondHelmet.php index 513bf437e..6ebe38612 100644 --- a/src/pocketmine/item/DiamondHelmet.php +++ b/src/pocketmine/item/DiamondHelmet.php @@ -28,4 +28,8 @@ class DiamondHelmet extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::DIAMOND_HELMET, $meta, "Diamond Helmet"); } + + public function getDefensePoints() : int{ + return 3; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondLeggings.php b/src/pocketmine/item/DiamondLeggings.php index ccadf2327..1beb2a8b0 100644 --- a/src/pocketmine/item/DiamondLeggings.php +++ b/src/pocketmine/item/DiamondLeggings.php @@ -28,4 +28,8 @@ class DiamondLeggings extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::DIAMOND_LEGGINGS, $meta, "Diamond Leggings"); } + + public function getDefensePoints() : int{ + return 6; + } } \ No newline at end of file diff --git a/src/pocketmine/item/DiamondPickaxe.php b/src/pocketmine/item/DiamondPickaxe.php index 4a00821bb..915409493 100644 --- a/src/pocketmine/item/DiamondPickaxe.php +++ b/src/pocketmine/item/DiamondPickaxe.php @@ -32,4 +32,8 @@ class DiamondPickaxe extends Tool{ public function isPickaxe(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 6; + } } diff --git a/src/pocketmine/item/DiamondShovel.php b/src/pocketmine/item/DiamondShovel.php index d13187066..64c0ef459 100644 --- a/src/pocketmine/item/DiamondShovel.php +++ b/src/pocketmine/item/DiamondShovel.php @@ -32,4 +32,8 @@ class DiamondShovel extends Tool{ public function isShovel(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 5; + } } diff --git a/src/pocketmine/item/DiamondSword.php b/src/pocketmine/item/DiamondSword.php index 5b192a9ee..0205ca4b3 100644 --- a/src/pocketmine/item/DiamondSword.php +++ b/src/pocketmine/item/DiamondSword.php @@ -32,4 +32,8 @@ class DiamondSword extends Tool{ public function isSword(){ return Tool::TIER_DIAMOND; } + + public function getAttackPoints() : int{ + return 8; + } } diff --git a/src/pocketmine/item/GoldAxe.php b/src/pocketmine/item/GoldAxe.php index 208254e1c..ed363f735 100644 --- a/src/pocketmine/item/GoldAxe.php +++ b/src/pocketmine/item/GoldAxe.php @@ -32,4 +32,8 @@ class GoldAxe extends Tool{ public function isAxe(){ return Tool::TIER_GOLD; } + + public function getAttackPoints() : int{ + return 4; + } } \ No newline at end of file diff --git a/src/pocketmine/item/GoldBoots.php b/src/pocketmine/item/GoldBoots.php index eab079f2d..886bc6559 100644 --- a/src/pocketmine/item/GoldBoots.php +++ b/src/pocketmine/item/GoldBoots.php @@ -28,4 +28,8 @@ class GoldBoots extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::GOLD_BOOTS, $meta, "Gold Boots"); } + + public function getDefensePoints() : int{ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/GoldChestplate.php b/src/pocketmine/item/GoldChestplate.php index e0dd71839..a9ddf2ca9 100644 --- a/src/pocketmine/item/GoldChestplate.php +++ b/src/pocketmine/item/GoldChestplate.php @@ -28,4 +28,8 @@ class GoldChestplate extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::GOLD_CHESTPLATE, $meta, "Gold Chestplate"); } + + public function getDefensePoints() : int{ + return 5; + } } \ No newline at end of file diff --git a/src/pocketmine/item/GoldHelmet.php b/src/pocketmine/item/GoldHelmet.php index e8e6e3905..059dc0c50 100644 --- a/src/pocketmine/item/GoldHelmet.php +++ b/src/pocketmine/item/GoldHelmet.php @@ -28,4 +28,8 @@ class GoldHelmet extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::GOLD_HELMET, $meta, "Gold Helmet"); } + + public function getDefensePoints() : int{ + return 2; + } } \ No newline at end of file diff --git a/src/pocketmine/item/GoldLeggings.php b/src/pocketmine/item/GoldLeggings.php index cd61231fd..5d7ef871a 100644 --- a/src/pocketmine/item/GoldLeggings.php +++ b/src/pocketmine/item/GoldLeggings.php @@ -28,4 +28,8 @@ class GoldLeggings extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::GOLD_LEGGINGS, $meta, "Gold Leggings"); } + + public function getDefensePoints() : int{ + return 3; + } } \ No newline at end of file diff --git a/src/pocketmine/item/GoldPickaxe.php b/src/pocketmine/item/GoldPickaxe.php index 042ac2bb5..56bb1f8f9 100644 --- a/src/pocketmine/item/GoldPickaxe.php +++ b/src/pocketmine/item/GoldPickaxe.php @@ -32,4 +32,8 @@ class GoldPickaxe extends Tool{ public function isPickaxe(){ return Tool::TIER_GOLD; } + + public function getAttackPoints() : int{ + return 3; + } } diff --git a/src/pocketmine/item/GoldShovel.php b/src/pocketmine/item/GoldShovel.php index 041b0cc90..5a2341516 100644 --- a/src/pocketmine/item/GoldShovel.php +++ b/src/pocketmine/item/GoldShovel.php @@ -32,4 +32,8 @@ class GoldShovel extends Tool{ public function isShovel(){ return Tool::TIER_GOLD; } + + public function getAttackPoints() : int{ + return 2; + } } diff --git a/src/pocketmine/item/GoldSword.php b/src/pocketmine/item/GoldSword.php index 289f05888..f7668f6a5 100644 --- a/src/pocketmine/item/GoldSword.php +++ b/src/pocketmine/item/GoldSword.php @@ -32,4 +32,8 @@ class GoldSword extends Tool{ public function isSword(){ return Tool::TIER_GOLD; } + + public function getAttackPoints() : int{ + return 5; + } } diff --git a/src/pocketmine/item/IronAxe.php b/src/pocketmine/item/IronAxe.php index 9fc681ccd..74ff6aadf 100644 --- a/src/pocketmine/item/IronAxe.php +++ b/src/pocketmine/item/IronAxe.php @@ -32,4 +32,8 @@ class IronAxe extends Tool{ public function isAxe(){ return Tool::TIER_IRON; } + + public function getAttackPoints() : int{ + return 6; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronBoots.php b/src/pocketmine/item/IronBoots.php index 8fbc7af84..c87160301 100644 --- a/src/pocketmine/item/IronBoots.php +++ b/src/pocketmine/item/IronBoots.php @@ -28,4 +28,8 @@ class IronBoots extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::IRON_BOOTS, $meta, "Iron Boots"); } + + public function getDefensePoints() : int{ + return 2; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronChestplate.php b/src/pocketmine/item/IronChestplate.php index 7b69204b9..7fbbe2e94 100644 --- a/src/pocketmine/item/IronChestplate.php +++ b/src/pocketmine/item/IronChestplate.php @@ -28,4 +28,8 @@ class IronChestplate extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::IRON_CHESTPLATE, $meta, "Iron Chestplate"); } + + public function getDefensePoints() : int{ + return 6; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronHelmet.php b/src/pocketmine/item/IronHelmet.php index 2a7a7b8f6..325563648 100644 --- a/src/pocketmine/item/IronHelmet.php +++ b/src/pocketmine/item/IronHelmet.php @@ -28,4 +28,8 @@ class IronHelmet extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::IRON_HELMET, $meta, "Iron Helmet"); } + + public function getDefensePoints() : int{ + return 2; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronLeggings.php b/src/pocketmine/item/IronLeggings.php index f0a135b4b..208dc50e8 100644 --- a/src/pocketmine/item/IronLeggings.php +++ b/src/pocketmine/item/IronLeggings.php @@ -28,4 +28,8 @@ class IronLeggings extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::IRON_LEGGINGS, $meta, "Iron Leggings"); } + + public function getDefensePoints() : int{ + return 5; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronPickaxe.php b/src/pocketmine/item/IronPickaxe.php index 28a43bc90..fc87f33ca 100644 --- a/src/pocketmine/item/IronPickaxe.php +++ b/src/pocketmine/item/IronPickaxe.php @@ -32,4 +32,8 @@ class IronPickaxe extends Tool{ public function isPickaxe(){ return Tool::TIER_IRON; } + + public function getAttackPoints() : int{ + return 5; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronShovel.php b/src/pocketmine/item/IronShovel.php index 129e970ad..b2d7cbec6 100644 --- a/src/pocketmine/item/IronShovel.php +++ b/src/pocketmine/item/IronShovel.php @@ -32,4 +32,8 @@ class IronShovel extends Tool{ public function isShovel(){ return Tool::TIER_IRON; } + + public function getAttackPoints() : int{ + return 4; + } } \ No newline at end of file diff --git a/src/pocketmine/item/IronSword.php b/src/pocketmine/item/IronSword.php index 84d4cb1d9..f3ca369b4 100644 --- a/src/pocketmine/item/IronSword.php +++ b/src/pocketmine/item/IronSword.php @@ -32,4 +32,8 @@ class IronSword extends Tool{ public function isSword(){ return Tool::TIER_IRON; } + + public function getAttackPoints() : int{ + return 7; + } } \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 4e2e91343..c64aa463b 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -746,6 +746,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 * diff --git a/src/pocketmine/item/LeatherBoots.php b/src/pocketmine/item/LeatherBoots.php index 1008d491a..f8a494d9d 100644 --- a/src/pocketmine/item/LeatherBoots.php +++ b/src/pocketmine/item/LeatherBoots.php @@ -28,4 +28,8 @@ class LeatherBoots extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::LEATHER_BOOTS, $meta, "Leather Boots"); } + + public function getDefensePoints() : int{ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/LeatherCap.php b/src/pocketmine/item/LeatherCap.php index 30ce1dde1..1dead2531 100644 --- a/src/pocketmine/item/LeatherCap.php +++ b/src/pocketmine/item/LeatherCap.php @@ -28,4 +28,8 @@ class LeatherCap extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::LEATHER_CAP, $meta, "Leather Cap"); } + + public function getDefensePoints() : int{ + return 1; + } } \ No newline at end of file diff --git a/src/pocketmine/item/LeatherPants.php b/src/pocketmine/item/LeatherPants.php index 6d181811c..7d9dda553 100644 --- a/src/pocketmine/item/LeatherPants.php +++ b/src/pocketmine/item/LeatherPants.php @@ -28,4 +28,8 @@ class LeatherPants extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::LEATHER_PANTS, $meta, "Leather Pants"); } + + public function getDefensePoints() : int{ + return 2; + } } \ No newline at end of file diff --git a/src/pocketmine/item/LeatherTunic.php b/src/pocketmine/item/LeatherTunic.php index d5fe6f56a..878dcb5fe 100644 --- a/src/pocketmine/item/LeatherTunic.php +++ b/src/pocketmine/item/LeatherTunic.php @@ -28,4 +28,8 @@ class LeatherTunic extends Armor{ public function __construct(int $meta = 0){ parent::__construct(self::LEATHER_TUNIC, $meta, "Leather Tunic"); } + + public function getDefensePoints() : int{ + return 3; + } } \ No newline at end of file diff --git a/src/pocketmine/item/StoneAxe.php b/src/pocketmine/item/StoneAxe.php index a4f67cacc..6e9d14137 100644 --- a/src/pocketmine/item/StoneAxe.php +++ b/src/pocketmine/item/StoneAxe.php @@ -33,4 +33,8 @@ class StoneAxe extends Tool{ public function isAxe(){ return Tool::TIER_STONE; } + + public function getAttackPoints() : int{ + return 5; + } } \ No newline at end of file diff --git a/src/pocketmine/item/StonePickaxe.php b/src/pocketmine/item/StonePickaxe.php index dfb296dab..4a904cee5 100644 --- a/src/pocketmine/item/StonePickaxe.php +++ b/src/pocketmine/item/StonePickaxe.php @@ -32,4 +32,8 @@ class StonePickaxe extends Tool{ public function isPickaxe(){ return Tool::TIER_STONE; } + + public function getAttackPoints() : int{ + return 4; + } } diff --git a/src/pocketmine/item/StoneShovel.php b/src/pocketmine/item/StoneShovel.php index 8378ae424..918a642b2 100644 --- a/src/pocketmine/item/StoneShovel.php +++ b/src/pocketmine/item/StoneShovel.php @@ -32,4 +32,8 @@ class StoneShovel extends Tool{ public function isShovel(){ return Tool::TIER_STONE; } + + public function getAttackPoints() : int{ + return 3; + } } diff --git a/src/pocketmine/item/StoneSword.php b/src/pocketmine/item/StoneSword.php index 614755107..8084eb5fb 100644 --- a/src/pocketmine/item/StoneSword.php +++ b/src/pocketmine/item/StoneSword.php @@ -32,4 +32,8 @@ class StoneSword extends Tool{ public function isSword(){ return Tool::TIER_STONE; } + + public function getAttackPoints() : int{ + return 6; + } } diff --git a/src/pocketmine/item/WoodenAxe.php b/src/pocketmine/item/WoodenAxe.php index 64ff55cd5..8cb28d2fb 100644 --- a/src/pocketmine/item/WoodenAxe.php +++ b/src/pocketmine/item/WoodenAxe.php @@ -36,4 +36,8 @@ class WoodenAxe extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 4; + } } diff --git a/src/pocketmine/item/WoodenPickaxe.php b/src/pocketmine/item/WoodenPickaxe.php index d08aabaf4..a2df1dc71 100644 --- a/src/pocketmine/item/WoodenPickaxe.php +++ b/src/pocketmine/item/WoodenPickaxe.php @@ -36,4 +36,8 @@ class WoodenPickaxe extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 3; + } } diff --git a/src/pocketmine/item/WoodenShovel.php b/src/pocketmine/item/WoodenShovel.php index 760541627..8582ba97f 100644 --- a/src/pocketmine/item/WoodenShovel.php +++ b/src/pocketmine/item/WoodenShovel.php @@ -36,4 +36,8 @@ class WoodenShovel extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 2; + } } diff --git a/src/pocketmine/item/WoodenSword.php b/src/pocketmine/item/WoodenSword.php index 034a2ff9b..37d9ccfa7 100644 --- a/src/pocketmine/item/WoodenSword.php +++ b/src/pocketmine/item/WoodenSword.php @@ -36,4 +36,8 @@ class WoodenSword extends Tool{ public function getFuelTime() : int{ return 200; } + + public function getAttackPoints() : int{ + return 5; + } }