AnvilTransaction 5.46.0
Extends InventoryTransaction
Repairing, combining and renaming in an anvil (vanilla AnvilMenu.createResult):
- repair with the material of the item: each material item restores a quarter of the durability (1 level each);
- combine with the same item (durability of both plus 12%, 2 levels) and/or an enchanted book: enchantments are merged (same levels go one up, up to the maximum), each costing its anvil cost (1, 2, 4 or 8 by rarity, halved for books) times the level; incompatible ones cost 1 level and are dropped;
- rename (1 level; renaming alone never costs more than 39 levels). The prior work penalty (RepairCost tag) of both items is added and doubles plus one after each use. Results of 40 levels or more are "too expensive" outside creative. The anvil has a 12% chance to get damaged per use.
Constants
MAX_NAME_LENGTH
php
public const MAX_NAME_LENGTH = 50TAG_REPAIR_COST
php
public const TAG_REPAIR_COST = "RepairCost"TOO_EXPENSIVE
php
public const TOO_EXPENSIVE = 40Methods
__construct()
php
public function __construct(\pocketmine\player\Player $source, \pocketmine\world\Position $anvilPosition, \pocketmine\inventory\transaction\AnvilResult $expected, array $actions = [])calculateResult()
php
public static function calculateResult(\pocketmine\item\Item $input, ?\pocketmine\item\Item $material, ?string $newName, bool $creative) : ?\pocketmine\inventory\transaction\AnvilResultComputes the anvil result, or null if nothing can be made.
execute()
php
public function execute() : voidgetAnvilCost()
php
public static function getAnvilCost(\pocketmine\item\enchantment\Enchantment $enchantment) : intAnvil cost of an enchantment per level (vanilla: 1, 2, 4 or 8 for common, uncommon, rare and very rare ones).
getExpectedResult()
php
public function getExpectedResult() : \pocketmine\inventory\transaction\AnvilResultgetRepairCost()
php
public static function getRepairCost(\pocketmine\item\Item $item) : intisValidRepairMaterial()
php
public static function isValidRepairMaterial(\pocketmine\item\Item $item, \pocketmine\item\Item $material) : boolWhether the material repairs the item in an anvil (vanilla repairable tags).
validate()
php
public function validate() : void