Removing useless armour descendent classes, move armour slot to ArmorTypeInfo

This commit is contained in:
Dylan K. Taylor 2019-08-02 16:17:04 +01:00
parent 056c5ed6cd
commit 58e9728710
9 changed files with 56 additions and 179 deletions

View File

@ -434,11 +434,7 @@ This version features substantial changes to the network system, improving coher
- `Item::removeCreativeItem()` -> `CreativeInventory::remove()`
- The following classes have been added:
- `ArmorTypeInfo`
- `Boots`
- `Chestplate`
- `Fertilizer`
- `Helmet`
- `Leggings`
- `LiquidBucket`
- `MilkBucket`
- `WritableBookBase`

View File

@ -38,7 +38,7 @@ use pocketmine\utils\Color;
use function lcg_value;
use function mt_rand;
abstract class Armor extends Durable{
class Armor extends Durable{
public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
@ -65,7 +65,9 @@ abstract class Armor extends Durable{
* @see ArmorInventory
* @return int
*/
abstract public function getArmorSlot() : int;
public function getArmorSlot() : int{
return $this->armorInfo->getArmorSlot();
}
public function getMaxStackSize() : int{
return 1;

View File

@ -29,10 +29,13 @@ class ArmorTypeInfo{
private $defensePoints;
/** @var int */
private $maxDurability;
/** @var int */
private $armorSlot;
public function __construct(int $defensePoints, int $maxDurability){
public function __construct(int $defensePoints, int $maxDurability, int $armorSlot){
$this->defensePoints = $defensePoints;
$this->maxDurability = $maxDurability;
$this->armorSlot = $armorSlot;
}
/**
@ -48,4 +51,11 @@ class ArmorTypeInfo{
public function getMaxDurability() : int{
return $this->maxDurability;
}
/**
* @return int
*/
public function getArmorSlot() : int{
return $this->armorSlot;
}
}

View File

@ -1,33 +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;
use pocketmine\inventory\ArmorInventory;
class Boots extends Armor{
public function getArmorSlot() : int{
return ArmorInventory::SLOT_FEET;
}
}

View File

@ -1,33 +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;
use pocketmine\inventory\ArmorInventory;
class Chestplate extends Armor{
public function getArmorSlot() : int{
return ArmorInventory::SLOT_CHEST;
}
}

View File

@ -1,33 +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;
use pocketmine\inventory\ArmorInventory;
class Helmet extends Armor{
public function getArmorSlot() : int{
return ArmorInventory::SLOT_HEAD;
}
}

View File

@ -31,6 +31,7 @@ use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Living;
use pocketmine\inventory\ArmorInventory;
use pocketmine\nbt\tag\CompoundTag;
use function constant;
use function defined;
@ -351,26 +352,26 @@ class ItemFactory{
}
private static function registerArmorItems() : void{
self::register(new Boots(ItemIds::CHAIN_BOOTS, 0, "Chainmail Boots", new ArmorTypeInfo(1, 196)));
self::register(new Boots(ItemIds::DIAMOND_BOOTS, 0, "Diamond Boots", new ArmorTypeInfo(3, 430)));
self::register(new Boots(ItemIds::GOLDEN_BOOTS, 0, "Golden Boots", new ArmorTypeInfo(1, 92)));
self::register(new Boots(ItemIds::IRON_BOOTS, 0, "Iron Boots", new ArmorTypeInfo(2, 196)));
self::register(new Boots(ItemIds::LEATHER_BOOTS, 0, "Leather Boots", new ArmorTypeInfo(1, 66)));
self::register(new Chestplate(ItemIds::CHAIN_CHESTPLATE, 0, "Chainmail Chestplate", new ArmorTypeInfo(5, 241)));
self::register(new Chestplate(ItemIds::DIAMOND_CHESTPLATE, 0, "Diamond Chestplate", new ArmorTypeInfo(8, 529)));
self::register(new Chestplate(ItemIds::GOLDEN_CHESTPLATE, 0, "Golden Chestplate", new ArmorTypeInfo(5, 113)));
self::register(new Chestplate(ItemIds::IRON_CHESTPLATE, 0, "Iron Chestplate", new ArmorTypeInfo(6, 241)));
self::register(new Chestplate(ItemIds::LEATHER_CHESTPLATE, 0, "Leather Tunic", new ArmorTypeInfo(3, 81)));
self::register(new Helmet(ItemIds::CHAIN_HELMET, 0, "Chainmail Helmet", new ArmorTypeInfo(2, 166)));
self::register(new Helmet(ItemIds::DIAMOND_HELMET, 0, "Diamond Helmet", new ArmorTypeInfo(3, 364)));
self::register(new Helmet(ItemIds::GOLDEN_HELMET, 0, "Golden Helmet", new ArmorTypeInfo(2, 78)));
self::register(new Helmet(ItemIds::IRON_HELMET, 0, "Iron Helmet", new ArmorTypeInfo(2, 166)));
self::register(new Helmet(ItemIds::LEATHER_HELMET, 0, "Leather Cap", new ArmorTypeInfo(1, 56)));
self::register(new Leggings(ItemIds::CHAIN_LEGGINGS, 0, "Chainmail Leggings", new ArmorTypeInfo(4, 226)));
self::register(new Leggings(ItemIds::DIAMOND_LEGGINGS, 0, "Diamond Leggings", new ArmorTypeInfo(6, 496)));
self::register(new Leggings(ItemIds::GOLDEN_LEGGINGS, 0, "Golden Leggings", new ArmorTypeInfo(3, 106)));
self::register(new Leggings(ItemIds::IRON_LEGGINGS, 0, "Iron Leggings", new ArmorTypeInfo(5, 226)));
self::register(new Leggings(ItemIds::LEATHER_LEGGINGS, 0, "Leather Pants", new ArmorTypeInfo(2, 76)));
self::register(new Armor(ItemIds::CHAIN_BOOTS, 0, "Chainmail Boots", new ArmorTypeInfo(1, 196, ArmorInventory::SLOT_FEET)));
self::register(new Armor(ItemIds::DIAMOND_BOOTS, 0, "Diamond Boots", new ArmorTypeInfo(3, 430, ArmorInventory::SLOT_FEET)));
self::register(new Armor(ItemIds::GOLDEN_BOOTS, 0, "Golden Boots", new ArmorTypeInfo(1, 92, ArmorInventory::SLOT_FEET)));
self::register(new Armor(ItemIds::IRON_BOOTS, 0, "Iron Boots", new ArmorTypeInfo(2, 196, ArmorInventory::SLOT_FEET)));
self::register(new Armor(ItemIds::LEATHER_BOOTS, 0, "Leather Boots", new ArmorTypeInfo(1, 66, ArmorInventory::SLOT_FEET)));
self::register(new Armor(ItemIds::CHAIN_CHESTPLATE, 0, "Chainmail Chestplate", new ArmorTypeInfo(5, 241, ArmorInventory::SLOT_CHEST)));
self::register(new Armor(ItemIds::DIAMOND_CHESTPLATE, 0, "Diamond Chestplate", new ArmorTypeInfo(8, 529, ArmorInventory::SLOT_CHEST)));
self::register(new Armor(ItemIds::GOLDEN_CHESTPLATE, 0, "Golden Chestplate", new ArmorTypeInfo(5, 113, ArmorInventory::SLOT_CHEST)));
self::register(new Armor(ItemIds::IRON_CHESTPLATE, 0, "Iron Chestplate", new ArmorTypeInfo(6, 241, ArmorInventory::SLOT_CHEST)));
self::register(new Armor(ItemIds::LEATHER_CHESTPLATE, 0, "Leather Tunic", new ArmorTypeInfo(3, 81, ArmorInventory::SLOT_CHEST)));
self::register(new Armor(ItemIds::CHAIN_HELMET, 0, "Chainmail Helmet", new ArmorTypeInfo(2, 166, ArmorInventory::SLOT_HEAD)));
self::register(new Armor(ItemIds::DIAMOND_HELMET, 0, "Diamond Helmet", new ArmorTypeInfo(3, 364, ArmorInventory::SLOT_HEAD)));
self::register(new Armor(ItemIds::GOLDEN_HELMET, 0, "Golden Helmet", new ArmorTypeInfo(2, 78, ArmorInventory::SLOT_HEAD)));
self::register(new Armor(ItemIds::IRON_HELMET, 0, "Iron Helmet", new ArmorTypeInfo(2, 166, ArmorInventory::SLOT_HEAD)));
self::register(new Armor(ItemIds::LEATHER_HELMET, 0, "Leather Cap", new ArmorTypeInfo(1, 56, ArmorInventory::SLOT_HEAD)));
self::register(new Armor(ItemIds::CHAIN_LEGGINGS, 0, "Chainmail Leggings", new ArmorTypeInfo(4, 226, ArmorInventory::SLOT_LEGS)));
self::register(new Armor(ItemIds::DIAMOND_LEGGINGS, 0, "Diamond Leggings", new ArmorTypeInfo(6, 496, ArmorInventory::SLOT_LEGS)));
self::register(new Armor(ItemIds::GOLDEN_LEGGINGS, 0, "Golden Leggings", new ArmorTypeInfo(3, 106, ArmorInventory::SLOT_LEGS)));
self::register(new Armor(ItemIds::IRON_LEGGINGS, 0, "Iron Leggings", new ArmorTypeInfo(5, 226, ArmorInventory::SLOT_LEGS)));
self::register(new Armor(ItemIds::LEATHER_LEGGINGS, 0, "Leather Pants", new ArmorTypeInfo(2, 76, ArmorInventory::SLOT_LEGS)));
}
/**

View File

@ -1,33 +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;
use pocketmine\inventory\ArmorInventory;
class Leggings extends Armor{
public function getArmorSlot() : int{
return ArmorInventory::SLOT_LEGS;
}
}

View File

@ -62,10 +62,10 @@ use function assert;
* @method static Bucket BUCKET()
* @method static ItemBlock CAKE()
* @method static Carrot CARROT()
* @method static Boots CHAINMAIL_BOOTS()
* @method static Chestplate CHAINMAIL_CHESTPLATE()
* @method static Helmet CHAINMAIL_HELMET()
* @method static Leggings CHAINMAIL_LEGGINGS()
* @method static Armor CHAINMAIL_BOOTS()
* @method static Armor CHAINMAIL_CHESTPLATE()
* @method static Armor CHAINMAIL_HELMET()
* @method static Armor CHAINMAIL_LEGGINGS()
* @method static Coal CHARCOAL()
* @method static Item CHEMICAL_ALUMINIUM_OXIDE()
* @method static Item CHEMICAL_AMMONIA()
@ -126,11 +126,11 @@ use function assert;
* @method static Boat DARK_OAK_BOAT()
* @method static Item DIAMOND()
* @method static Axe DIAMOND_AXE()
* @method static Boots DIAMOND_BOOTS()
* @method static Chestplate DIAMOND_CHESTPLATE()
* @method static Helmet DIAMOND_HELMET()
* @method static Armor DIAMOND_BOOTS()
* @method static Armor DIAMOND_CHESTPLATE()
* @method static Armor DIAMOND_HELMET()
* @method static Hoe DIAMOND_HOE()
* @method static Leggings DIAMOND_LEGGINGS()
* @method static Armor DIAMOND_LEGGINGS()
* @method static Pickaxe DIAMOND_PICKAXE()
* @method static Shovel DIAMOND_SHOVEL()
* @method static Sword DIAMOND_SWORD()
@ -155,12 +155,12 @@ use function assert;
* @method static Item GOLD_NUGGET()
* @method static GoldenApple GOLDEN_APPLE()
* @method static Axe GOLDEN_AXE()
* @method static Boots GOLDEN_BOOTS()
* @method static Armor GOLDEN_BOOTS()
* @method static GoldenCarrot GOLDEN_CARROT()
* @method static Chestplate GOLDEN_CHESTPLATE()
* @method static Helmet GOLDEN_HELMET()
* @method static Armor GOLDEN_CHESTPLATE()
* @method static Armor GOLDEN_HELMET()
* @method static Hoe GOLDEN_HOE()
* @method static Leggings GOLDEN_LEGGINGS()
* @method static Armor GOLDEN_LEGGINGS()
* @method static Pickaxe GOLDEN_PICKAXE()
* @method static Shovel GOLDEN_SHOVEL()
* @method static Sword GOLDEN_SWORD()
@ -174,12 +174,12 @@ use function assert;
* @method static Item HEART_OF_THE_SEA()
* @method static Item INK_SAC()
* @method static Axe IRON_AXE()
* @method static Boots IRON_BOOTS()
* @method static Chestplate IRON_CHESTPLATE()
* @method static Helmet IRON_HELMET()
* @method static Armor IRON_BOOTS()
* @method static Armor IRON_CHESTPLATE()
* @method static Armor IRON_HELMET()
* @method static Hoe IRON_HOE()
* @method static Item IRON_INGOT()
* @method static Leggings IRON_LEGGINGS()
* @method static Armor IRON_LEGGINGS()
* @method static Item IRON_NUGGET()
* @method static Pickaxe IRON_PICKAXE()
* @method static Shovel IRON_SHOVEL()
@ -188,10 +188,10 @@ use function assert;
* @method static Item LAPIS_LAZULI()
* @method static LiquidBucket LAVA_BUCKET()
* @method static Item LEATHER()
* @method static Boots LEATHER_BOOTS()
* @method static Helmet LEATHER_CAP()
* @method static Leggings LEATHER_PANTS()
* @method static Chestplate LEATHER_TUNIC()
* @method static Armor LEATHER_BOOTS()
* @method static Armor LEATHER_CAP()
* @method static Armor LEATHER_PANTS()
* @method static Armor LEATHER_TUNIC()
* @method static Banner LIGHT_BLUE_BANNER()
* @method static Bed LIGHT_BLUE_BED()
* @method static Dye LIGHT_BLUE_DYE()