mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Use 'enchanting' terminology
'enchant' just didn't feel right, being a verb. All these things pertain to the act of enchanting. This is now also consistent with CraftingTransaction etc. The ship already sailed on EnchantInventory, which will have to be renamed at a later datte. However, that was already inconsistent with 'enchanting table', so that's the odd one out here.
This commit is contained in:
parent
bf668c0f6c
commit
1504fdca24
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory;
|
||||
|
||||
use pocketmine\event\player\PlayerEnchantOptionsRequestEvent;
|
||||
use pocketmine\event\player\PlayerEnchantingOptionsRequestEvent;
|
||||
use pocketmine\inventory\SimpleInventory;
|
||||
use pocketmine\inventory\TemporaryInventory;
|
||||
use pocketmine\item\enchantment\EnchantHelper as Helper;
|
||||
use pocketmine\item\enchantment\EnchantOption;
|
||||
use pocketmine\item\enchantment\EnchantingHelper as Helper;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\world\Position;
|
||||
use function array_values;
|
||||
@ -39,7 +39,7 @@ class EnchantInventory extends SimpleInventory implements BlockInventory, Tempor
|
||||
public const SLOT_INPUT = 0;
|
||||
public const SLOT_LAPIS = 1;
|
||||
|
||||
/** @var EnchantOption[] $options */
|
||||
/** @var EnchantingOption[] $options */
|
||||
private array $options = [];
|
||||
|
||||
public function __construct(Position $holder){
|
||||
@ -54,7 +54,7 @@ class EnchantInventory extends SimpleInventory implements BlockInventory, Tempor
|
||||
$item = $this->getInput();
|
||||
$options = Helper::generateOptions($this->holder, $item, $viewer->getEnchantmentSeed());
|
||||
|
||||
$event = new PlayerEnchantOptionsRequestEvent($viewer, $this, $options);
|
||||
$event = new PlayerEnchantingOptionsRequestEvent($viewer, $this, $options);
|
||||
$event->call();
|
||||
if(!$event->isCancelled() && count($event->getOptions()) > 0){
|
||||
$this->options = array_values($event->getOptions());
|
||||
@ -79,7 +79,7 @@ class EnchantInventory extends SimpleInventory implements BlockInventory, Tempor
|
||||
return $option === null ? null : Helper::enchantItem($this->getInput(), $option->getEnchantments());
|
||||
}
|
||||
|
||||
public function getOption(int $optionId) : ?EnchantOption{
|
||||
public function getOption(int $optionId) : ?EnchantingOption{
|
||||
return $this->options[$optionId] ?? null;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||
use pocketmine\item\enchantment\EnchantHelper;
|
||||
use pocketmine\item\enchantment\EnchantingHelper;
|
||||
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||
use pocketmine\item\enchantment\StringToEnchantmentParser;
|
||||
use pocketmine\lang\KnownTranslationFactory;
|
||||
@ -78,7 +78,7 @@ class EnchantCommand extends VanillaCommand{
|
||||
}
|
||||
|
||||
//this is necessary to deal with enchanted books, which are a different item type than regular books
|
||||
$enchantedItem = EnchantHelper::enchantItem($item, [new EnchantmentInstance($enchantment, $level)]);
|
||||
$enchantedItem = EnchantingHelper::enchantItem($item, [new EnchantmentInstance($enchantment, $level)]);
|
||||
$player->getInventory()->setItemInHand($enchantedItem);
|
||||
|
||||
self::broadcastCommandMessage($sender, KnownTranslationFactory::commands_enchant_success($player->getName()));
|
||||
|
@ -37,7 +37,7 @@ use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerEnderInventory;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\inventory\PlayerOffHandInventory;
|
||||
use pocketmine\item\enchantment\EnchantHelper;
|
||||
use pocketmine\item\enchantment\EnchantingHelper;
|
||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Totem;
|
||||
@ -219,7 +219,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
}
|
||||
|
||||
public function regenerateEnchantmentSeed() : void{
|
||||
$this->xpSeed = EnchantHelper::generateSeed();
|
||||
$this->xpSeed = EnchantingHelper::generateSeed();
|
||||
}
|
||||
|
||||
public function getXpDropAmount() : int{
|
||||
@ -345,7 +345,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
if(($xpSeedTag = $nbt->getTag(self::TAG_XP_SEED)) instanceof IntTag){
|
||||
$this->xpSeed = $xpSeedTag->getValue();
|
||||
}else{
|
||||
$this->xpSeed = EnchantHelper::generateSeed();
|
||||
$this->xpSeed = EnchantingHelper::generateSeed();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ use pocketmine\block\inventory\EnchantInventory;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\event\Event;
|
||||
use pocketmine\item\enchantment\EnchantOption;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\Utils;
|
||||
use function count;
|
||||
@ -36,36 +36,36 @@ use function count;
|
||||
* Called when a player inserts an item into an enchanting table's input slot.
|
||||
* The options provided by the event will be shown on the enchanting table menu.
|
||||
*/
|
||||
class PlayerEnchantOptionsRequestEvent extends PlayerEvent implements Cancellable{
|
||||
class PlayerEnchantingOptionsRequestEvent extends PlayerEvent implements Cancellable{
|
||||
use CancellableTrait;
|
||||
|
||||
/**
|
||||
* @param EnchantOption[] $options
|
||||
* @param EnchantingOption[] $options
|
||||
*/
|
||||
public function __construct(
|
||||
Player $player,
|
||||
private readonly EnchantInventory $enchantInventory,
|
||||
private readonly EnchantInventory $inventory,
|
||||
private array $options
|
||||
){
|
||||
$this->player = $player;
|
||||
}
|
||||
|
||||
public function getEnchantInventory() : EnchantInventory{
|
||||
return $this->enchantInventory;
|
||||
public function getInventory() : EnchantInventory{
|
||||
return $this->inventory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EnchantOption[]
|
||||
* @return EnchantingOption[]
|
||||
*/
|
||||
public function getOptions() : array{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EnchantOption[] $options
|
||||
* @param EnchantingOption[] $options
|
||||
*/
|
||||
public function setOptions(array $options) : void{
|
||||
Utils::validateArrayValueType($options, function(EnchantOption $_) : void{ });
|
||||
Utils::validateArrayValueType($options, function(EnchantingOption $_) : void{ });
|
||||
if(($optionCount = count($options)) > 3){
|
||||
throw new \LogicException("The maximum number of options for an enchanting table is 3, but $optionCount have been passed");
|
||||
}
|
@ -25,8 +25,8 @@ namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
use pocketmine\inventory\transaction\EnchantTransaction;
|
||||
use pocketmine\item\enchantment\EnchantOption;
|
||||
use pocketmine\inventory\transaction\EnchantingTransaction;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\player\Player;
|
||||
|
||||
@ -38,8 +38,8 @@ class PlayerItemEnchantEvent extends PlayerEvent implements Cancellable{
|
||||
|
||||
public function __construct(
|
||||
Player $player,
|
||||
private readonly EnchantTransaction $transaction,
|
||||
private readonly EnchantOption $option,
|
||||
private readonly EnchantingTransaction $transaction,
|
||||
private readonly EnchantingOption $option,
|
||||
private readonly Item $inputItem,
|
||||
private readonly Item $outputItem,
|
||||
private readonly int $cost
|
||||
@ -50,14 +50,14 @@ class PlayerItemEnchantEvent extends PlayerEvent implements Cancellable{
|
||||
/**
|
||||
* Returns the inventory transaction involved in this enchant event.
|
||||
*/
|
||||
public function getTransaction() : EnchantTransaction{
|
||||
public function getTransaction() : EnchantingTransaction{
|
||||
return $this->transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enchantment option used.
|
||||
*/
|
||||
public function getOption() : EnchantOption{
|
||||
public function getOption() : EnchantingOption{
|
||||
return $this->option;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\inventory\transaction;
|
||||
|
||||
use pocketmine\event\player\PlayerItemEnchantEvent;
|
||||
use pocketmine\item\enchantment\EnchantHelper;
|
||||
use pocketmine\item\enchantment\EnchantOption;
|
||||
use pocketmine\item\enchantment\EnchantingHelper;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemTypeIds;
|
||||
use pocketmine\player\Player;
|
||||
@ -33,14 +33,14 @@ use pocketmine\utils\AssumptionFailedError;
|
||||
use function count;
|
||||
use function min;
|
||||
|
||||
class EnchantTransaction extends InventoryTransaction{
|
||||
class EnchantingTransaction extends InventoryTransaction{
|
||||
|
||||
private ?Item $inputItem = null;
|
||||
private ?Item $outputItem = null;
|
||||
|
||||
public function __construct(
|
||||
Player $source,
|
||||
private readonly EnchantOption $option,
|
||||
private readonly EnchantingOption $option,
|
||||
private readonly int $cost
|
||||
){
|
||||
parent::__construct($source);
|
||||
@ -51,7 +51,7 @@ class EnchantTransaction extends InventoryTransaction{
|
||||
throw new AssumptionFailedError("Expected that inputItem and outputItem are not null before validating output");
|
||||
}
|
||||
|
||||
$enchantedInput = EnchantHelper::enchantItem($this->inputItem, $this->option->getEnchantments());
|
||||
$enchantedInput = EnchantingHelper::enchantItem($this->inputItem, $this->option->getEnchantments());
|
||||
if(!$this->outputItem->equalsExact($enchantedInput)){
|
||||
throw new TransactionValidationException("Invalid output item");
|
||||
}
|
@ -45,7 +45,7 @@ use function round;
|
||||
/**
|
||||
* Helper methods used for enchanting using the enchanting table.
|
||||
*/
|
||||
final class EnchantHelper{
|
||||
final class EnchantingHelper{
|
||||
private const MAX_BOOKSHELF_COUNT = 15;
|
||||
|
||||
private function __construct(){
|
||||
@ -73,7 +73,7 @@ final class EnchantHelper{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EnchantOption[]
|
||||
* @return EnchantingOption[]
|
||||
*/
|
||||
public static function generateOptions(Position $tablePos, Item $input, int $seed) : array{
|
||||
if($input->isNull() || $input->hasEnchantments()){
|
||||
@ -89,9 +89,9 @@ final class EnchantHelper{
|
||||
$bottomRequiredLevel = max($baseRequiredLevel, $bookshelfCount * 2);
|
||||
|
||||
return [
|
||||
self::createEnchantOption($random, $input, $topRequiredLevel),
|
||||
self::createEnchantOption($random, $input, $middleRequiredLevel),
|
||||
self::createEnchantOption($random, $input, $bottomRequiredLevel),
|
||||
self::createOption($random, $input, $topRequiredLevel),
|
||||
self::createOption($random, $input, $middleRequiredLevel),
|
||||
self::createOption($random, $input, $bottomRequiredLevel),
|
||||
];
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ final class EnchantHelper{
|
||||
return $bookshelfCount;
|
||||
}
|
||||
|
||||
private static function createEnchantOption(Random $random, Item $inputItem, int $requiredXpLevel) : EnchantOption{
|
||||
private static function createOption(Random $random, Item $inputItem, int $requiredXpLevel) : EnchantingOption{
|
||||
$enchantingPower = $requiredXpLevel;
|
||||
|
||||
$enchantability = $inputItem->getEnchantability();
|
||||
@ -171,7 +171,7 @@ final class EnchantHelper{
|
||||
}
|
||||
}
|
||||
|
||||
return new EnchantOption($requiredXpLevel, self::getRandomOptionName($random), $resultEnchantments);
|
||||
return new EnchantingOption($requiredXpLevel, self::getRandomOptionName($random), $resultEnchantments);
|
||||
}
|
||||
|
||||
/**
|
@ -27,7 +27,7 @@ namespace pocketmine\item\enchantment;
|
||||
* Represents an option on the enchanting table menu.
|
||||
* If selected, all the enchantments in the option will be applied to the item.
|
||||
*/
|
||||
class EnchantOption{
|
||||
class EnchantingOption{
|
||||
|
||||
/**
|
||||
* @param EnchantmentInstance[] $enchantments
|
@ -39,8 +39,8 @@ use pocketmine\data\bedrock\EnchantmentIdMap;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\transaction\action\SlotChangeAction;
|
||||
use pocketmine\inventory\transaction\InventoryTransaction;
|
||||
use pocketmine\item\enchantment\EnchantingOption;
|
||||
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||
use pocketmine\item\enchantment\EnchantOption;
|
||||
use pocketmine\network\mcpe\cache\CreativeInventoryCache;
|
||||
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
|
||||
@ -645,7 +645,7 @@ class InventoryManager{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EnchantOption[] $options
|
||||
* @param EnchantingOption[] $options
|
||||
*/
|
||||
public function syncEnchantingTableOptions(array $options) : void{
|
||||
$protocolOptions = [];
|
||||
|
@ -29,7 +29,7 @@ use pocketmine\inventory\transaction\action\CreateItemAction;
|
||||
use pocketmine\inventory\transaction\action\DestroyItemAction;
|
||||
use pocketmine\inventory\transaction\action\DropItemAction;
|
||||
use pocketmine\inventory\transaction\CraftingTransaction;
|
||||
use pocketmine\inventory\transaction\EnchantTransaction;
|
||||
use pocketmine\inventory\transaction\EnchantingTransaction;
|
||||
use pocketmine\inventory\transaction\InventoryTransaction;
|
||||
use pocketmine\inventory\transaction\TransactionBuilder;
|
||||
use pocketmine\inventory\transaction\TransactionBuilderInventory;
|
||||
@ -289,7 +289,7 @@ class ItemStackRequestExecutor{
|
||||
* @throws ItemStackRequestProcessException
|
||||
*/
|
||||
private function assertDoingCrafting() : void{
|
||||
if(!$this->specialTransaction instanceof CraftingTransaction && !$this->specialTransaction instanceof EnchantTransaction){
|
||||
if(!$this->specialTransaction instanceof CraftingTransaction && !$this->specialTransaction instanceof EnchantingTransaction){
|
||||
if($this->specialTransaction === null){
|
||||
throw new ItemStackRequestProcessException("Expected CraftRecipe or CraftRecipeAuto action to precede this action");
|
||||
}else{
|
||||
@ -339,7 +339,7 @@ class ItemStackRequestExecutor{
|
||||
if($window instanceof EnchantInventory){
|
||||
$optionId = $this->inventoryManager->getEnchantingTableOptionIndex($action->getRecipeId());
|
||||
if($optionId !== null && ($option = $window->getOption($optionId)) !== null){
|
||||
$this->specialTransaction = new EnchantTransaction($this->player, $option, $optionId + 1);
|
||||
$this->specialTransaction = new EnchantingTransaction($this->player, $option, $optionId + 1);
|
||||
$this->setNextCreatedItem($window->getOutput($optionId));
|
||||
}
|
||||
}else{
|
||||
|
Loading…
x
Reference in New Issue
Block a user