Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement enchanting system #5953

Merged
merged 97 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
741486e
Add an enchanting system
S3v3Nice Jul 31, 2023
a5e12e8
Merge branch 'enchanting' into minor-next
S3v3Nice Jul 31, 2023
54dfd70
Register incompatibility for Fortune and Silk Touch enchantments
S3v3Nice Jul 31, 2023
774fde8
Fix phpstan errors
S3v3Nice Jul 31, 2023
50688e1
Fix phpstan errors 2
S3v3Nice Jul 31, 2023
1ed7559
Fix code style
S3v3Nice Jul 31, 2023
7066c22
Changes on review
S3v3Nice Aug 1, 2023
ef2a87d
Add isDyeable to ArmorMaterial
S3v3Nice Aug 1, 2023
2e63d39
Small code style fix
S3v3Nice Aug 1, 2023
1409be2
Changes on review; Add EnchantmentOption
S3v3Nice Aug 1, 2023
9754989
Small code style fix
S3v3Nice Aug 1, 2023
f26b11d
Small phpstan fix
S3v3Nice Aug 1, 2023
6767a8f
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 1, 2023
f941d23
Small code style fix
S3v3Nice Aug 1, 2023
c920898
Move send PlayerEnchantOptionsPacket logic to NetworkSession
S3v3Nice Aug 1, 2023
0ec6773
Changes on review
S3v3Nice Aug 1, 2023
0c351df
Very small code style fix
S3v3Nice Aug 1, 2023
a07056f
Specify enchantmentFlag of carved pumpkin and mob head in their own c…
S3v3Nice Aug 1, 2023
189c9ed
Fix default value for $minCost and $maxCost in Enchantment
S3v3Nice Aug 1, 2023
7a673b0
Prevent crash on incorrect enchantment option id being sent by client
S3v3Nice Aug 1, 2023
27dfe40
Remove output caching (`prepareOutput`) and `getLapis` from EnchantIn…
S3v3Nice Aug 1, 2023
e671f54
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 1, 2023
f90d5e3
Changes on review
S3v3Nice Aug 1, 2023
5446787
Merge remote-tracking branch 'origin/minor-next' into minor-next
S3v3Nice Aug 1, 2023
e3e8595
Fix `EnchantmentHelper::getEnchantability`
S3v3Nice Aug 2, 2023
bb3a2ed
Changes on review
S3v3Nice Aug 2, 2023
84d3f47
Changes on review
S3v3Nice Aug 3, 2023
777f83d
Remove @var from EnchantmentHelper
S3v3Nice Aug 3, 2023
c1a8e70
Changes on review
S3v3Nice Aug 3, 2023
dd4b577
Make the enchantment incompatibility system tag-based
S3v3Nice Aug 3, 2023
0654da6
Add `Human::setXpSeed`, Remove `Player::onEnchant`
S3v3Nice Aug 3, 2023
2d9e622
Add EnchantingTableOptionRegistry; Remove `Enchantment::isTreasure`
S3v3Nice Aug 3, 2023
82ab503
Rename `minCost`, `maxCost` to `minEnchantingPower`, `maxEnchantingPo…
S3v3Nice Aug 3, 2023
1107ad1
Add PlayerEnchantmentOptionsRequestEvent and some changes
S3v3Nice Aug 3, 2023
b6fb6d5
Fix code style
S3v3Nice Aug 3, 2023
3fd94aa
Add `Item::getEnchantability` and some other changes
S3v3Nice Aug 4, 2023
e079ccb
Small fixes
S3v3Nice Aug 4, 2023
686ca71
Rename `enchantmentOptions` to `options` in PlayerEnchantmentOptionsR…
S3v3Nice Aug 4, 2023
1f3a62d
PlayerEnchantmentOptionsRequestEvent: Remove `item` and `enchantmentT…
S3v3Nice Aug 4, 2023
99e6bf4
Add `EnchantInventory::getLapis`
S3v3Nice Aug 4, 2023
386a595
Changes on review
S3v3Nice Aug 4, 2023
b2c5be0
Changes on review
S3v3Nice Aug 5, 2023
aead55c
Specify `$enchantments` parameter type in EnchantmentHelper
S3v3Nice Aug 5, 2023
a6f5cc3
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 5, 2023
971e67f
Edit `EnchantItemEvent::getCost` doc
S3v3Nice Aug 5, 2023
7e7e152
Some code cleanup in EnchantInventory
S3v3Nice Aug 7, 2023
5e82fd6
Fix Pumpkin and LitPumpkin break info
S3v3Nice Aug 7, 2023
1c18017
Changes on review
S3v3Nice Aug 7, 2023
4616416
Specify that result of `EnchantInventory::getOptionCost` is not null …
S3v3Nice Aug 7, 2023
ba57dca
Make ItemStackRequestExecutor subtract option id offset
S3v3Nice Aug 7, 2023
1c0be37
Complete remove $optionIds from `NetworkSession::sendEnchantOptions`
S3v3Nice Aug 7, 2023
36aa974
Remove unnecessary second use of EnchantmentHelper in EnchantInventory
S3v3Nice Aug 8, 2023
7d054bc
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 8, 2023
115c168
Use double quotes instead of single quotes for strings
S3v3Nice Aug 8, 2023
96fbba5
New item enchantment tag system
S3v3Nice Aug 8, 2023
e6bae92
Fix code style and phpstan errors
S3v3Nice Aug 8, 2023
a4ab760
Changes on review
S3v3Nice Aug 8, 2023
815d644
Fix code style
S3v3Nice Aug 8, 2023
0090328
Changes on review
S3v3Nice Aug 8, 2023
03883ec
Fix code style and phpstan errors
S3v3Nice Aug 8, 2023
0624be8
Fix validation for already set `$this->inputItem` in EnchantTransaction
S3v3Nice Aug 8, 2023
05c4c52
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 8, 2023
6be6a1d
Fix docs of `Block::getEnchantmentTags` and `Item::getEnchantmentTags`
S3v3Nice Aug 8, 2023
b8583d3
Rename `getXpSeed`, `setXpSeed`, `generateXpSeed` to `getEnchantmentS…
S3v3Nice Aug 8, 2023
c4f1618
Small code cleanup and enhancements
S3v3Nice Aug 8, 2023
a4374dd
Convert ArmorMaterial from 'enum' to simple class; Add VanillaArmorMa…
S3v3Nice Aug 9, 2023
87759b6
Remove unnecessary `BREAKABLE` item enchantment tag
S3v3Nice Aug 9, 2023
2422a1b
Change EnchantingTableOptionRegistry to AvailableEnchantmentRegistry
S3v3Nice Aug 9, 2023
2f0d409
Fix code style
S3v3Nice Aug 9, 2023
7856d9b
Add `isAvailableForItem` into AvailableEnchantmentRegistry
S3v3Nice Aug 9, 2023
a5e16e7
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 9, 2023
b2216dc
Remove `$onlyPrimaryTags` param, Add `getAvailableEnchantingTableEnch…
S3v3Nice Aug 9, 2023
835f1ff
Rename two methods in AvailableEnchantmentRegistry
S3v3Nice Aug 10, 2023
ddb534d
Rename `getNonGroupingTags` to `getLeafTags` in ItemEnchantmentTagReg…
S3v3Nice Aug 10, 2023
3fe1bda
Optimize `getLeafTags` in ItemEnchantmentTagRegistry
S3v3Nice Aug 10, 2023
8c9c409
Fix code style and phpstan errors
S3v3Nice Aug 10, 2023
9d6a762
Optimize `isTagArraySubset`, make `getLeafTags` private in ItemEnchan…
S3v3Nice Aug 10, 2023
7f51c37
Place `getLeafTagsForArray` below `isTagArraySubset` in ItemEnchantme…
S3v3Nice Aug 10, 2023
6698b40
Put assertion in `unregister` later in ItemEnchantmentTagRegistry
S3v3Nice Aug 10, 2023
73b1cc7
Improve documentation for two methods in AvailableEnchantmentRegistry
S3v3Nice Aug 10, 2023
fac7e28
Merge branch 'minor-next' into minor-next
S3v3Nice Aug 10, 2023
5c6114e
Adjust the exception message in `ItemEnchantmentTagRegistry::assertNo…
S3v3Nice Aug 10, 2023
8c476d3
Small cleanup for `AvailableEnchantmentRegistry::getEnchantingTableEn…
S3v3Nice Aug 10, 2023
7343a8a
Add missing documentation for `ToolTier::getEnchantability` and `Bloc…
S3v3Nice Aug 10, 2023
de1e1be
Better handling of enchantment recipe IDs
dktapps Aug 15, 2023
9d79ac4
Change `isTagArraySubset` to `isTagArrayIntersection` in ItemEnchantm…
S3v3Nice Aug 15, 2023
c9e0dff
Fix phpstan error
S3v3Nice Aug 15, 2023
c67ebd8
Fix @see in docs of `getEnchantmentTags`
S3v3Nice Aug 15, 2023
fee0085
Revert LEATHER as the default armor material
S3v3Nice Aug 15, 2023
e136faa
Limit the number of enchantment options in PlayerEnchantmentOptionsRe…
S3v3Nice Aug 15, 2023
9c49c5d
Update docs for `getEnchantmentTags`
S3v3Nice Aug 15, 2023
cb0c2c7
EnchantmentHelper: do not check space twice if bookshelves are stacked
dktapps Aug 15, 2023
27962fa
Rename and move some stuff
dktapps Aug 15, 2023
1524b23
Use the conventional way of passing player for player events
dktapps Aug 15, 2023
afcf067
Docs cleanup, rename some things
dktapps Aug 15, 2023
51d9424
IncompatibleEnchantmentRegistry: Avoid unncessary array_searches
dktapps Aug 15, 2023
87edda4
Added WEAPONS tag
dktapps Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Projectile;
use pocketmine\item\enchantment\ItemFlags;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\item\Item;
use pocketmine\item\ItemBlock;
Expand Down Expand Up @@ -67,6 +68,7 @@ class Block{
protected BlockIdentifier $idInfo;
protected string $fallbackName;
protected BlockTypeInfo $typeInfo;
protected int $itemEnchantmentFlag;
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
protected Position $position;

/** @var AxisAlignedBB[]|null */
Expand All @@ -80,10 +82,11 @@ class Block{
/**
* @param string $name English name of the block type (TODO: implement translations)
*/
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, int $itemEnchantmentFlag = ItemFlags::NONE){
$this->idInfo = $idInfo;
$this->fallbackName = $name;
$this->typeInfo = $typeInfo;
$this->itemEnchantmentFlag = $itemEnchantmentFlag;
$this->position = new Position(0, 0, 0, null);

$calculator = new RuntimeDataSizeCalculator();
Expand Down
3 changes: 2 additions & 1 deletion src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use pocketmine\block\utils\WoodType;
use pocketmine\crafting\FurnaceType;
use pocketmine\entity\projectile\Projectile;
use pocketmine\item\enchantment\ItemFlags;
use pocketmine\item\Item;
use pocketmine\item\ToolTier;
use pocketmine\math\Facing;
Expand Down Expand Up @@ -964,7 +965,7 @@ public function getBreakTime(Item $item) : float{

$pumpkinBreakInfo = new Info(BreakInfo::axe(1.0));
self::register("pumpkin", new Pumpkin(new BID(Ids::PUMPKIN), "Pumpkin", $pumpkinBreakInfo));
self::register("carved_pumpkin", new CarvedPumpkin(new BID(Ids::CARVED_PUMPKIN), "Carved Pumpkin", $pumpkinBreakInfo));
self::register("carved_pumpkin", new CarvedPumpkin(new BID(Ids::CARVED_PUMPKIN), "Carved Pumpkin", $pumpkinBreakInfo, ItemFlags::HEAD));
self::register("lit_pumpkin", new LitPumpkin(new BID(Ids::LIT_PUMPKIN), "Jack o'Lantern", $pumpkinBreakInfo));

self::register("pumpkin_stem", new PumpkinStem(new BID(Ids::PUMPKIN_STEM), "Pumpkin Stem", new Info(BreakInfo::instant())));
Expand Down
83 changes: 83 additions & 0 deletions src/block/inventory/EnchantInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,101 @@

namespace pocketmine\block\inventory;

use pocketmine\data\bedrock\EnchantmentIdMap;
use pocketmine\inventory\SimpleInventory;
use pocketmine\inventory\TemporaryInventory;
use pocketmine\item\enchantment\EnchantmentHelper as Helper;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\Item;
use pocketmine\item\ItemTypeIds;
use pocketmine\item\VanillaItems;
use pocketmine\network\mcpe\protocol\PlayerEnchantOptionsPacket;
use pocketmine\network\mcpe\protocol\types\Enchant;
use pocketmine\network\mcpe\protocol\types\EnchantOption;
use pocketmine\world\Position;
use function array_map;
use function array_merge;
use function count;
use function is_null;

class EnchantInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{
use BlockInventoryTrait;

public const SLOT_INPUT = 0;
public const SLOT_LAPIS = 1;

/** @var EnchantOption[] $options */
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
private array $options = [];

/** @var Item[] $outputs */
private array $outputs = [];

public function __construct(Position $holder){
$this->holder = $holder;
parent::__construct(2);
}

protected function onSlotChange(int $index, Item $before) : void{
if($index == self::SLOT_INPUT){
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
foreach($this->viewers as $viewer){
$this->options = Helper::getEnchantOptions($this->holder, $this->getItem(self::SLOT_INPUT), $viewer->getEnchantmentSeed());
$this->outputs = [];

if(count($this->options) !== 0){
$viewer->getNetworkSession()->sendDataPacket(PlayerEnchantOptionsPacket::create($this->options));
}
}
}

parent::onSlotChange($index, $before);
}

public function getInput() : Item{
return $this->getItem(self::SLOT_INPUT);
}

public function getLapis() : Item{
return $this->getItem(self::SLOT_LAPIS);
}

public function getOutput(int $optionId) : Item{
$this->prepareOutput($optionId);
return $this->outputs[$optionId];
}

private function prepareOutput(int $optionId) : void{
if(isset($this->outputs[$optionId])){
return;
}

$option = $this->options[$optionId] ?? null;
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
if(is_null($option)){
throw new \RuntimeException("Failed to find enchantment option with network id $optionId");
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
}

$enchantments = array_map(
function(Enchant $e){
$enchantment = EnchantmentIdMap::getInstance()->fromId($e->getId());
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
if(is_null($enchantment)){
throw new \RuntimeException("Failed to get enchantment with id {$e->getId()}");
}
return new EnchantmentInstance($enchantment, $e->getLevel());
},
array_merge(
$option->getEquipActivatedEnchantments(),
$option->getHeldActivatedEnchantments(),
$option->getSelfActivatedEnchantments()
)
);

$outputItem = $this->getItem(self::SLOT_INPUT);
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
if($outputItem->getTypeId() === ItemTypeIds::BOOK){
$outputItem = VanillaItems::ENCHANTED_BOOK();
}
foreach($enchantments as $enchantment){
$outputItem->addEnchantment($enchantment);
}

$this->outputs[$optionId] = $outputItem;
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private function register1to1ItemMappings() : void{
$this->map1to1Item(Ids::ECHO_SHARD, Items::ECHO_SHARD());
$this->map1to1Item(Ids::EGG, Items::EGG());
$this->map1to1Item(Ids::EMERALD, Items::EMERALD());
$this->map1to1Item(Ids::ENCHANTED_BOOK, Items::ENCHANTED_BOOK());
$this->map1to1Item(Ids::ENCHANTED_GOLDEN_APPLE, Items::ENCHANTED_GOLDEN_APPLE());
$this->map1to1Item(Ids::ENDER_PEARL, Items::ENDER_PEARL());
$this->map1to1Item(Ids::EXPERIENCE_BOTTLE, Items::EXPERIENCE_BOTTLE());
Expand Down
16 changes: 12 additions & 4 deletions src/entity/Human.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function getNetworkTypeId() : string{ return EntityIds::PLAYER; }
protected HungerManager $hungerManager;
protected ExperienceManager $xpManager;

protected int $xpSeed;
protected int $enchantmentSeed;
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved

public function __construct(Location $location, Skin $skin, ?CompoundTag $nbt = null){
$this->skin = $skin;
Expand Down Expand Up @@ -211,6 +211,14 @@ public function getXpManager() : ExperienceManager{
return $this->xpManager;
}

public function getEnchantmentSeed() : int{
return $this->enchantmentSeed;
}

protected function generateEnchantmentSeed() : void{
$this->enchantmentSeed = mt_rand(Limits::INT32_MIN, Limits::INT32_MAX);
}

public function getXpDropAmount() : int{
//this causes some XP to be lost on death when above level 1 (by design), dropping at most enough points for
//about 7.5 levels of XP.
Expand Down Expand Up @@ -332,9 +340,9 @@ function(Inventory $unused, array $oldItems) use ($syncHeldItem) : void{
$this->xpManager->setLifetimeTotalXp($nbt->getInt(self::TAG_LIFETIME_XP_TOTAL, 0));

if(($xpSeedTag = $nbt->getTag(self::TAG_XP_SEED)) instanceof IntTag){
$this->xpSeed = $xpSeedTag->getValue();
$this->enchantmentSeed = $xpSeedTag->getValue();
}else{
$this->xpSeed = random_int(Limits::INT32_MIN, Limits::INT32_MAX);
$this->generateEnchantmentSeed();
}
}

Expand Down Expand Up @@ -408,7 +416,7 @@ public function saveNBT() : CompoundTag{
$nbt->setInt(self::TAG_XP_LEVEL, $this->xpManager->getXpLevel());
$nbt->setFloat(self::TAG_XP_PROGRESS, $this->xpManager->getXpProgress());
$nbt->setInt(self::TAG_LIFETIME_XP_TOTAL, $this->xpManager->getLifetimeTotalXp());
$nbt->setInt(self::TAG_XP_SEED, $this->xpSeed);
$nbt->setInt(self::TAG_XP_SEED, $this->enchantmentSeed);

$inventoryTag = new ListTag([], NBT::TAG_Compound);
$nbt->setTag(self::TAG_INVENTORY, $inventoryTag);
Expand Down
90 changes: 90 additions & 0 deletions src/inventory/transaction/EnchantTransaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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\inventory\transaction;

use pocketmine\block\inventory\EnchantInventory;
use pocketmine\inventory\transaction\action\InventoryAction;
use pocketmine\item\Item;
use pocketmine\item\ItemTypeIds;
use pocketmine\player\Player;
use function count;
use function is_null;

class EnchantTransaction extends InventoryTransaction{

private int $optionId;
private ?Item $inputItem = null;
private int $lapisCost = 0;

public function __construct(Player $source, int $optionId){
$this->optionId = $optionId;
parent::__construct($source);
}

public function validate() : void{
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
if(count($this->actions) < 1){
throw new TransactionValidationException("Transaction must have at least one action to be executable");
}

/** @var EnchantInventory $enchantWindow */
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
$enchantWindow = $this->source->getCurrentWindow();
if(is_null($this->inputItem) || !$this->inputItem->equalsExact($enchantWindow->getInput())){
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
throw new TransactionValidationException("Incorrect input item");
}

if($this->source->hasFiniteResources()){
$enchantLevel = $this->getEnchantLevel();
if($this->lapisCost !== $enchantLevel){
throw new TransactionValidationException("Expected the amount of lapis lazuli spent to be {$this->getEnchantLevel()}, but received $this->lapisCost");
}

$xpLevel = $this->source->getXpManager()->getXpLevel();
if($xpLevel < $enchantLevel){
throw new TransactionValidationException("Expected player to have xp level at least of $enchantLevel, but received $xpLevel");
}
}
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
}

public function addAction(InventoryAction $action) : void{
parent::addAction($action);

$sourceItem = $action->getSourceItem();
$targetItem = $action->getTargetItem();

if($sourceItem->getTypeId() === ItemTypeIds::LAPIS_LAZULI){
$this->lapisCost = $sourceItem->getCount() - $targetItem->getCount();
}else{
$this->inputItem = $sourceItem;
}
}

public function execute() : void{
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
parent::execute();
$this->source->onEnchant($this->getEnchantLevel());
}

public function getEnchantLevel() : int{
return $this->optionId + 1;
}
}
9 changes: 7 additions & 2 deletions src/item/Armor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use pocketmine\color\Color;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\inventory\ArmorInventory;
use pocketmine\item\enchantment\ItemFlags;
use pocketmine\item\enchantment\ProtectionEnchantment;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\math\Vector3;
Expand All @@ -44,8 +45,8 @@ class Armor extends Durable{

protected ?Color $customColor = null;

public function __construct(ItemIdentifier $identifier, string $name, ArmorTypeInfo $info){
parent::__construct($identifier, $name);
public function __construct(ItemIdentifier $identifier, string $name, ArmorTypeInfo $info, int $enchantmentFlag = ItemFlags::NONE){
parent::__construct($identifier, $name, $enchantmentFlag);
$this->armorInfo = $info;
}

Expand All @@ -72,6 +73,10 @@ public function isFireProof() : bool{
return $this->armorInfo->isFireProof();
}

public function getMaterial() : ArmorMaterial{
return $this->armorInfo->getMaterial();
}

/**
* Returns the dyed colour of this armour piece. This generally only applies to leather armour.
*/
Expand Down
69 changes: 69 additions & 0 deletions src/item/ArmorMaterial.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\utils\EnumTrait;

/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see build/generate-registry-annotations.php
* @generate-registry-docblock
*
* @method static ArmorMaterial CHAINMAIL()
* @method static ArmorMaterial DIAMOND()
* @method static ArmorMaterial GOLD()
* @method static ArmorMaterial IRON()
* @method static ArmorMaterial LEATHER()
* @method static ArmorMaterial NETHERITE()
* @method static ArmorMaterial TURTLE()
*/
final class ArmorMaterial{
use EnumTrait {
__construct as Enum___construct;
}

protected static function setup() : void{
self::registerAll(
new self("leather", 15),
new self("chainmail", 12),
new self("iron", 9),
new self("turtle", 9),
new self("gold", 25),
new self("diamond", 10),
new self("netherite", 15)
);
}

private function __construct(
string $name,
private int $enchantability
){
$this->Enum___construct($name);
}

public function getEnchantability() : int{
return $this->enchantability;
}
}
S3v3Nice marked this conversation as resolved.
Show resolved Hide resolved
Loading