diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86338a75..4d707b85 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,10 +13,11 @@ jobs: run: mkdir vendor - name: Download Virion Dependencies run: | - wget -O vendor/libFormAPI.phar https://poggit.pmmp.io/r/207248/libFormAPI_dev-4.phar - wget -O vendor/Commando.phar https://poggit.pmmp.io/r/162923/Commando_dev-30.phar - wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/163495/libPiggyUpdateChecker_dev-1.phar + wget -O vendor/FormsUI.phar https://poggit.pmmp.io/r/209836/FormsUI_dev-20.phar + wget -O vendor/Commando.phar https://poggit.pmmp.io/r/233076/Commando_dev-41.phar + wget -O vendor/libPiggyUpdateChecker.phar https://poggit.pmmp.io/r/211732/libPiggyUpdateChecker_dev-2.phar + wget -O vendor/Customies.phar https://poggit.pmmp.io/r/216154/Customies.phar - name: Run PHPStan - uses: paroxity/pmmp-phpstan-action@4.21.0 + uses: paroxity/pmmp-phpstan-action@5.3.0 with: phpstan-config: phpstan.neon.dist \ No newline at end of file diff --git a/.poggit.yml b/.poggit.yml index a8f2deca..2db8d592 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -1,16 +1,15 @@ --- # Poggit-CI Manifest. Open the CI at https://poggit.pmmp.io/ci/DaPigGuy/PiggyCustomEnchants branches: - master - - pmmp-4.0.0 projects: PiggyCustomEnchants: path: "" icon: "resources/PCE_Icon.png" libs: - - src: jojoe77777/FormAPI/libFormAPI - version: ^2.1.1 + - src: Vecnavium/FormsUI/FormsUI + version: ^1.1.3 - src: Paroxity/Commando/Commando - version: ^3.0.0 + version: ^3.1.0 - src: DaPigGuy/libPiggyUpdateChecker/libPiggyUpdateChecker version: ^1.0.0 lint: false diff --git a/README.md b/README.md index cff0c2fb..74b52fa5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PiggyCustomEnchants [![Poggit-CI](https://poggit.pmmp.io/shield.dl/PiggyCustomEnchants)](https://poggit.pmmp.io/p/PiggyCustomEnchants) [![Discord](https://img.shields.io/discord/330850307607363585?logo=discord)](https://discord.gg/qmnDsSD) +# PiggyCustomEnchants [![Poggit-CI](https://poggit.pmmp.io/shield.dl.total/PiggyCustomEnchants)](https://poggit.pmmp.io/p/PiggyCustomEnchants) [![Discord](https://img.shields.io/discord/330850307607363585?logo=discord)](https://discord.gg/qmnDsSD) PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP](https://github.com/pmmp/PocketMine-MP) featuring over 90 custom enchantments. @@ -13,7 +13,8 @@ PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP ## Installation & Setup 1. Install the plugin from Poggit. -2. (Optional) Configure your PiggyCE +2. Install [Customies](https://poggit.pmmp.io/p/Customies) from Poggit. +3. (Optional) Configure your PiggyCE * Enchantment rarities, max levels, names, descriptions, & chances can be configured in their respective JSON files. * `chances.json`: Allows custom chance multipliers for any reactive enchantments. * Reaction chances are calculated by `chance multiplier * enchantment level`. @@ -39,7 +40,7 @@ PiggyCustomEnchants is an open-sourced custom enchants plugin for [PocketMine-MP - Jetpack ``` * `world-damage`: Toggles world damage for explosive enchantments -3. (Optional) Install additional plugins supporting PiggyCE: +4. (Optional) Install additional plugins supporting PiggyCE: * [PiggyCrates](https://poggit.pmmp.io/p/PiggyCrates) (Official) * [PiggyCustomEnchantsShop](https://poggit.pmmp.io/p/PiggyCustomEnchantsShop) (Official) * [PCEAllyChecks](https://poggit.pmmp.io/p/PCEAllyChecks) (Official) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d6ec58a0..9624ef72 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,12 +5,11 @@ parameters: bootstrapFiles: - phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php scanDirectories: - - phar:///source/vendor/libFormAPI.phar/src/ + - phar:///source/vendor/FormsUI.phar/src/ - phar:///source/vendor/Commando.phar/src/ - phar:///source/vendor/libPiggyUpdateChecker.phar/src/ + - phar:///source/vendor/Customies.phar/src/ excludePaths: analyse: - source/vendor - checkMissingIterableValueType: false - ignoreErrors: - - "#Strict comparison using === between pocketmine\\\\inventory\\\\PlayerInventory and null will always evaluate to false.#" \ No newline at end of file + checkMissingIterableValueType: false \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 876134d9..f5003715 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,10 +1,11 @@ name: PiggyCustomEnchants main: DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants -version: 3.0.12 -api: 4.21.0 +version: 3.1.0 +api: 5.3.0 load: POSTWORLD author: DaPigGuy website: "https://github.com/DaPigGuy/PiggyCustomEnchants/" +depend: ["Customies"] permissions: piggycustomenchants: default: false diff --git a/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php b/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php index 30eb007b..b1d2739b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php +++ b/src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php @@ -230,13 +230,13 @@ public static function unregisterEnchantment(int|CustomEnchant $id): void self::$plugin->getLogger()->debug("Custom Enchantment '" . $enchant->getDisplayName() . "' unregistered with id " . $enchant->getId()); unset(self::$enchants[$id]); - $property = new ReflectionProperty(EnchantmentIdMap::class, "enchToId"); + $property = new ReflectionProperty(EnchantmentIdMap::class, "enumToId"); $property->setAccessible(true); $value = $property->getValue(EnchantmentIdMap::getInstance()); unset($value[spl_object_id(EnchantmentIdMap::getInstance()->fromId($id))]); $property->setValue(EnchantmentIdMap::getInstance(), $value); - $property = new ReflectionProperty(EnchantmentIdMap::class, "idToEnch"); + $property = new ReflectionProperty(EnchantmentIdMap::class, "idToEnum"); $property->setAccessible(true); $value = $property->getValue(EnchantmentIdMap::getInstance()); unset($value[$id]); diff --git a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php index 914c1468..87a97cfa 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/EventListener.php +++ b/src/DaPigGuy/PiggyCustomEnchants/EventListener.php @@ -11,9 +11,10 @@ use DaPigGuy\PiggyCustomEnchants\enchants\tools\DrillerEnchant; use DaPigGuy\PiggyCustomEnchants\entities\BombardmentTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\utils\ProjectileTracker; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\entity\EntityBlockChangeEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; @@ -40,7 +41,7 @@ use pocketmine\inventory\transaction\action\SlotChangeAction; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems; use pocketmine\network\mcpe\protocol\InventoryContentPacket; use pocketmine\network\mcpe\protocol\InventorySlotPacket; @@ -207,9 +208,9 @@ public function onJoin(PlayerJoinEvent $event): void if ($inventory instanceof PlayerInventory || $inventory instanceof ArmorInventory) { $holder = $inventory->getHolder(); if ($holder instanceof Player) { - if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), !$inventory instanceof ArmorInventory)) { - if ($newItem->getId() === ItemIds::AIR || $inventory instanceof ArmorInventory) foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); - if ($oldItem->getId() === ItemIds::AIR || $inventory instanceof ArmorInventory) foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); + if (!$oldItem->equals(($newItem = $inventory->getItem($slot)), false)) { + foreach ($oldItem->getEnchantments() as $oldEnchantment) ToggleableEnchantment::attemptToggle($holder, $oldItem, $oldEnchantment, $inventory, $slot, false); + foreach ($newItem->getEnchantments() as $newEnchantment) ToggleableEnchantment::attemptToggle($holder, $newItem, $newEnchantment, $inventory, $slot); } } } @@ -235,7 +236,7 @@ public function onMove(PlayerMoveEvent $event): void { $player = $event->getPlayer(); if (!Utils::shouldTakeFallDamage($player)) { - if ($player->getWorld()->getBlock($player->getPosition()->floor()->subtract(0, 1, 0))->getId() !== BlockLegacyIds::AIR && Utils::getNoFallDamageDuration($player) <= 0) { + if ($player->getWorld()->getBlock($player->getPosition()->floor()->subtract(0, 1, 0))->getTypeId() !== BlockTypeIds::AIR && Utils::getNoFallDamageDuration($player) <= 0) { Utils::setShouldTakeFallDamage($player, true); } else { Utils::increaseNoFallDamageDuration($player); @@ -302,7 +303,10 @@ public function onTransaction(InventoryTransactionEvent $event): void $actions = array_values($transaction->getActions()); if (count($actions) === 2) { foreach ($actions as $i => $action) { - if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && ($itemClickedWith = $action->getTargetItem())->getId() === ItemIds::ENCHANTED_BOOK && ($itemClicked = $action->getSourceItem())->getId() !== ItemIds::AIR && ($itemClicked->getId() !== ItemIds::ENCHANTED_BOOK || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { + if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction && + ($itemClickedWith = $action->getTargetItem())->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() && + ($itemClicked = $action->getSourceItem())->getTypeId() !== BlockTypeIds::AIR && + ($itemClicked->getTypeId() !== CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) { if (count($itemClickedWith->getEnchantments()) < 1) return; $enchantmentSuccessful = false; foreach ($itemClickedWith->getEnchantments() as $enchantment) { @@ -324,8 +328,8 @@ public function onTransaction(InventoryTransactionEvent $event): void ) || $itemClicked->getCount() !== 1 || $newLevel > $enchantmentType->getMaxLevel() || - ($itemClicked->getId() === ItemIds::ENCHANTED_BOOK && count($itemClicked->getEnchantments()) === 0) || - $itemClicked->getId() === ItemIds::BOOK + ($itemClicked->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) || + $itemClicked->getTypeId() === ItemTypeIds::BOOK ) continue; $itemClicked->addEnchantment(new EnchantmentInstance($enchantmentType, $newLevel)); if ($willChange) $enchantmentSuccessful = true; diff --git a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php index ab8c3674..e272b929 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php +++ b/src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php @@ -6,8 +6,10 @@ use CortexPE\Commando\BaseCommand; use CortexPE\Commando\PacketHooker; +use customiesdevs\customies\block\CustomiesBlockFactory; +use customiesdevs\customies\item\CustomiesItemFactory; use DaPigGuy\libPiggyUpdateChecker\libPiggyUpdateChecker; -use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian; +use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidianBlock; use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment; @@ -18,10 +20,13 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; +use DaPigGuy\PiggyCustomEnchants\items\PiggyEnchantedBookItem; use DaPigGuy\PiggyCustomEnchants\tasks\CheckDisabledEnchantsTask; use DaPigGuy\PiggyCustomEnchants\tasks\TickEnchantmentsTask; -use jojoe77777\FormAPI\Form; -use pocketmine\block\BlockFactory; +use pocketmine\block\BlockBreakInfo; +use pocketmine\block\BlockIdentifier; +use pocketmine\block\BlockTypeIds; +use pocketmine\block\BlockTypeInfo; use pocketmine\color\Color; use pocketmine\data\bedrock\EffectIdMap; use pocketmine\entity\effect\Effect; @@ -31,12 +36,13 @@ use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; use pocketmine\world\World; +use Vecnavium\FormsUI\Form; class PiggyCustomEnchants extends PluginBase { public static Effect $SLOW_FALL; - /** @var mixed[] */ + /** @var array */ private array $enchantmentData; public function onEnable(): void @@ -44,7 +50,7 @@ public function onEnable(): void foreach ( [ "Commando" => BaseCommand::class, - "libformapi" => Form::class, + "FormsUI" => Form::class, "libPiggyUpdateChecker" => libPiggyUpdateChecker::class ] as $virion => $class ) { @@ -65,9 +71,9 @@ public function onEnable(): void CustomEnchantManager::init($this); - BlockFactory::getInstance()->register(new PiggyObsidian(), true); + self::registerItemsAndBlocks(); - //TODO: Use real effect + // TODO: Use real effect self::$SLOW_FALL = new Effect("%potion.slowFalling", new Color(206, 255, 255)); EffectIdMap::getInstance()->register(27, self::$SLOW_FALL); @@ -149,4 +155,13 @@ public function areFormsEnabled(): bool { return $this->getConfig()->getNested("forms.enabled", true); } + + private static function registerItemsAndBlocks(): void + { + CustomiesItemFactory::getInstance()->registerItem(PiggyEnchantedBookItem::class, "piggyce:enchanted_book", "Enchanted Book"); + CustomiesBlockFactory::getInstance()->registerBlock( + static fn() => new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant())), + "piggyce:magmawalker_obsidian", + ); + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php new file mode 100644 index 00000000..81ec84e8 --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php @@ -0,0 +1,42 @@ + + */ + public static function getAll(): array + { + /** @var Block[] $result */ + $result = self::_registryGetAll(); + return $result; + } + + protected static function setup(): void + { + $blockFactory = CustomiesBlockFactory::getInstance(); + self::register("obsidian", $blockFactory->get("piggyce:magmawalker_obsidian")); + } +} diff --git a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php similarity index 68% rename from src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php rename to src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php index 2256fd50..3291c21f 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidian.php +++ b/src/DaPigGuy/PiggyCustomEnchants/blocks/PiggyObsidianBlock.php @@ -2,23 +2,15 @@ namespace DaPigGuy\PiggyCustomEnchants\blocks; -use pocketmine\block\Block; -use pocketmine\block\BlockBreakInfo; -use pocketmine\block\BlockIdentifier; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\Opaque; use pocketmine\block\VanillaBlocks; use pocketmine\item\Item; use pocketmine\player\Player; -class PiggyObsidian extends Block +final class PiggyObsidianBlock extends Opaque { private int $age = 0; - public function __construct() - { - parent::__construct(new BlockIdentifier(BlockLegacyIds::OBSIDIAN, 15), "Magmawalker Obsidian", BlockBreakInfo::instant()); - } - public function onScheduledUpdate(): void { if (mt_rand(0, 3) === 0 || $this->countNeighbors() < 4) { @@ -28,9 +20,13 @@ public function onScheduledUpdate(): void } } - public function onBreak(Item $item, Player $player = null): bool + public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []): bool { - $this->getPosition()->getWorld()->setBlock($this->getPosition(), VanillaBlocks::LAVA()); + $world = $this->position->getWorld(); + if (($t = $world->getTile($this->position)) !== null) { + $t->onBlockDestroyed(); + } + $world->setBlock($this->position, VanillaBlocks::LAVA()); return true; } @@ -43,7 +39,7 @@ public function countNeighbors(): int { $i = 0; foreach ($this->getAllSides() as $block) { - if ($block instanceof PiggyObsidian) { + if ($block instanceof PiggyObsidianBlock) { $i++; if ($i >= 4) return $i; } @@ -60,7 +56,7 @@ public function slightlyMelt(bool $meltNeighbors): void $this->getPosition()->getWorld()->useBreakOn($this->getPosition()); if ($meltNeighbors) { foreach ($this->getAllSides() as $block) { - if ($block instanceof PiggyObsidian) { + if ($block instanceof PiggyObsidianBlock) { $block->slightlyMelt(false); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php index b2751ecf..7bdb85b0 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/CustomEnchantsCommand.php @@ -13,15 +13,16 @@ use DaPigGuy\PiggyCustomEnchants\commands\subcommands\NBTSubCommand; use DaPigGuy\PiggyCustomEnchants\commands\subcommands\RemoveSubCommand; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class CustomEnchantsCommand extends BaseCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { @@ -44,6 +45,8 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo public function prepare(): void { + $this->setPermission("piggycustomenchants.command.ce"); + $this->registerSubCommand(new AboutSubCommand($this->plugin, "about", "Displays basic information about the plugin")); $this->registerSubCommand(new EnchantSubCommand($this->plugin, "enchant", "Apply an enchantment on an item")); $this->registerSubCommand(new InfoSubCommand($this->plugin, "info", "Get info on a custom enchant")); diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php index d0fd581d..7e36ab24 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/AboutSubCommand.php @@ -6,15 +6,16 @@ use CortexPE\Commando\BaseSubCommand; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class AboutSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php index 4e728048..66dcdc7b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/EnchantSubCommand.php @@ -9,20 +9,22 @@ use CortexPE\Commando\BaseSubCommand; use CortexPE\Commando\exception\ArgumentOrderException; use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; use pocketmine\command\CommandSender; use pocketmine\item\enchantment\EnchantmentInstance; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; use Ramsey\Uuid\Uuid; +use Vecnavium\FormsUI\CustomForm; class EnchantSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { @@ -68,7 +70,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo return; } } - if ($item->getId() === ItemIds::ENCHANTED_BOOK || $item->getId() === ItemIds::BOOK) { + if ($item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, $args["level"])); @@ -114,7 +116,7 @@ public function onRunForm(CommandSender $sender, string $aliasUsed, array $args) return; } } - if ($item->getId() === ItemIds::ENCHANTED_BOOK || $item->getId() === ItemIds::BOOK) { + if ($item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::BOOK) { $item->getNamedTag()->setString("PiggyCEBookUUID", Uuid::uuid4()->toString()); } $item->addEnchantment(new EnchantmentInstance($enchant, (int)$data[1])); diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php index 652e66f1..881c27b6 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/InfoSubCommand.php @@ -11,16 +11,17 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\CustomForm; +use Vecnavium\FormsUI\SimpleForm; class InfoSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { @@ -77,7 +78,7 @@ public function showInfo(Player $player, CustomEnchant $enchantment): void */ public function prepare(): void { - $this->setPermission("piggycustomenchants.command.ce.list"); + $this->setPermission("piggycustomenchants.command.ce.info"); $this->registerArgument(0, new RawStringArgument("enchantment", true)); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php index d9af1d68..45d138a6 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/ListSubCommand.php @@ -9,15 +9,16 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class ListSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php index 5c06d8ee..f496029b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/NBTSubCommand.php @@ -8,12 +8,13 @@ use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; class NBTSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php index d88a2fbb..b2cc1a18 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php +++ b/src/DaPigGuy/PiggyCustomEnchants/commands/subcommands/RemoveSubCommand.php @@ -10,15 +10,16 @@ use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; -use jojoe77777\FormAPI\CustomForm; use pocketmine\command\CommandSender; use pocketmine\player\Player; +use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\CustomForm; class RemoveSubCommand extends BaseSubCommand { /** @var PiggyCustomEnchants */ - protected $plugin; + protected Plugin $plugin; public function onRun(CommandSender $sender, string $aliasUsed, array $args): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php index f90a370e..9df90441 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/AntiKnockbackEnchant.php @@ -23,7 +23,7 @@ class AntiKnockbackEnchant extends ReactiveEnchantment public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { if ($event instanceof EntityDamageByEntityEvent) { - $stack = $stack > 4 ? 4 : $stack; + $stack = min($stack, 4); $event->setKnockBack($event->getKnockBack() * (4 - $stack) / (5 - $stack)); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php index 7844ec3b..23609be8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/HeavyEnchant.php @@ -11,7 +11,7 @@ use pocketmine\event\Event; use pocketmine\inventory\Inventory; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\player\Player; class HeavyEnchant extends ReactiveEnchantment @@ -31,7 +31,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $damager = $event->getDamager(); if ($damager instanceof Player) { - if ($damager->getInventory()->getItemInHand()->getId() === ItemIds::BOW) { + if ($damager->getInventory()->getItemInHand()->getTypeId() === ItemTypeIds::BOW) { $event->setModifier(-($event->getFinalDamage() * $this->extraData["absorbedDamageMultiplier"] * $level), CustomEnchantIds::HEAVY); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php index 0106351e..5cd131f8 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ReviveEnchant.php @@ -13,7 +13,6 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\Item; use pocketmine\player\Player; diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php index 534c0bf7..7534186a 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/ShrinkEnchant.php @@ -38,10 +38,10 @@ class ShrinkEnchant extends ToggleableEnchantment /** @var bool[] */ public array $shiftCache; - /** - * @return class-string[] - */ - public function getReagent(): array + /** + * @return class-string[] + */ + public function getReagent(): array { return [PlayerToggleSneakEvent::class]; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php index fbca2bc7..799815a7 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/JetpackEnchant.php @@ -15,7 +15,6 @@ use pocketmine\event\Event; use pocketmine\event\player\PlayerToggleSneakEvent; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\player\Player; use pocketmine\utils\TextFormat; @@ -32,12 +31,10 @@ class JetpackEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_BOOTS; /** @var Player[] */ - public $activeJetpacks = []; + public array $activeJetpacks = []; - /** @var array */ - public $powerRemaining; - /** @var array */ - public $lastActivated; + public array $powerRemaining; + public array $lastActivated; public function getReagent(): array { @@ -102,7 +99,6 @@ public function powerActiveJetpack(Player $player, bool $power = true): void if ($power) { if (!isset($this->powerRemaining[$player->getName()])) { $this->powerRemaining[$player->getName()] = $this->extraData["power"]; - $this->activeJetpacks[$player->getName()] = $player; } else { $this->powerRemaining[$player->getName()] += (time() - $this->lastActivated[$player->getName()]) * $this->extraData["rechargeAmount"]; if ($this->powerRemaining[$player->getName()] > $this->extraData["power"]) $this->powerRemaining[$player->getName()] = $this->extraData["power"]; @@ -110,8 +106,8 @@ public function powerActiveJetpack(Player $player, bool $power = true): void $player->sendTip(TextFormat::RED . "Jetpack needs to charge up to " . $this->extraData["enableAmount"] . " before it can be re-enabled. (" . round(abs($this->powerRemaining[$player->getName()]), 2) . " / " . $this->extraData["power"] . ")"); return; } - $this->activeJetpacks[$player->getName()] = $player; } + $this->activeJetpacks[$player->getName()] = $player; } else { unset($this->activeJetpacks[$player->getName()]); $this->lastActivated[$player->getName()] = time(); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php index e7f14da0..3f79be77 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/boots/MagmaWalkerEnchant.php @@ -4,10 +4,14 @@ namespace DaPigGuy\PiggyCustomEnchants\enchants\armor\boots; +use DaPigGuy\PiggyCustomEnchants\blocks\CustomBlocksRegistry; use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\Block; +use pocketmine\block\BlockBreakInfo; +use pocketmine\block\BlockIdentifier; +use pocketmine\block\BlockTypeIds; +use pocketmine\block\BlockTypeInfo; use pocketmine\block\Lava; use pocketmine\event\Event; use pocketmine\event\player\PlayerMoveEvent; @@ -44,9 +48,9 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo for ($x = -$radius; $x <= $radius; $x++) { for ($z = -$radius; $z <= $radius; $z++) { $b = $world->getBlock($player->getPosition()->add($x, -1, $z)); - if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getId() === BlockLegacyIds::AIR) { - if ($b instanceof Lava && $b->getMeta() === 0) { - $world->setBlock($b->getPosition()->asVector3(), BlockFactory::getInstance()->get(BlockLegacyIds::OBSIDIAN, 15)); + if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getTypeId() === BlockTypeIds::AIR) { + if ($b instanceof Lava && $b->isSource()) { + $world->setBlock($b->getPosition()->asVector3(), CustomBlocksRegistry::OBSIDIAN()); } } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php index f6ad9437..959b29f5 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ChickenEnchant.php @@ -9,10 +9,10 @@ use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; use pocketmine\item\VanillaItems; use pocketmine\player\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\format\io\GlobalItemDataHandlers; class ChickenEnchant extends TickingEnchantment { @@ -36,7 +36,11 @@ public function tick(Player $player, Item $item, Inventory $inventory, int $slot } $drop = array_rand($drops); $drop = explode(":", $drops[$drop]); - $item = count($drop) < 3 ? VanillaItems::GOLD_INGOT() : ItemFactory::getInstance()->get((int)$drop[0], (int)$drop[1], (int)$drop[2]); + + $itemify = GlobalItemDataHandlers::getUpgrader()->upgradeItemTypeDataInt((int)$drop[0], (int)$drop[1], (int)$drop[2], null); + $itemify = GlobalItemDataHandlers::getDeserializer()->deserializeStack($itemify); + + $item = count($drop) < 3 ? VanillaItems::GOLD_INGOT() : $itemify; $vowels = ["a", "e", "i", "o", "u"]; $player->getWorld()->dropItem($player->getPosition(), $item, $player->getDirectionVector()->multiply(-0.4)); $player->sendTip(TextFormat::GREEN . "You have laid a" . (in_array(strtolower($item->getName()[0]), $vowels) ? "n " : " ") . $item->getName() . "..."); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php index a83ba72e..0fe4ffed 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/chestplate/ParachuteEnchant.php @@ -11,7 +11,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment; use DaPigGuy\PiggyCustomEnchants\enchants\traits\ToggleTrait; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\entity\effect\EffectInstance; use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; @@ -34,7 +34,7 @@ public function tick(Player $player, Item $item, Inventory $inventory, int $slot if ($this->isInAir($player) && !$player->getAllowFlight() && !$player->canClimbWalls() && (($enchantInstance = $player->getArmorInventory()->getBoots()->getEnchantment(CustomEnchantManager::getEnchantment(CustomEnchantIds::JETPACK))) === null || !($enchant = $enchantInstance->getType()) instanceof JetpackEnchant || !$enchant->hasActiveJetpack($player))) { $player->getEffects()->add(new EffectInstance(PiggyCustomEnchants::$SLOW_FALL, 2147483647, 1, false)); } elseif ($player->getEffects()->get(PiggyCustomEnchants::$SLOW_FALL) !== null) { - if ($this->isInAir($player) || $player->getWorld()->getBlock($player->getPosition()->subtract(0, 1, 0))->getId() !== BlockLegacyIds::AIR) $player->getEffects()->remove(PiggyCustomEnchants::$SLOW_FALL); + if ($this->isInAir($player) || $player->getWorld()->getBlock($player->getPosition()->subtract(0, 1, 0))->getTypeId() !== BlockTypeIds::AIR) $player->getEffects()->remove(PiggyCustomEnchants::$SLOW_FALL); } $player->resetFallDistance(); } @@ -49,7 +49,7 @@ public function toggle(Player $player, Item $item, Inventory $inventory, int $sl public function isInAir(Player $player): bool { for ($y = 1; $y <= 5; $y++) { - if ($player->getWorld()->getBlock($player->getPosition()->subtract(0, $y, 0))->getId() !== BlockLegacyIds::AIR) return false; + if ($player->getWorld()->getBlock($player->getPosition()->subtract(0, $y, 0))->getTypeId() !== BlockTypeIds::AIR) return false; } return true; } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php index 060b6856..56910036 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/armor/helmet/ImplantsEnchant.php @@ -12,7 +12,6 @@ use pocketmine\event\Event; use pocketmine\event\player\PlayerMoveEvent; use pocketmine\inventory\Inventory; -use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\player\Player; use pocketmine\scheduler\ClosureTask; @@ -25,7 +24,7 @@ class ImplantsEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_HELMET; /** @var ClosureTask[] */ - public static $tasks; + public static array $tasks; public function getReagent(): array { @@ -52,7 +51,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo unset(self::$tasks[$player->getName()]); return; } - $player->setAirSupplyTicks($player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"]) > $player->getMaxAirSupplyTicks() ? $player->getMaxAirSupplyTicks() : $player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"])); + $player->setAirSupplyTicks(min($player->getAirSupplyTicks() + ($enchantment->getLevel() * $this->extraData["airTicksReplenishAmountMultiplier"]), $player->getMaxAirSupplyTicks())); } else { self::$tasks[$player->getName()]->getHandler()->cancel(); unset(self::$tasks[$player->getName()]); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php index 3d4e5927..5ffb1c7d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/miscellaneous/AutoRepairEnchant.php @@ -34,8 +34,8 @@ public function getDefaultExtraData(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { - if (!$item instanceof Durable || $item->getMeta() === 0) return; - $newDir = $item->getMeta() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); + if (!$item instanceof Durable || $item->getDamage() === 0) return; + $newDir = $item->getDamage() - ((int)$this->extraData["baseRepair"] + ((int)$this->extraData["repairMultiplier"] * $level)); if ($newDir < 0) { $item->setDamage(0); } else { diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php index 2d26525d..b506c782 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/axes/LumberjackEnchant.php @@ -7,7 +7,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\miscellaneous\RecursiveEnchant; use pocketmine\block\Block; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; @@ -21,6 +21,8 @@ class LumberjackEnchant extends RecursiveEnchant public int $itemType = CustomEnchant::ITEM_TYPE_AXE; + private const LOG_TYPES = [BlockTypeIds::ACACIA_LOG, BlockTypeIds::BIRCH_LOG, BlockTypeIds::CHERRY_LOG, BlockTypeIds::OAK_LOG, BlockTypeIds::DARK_OAK_LOG, BlockTypeIds::MANGROVE_LOG, BlockTypeIds::JUNGLE_LOG, BlockTypeIds::SPRUCE_LOG]; + public function getReagent(): array { return [BlockBreakEvent::class]; @@ -36,7 +38,7 @@ public function safeReact(Player $player, Item $item, Inventory $inventory, int if ($event instanceof BlockBreakEvent) { $block = $event->getBlock(); if ($player->isSneaking()) { - if ($block->getId() == BlockLegacyIds::LOG || $block->getId() == BlockLegacyIds::LOG2) { + if (in_array($block->getTypeId(), self::LOG_TYPES)) { $this->breakTree($block, $player); } } @@ -47,13 +49,9 @@ public function breakTree(Block $block, Player $player, int $mined = 0): void { $item = $player->getInventory()->getItemInHand(); for ($i = 0; $i <= 5; $i++) { - if ($mined > $this->extraData["limit"]) { - break; - } + if ($mined > $this->extraData["limit"]) break; $side = $block->getSide($i); - if ($side->getId() !== BlockLegacyIds::LOG && $side->getId() !== BlockLegacyIds::LOG2) { - continue; - } + if (!in_array($side->getTypeId(), self::LOG_TYPES)) continue; $player->getWorld()->useBreakOn($side->getPosition(), $item, $player); $mined++; $this->breakTree($side, $player, $mined); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php index e3bb6ca2..9f21550b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/hoe/FertilizerEnchant.php @@ -6,7 +6,7 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\miscellaneous\RecursiveEnchant; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; use pocketmine\event\Event; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\inventory\Inventory; @@ -37,12 +37,12 @@ public function safeReact(Player $player, Item $item, Inventory $inventory, int { if ($event instanceof PlayerInteractEvent) { $block = $event->getBlock(); - if ($block->getId() === BlockLegacyIds::GRASS || ($block->getId() === BlockLegacyIds::DIRT && $block->getMeta() === 0)) { + if ($block->getTypeId() === BlockTypeIds::GRASS || ($block->getTypeId() === BlockTypeIds::DIRT && $block->getStateId() === 0)) { $radius = $level * $this->extraData["radiusMultiplier"]; for ($x = -$radius; $x <= $radius; $x++) { for ($z = -$radius; $z <= $radius; $z++) { $newBlock = $block->getPosition()->getWorld()->getBlock($block->getPosition()->add($x, 0, $z)); - if ($newBlock->getId() === BlockLegacyIds::GRASS || ($newBlock->getId() === BlockLegacyIds::DIRT && $newBlock->getMeta() === 0)) { + if ($newBlock->getTypeId() === BlockTypeIds::GRASS || ($newBlock->getTypeId() === BlockTypeIds::DIRT && $newBlock->getStateId() === 0)) { $block->getPosition()->getWorld()->useItemOn($newBlock->getPosition(), $item, Facing::UP, $newBlock->getPosition(), $player); } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php index 9d51de8c..7340f852 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/tools/pickaxe/JackpotEnchant.php @@ -6,8 +6,8 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; +use pocketmine\block\BlockTypeIds; +use pocketmine\block\VanillaBlocks; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\Event; use pocketmine\inventory\Inventory; @@ -24,11 +24,11 @@ class JackpotEnchant extends ReactiveEnchantment public int $itemType = CustomEnchant::ITEM_TYPE_PICKAXE; const ORE_TIERS = [ - BlockLegacyIds::COAL_ORE, - BlockLegacyIds::IRON_ORE, - BlockLegacyIds::GOLD_ORE, - BlockLegacyIds::DIAMOND_ORE, - BlockLegacyIds::EMERALD_ORE + BlockTypeIds::COAL_ORE, + BlockTypeIds::IRON_ORE, + BlockTypeIds::GOLD_ORE, + BlockTypeIds::DIAMOND_ORE, + BlockTypeIds::EMERALD_ORE ]; public function getReagent(): array @@ -39,7 +39,7 @@ public function getReagent(): array public function react(Player $player, Item $item, Inventory $inventory, int $slot, Event $event, int $level, int $stack): void { if ($event instanceof BlockBreakEvent) { - $key = array_search($event->getBlock()->getId(), self::ORE_TIERS, true); + $key = array_search($event->getBlock()->getTypeId(), self::ORE_TIERS, true); if ($key !== false) { if (isset(self::ORE_TIERS[$key + 1])) { $drops = $event->getDrops(); @@ -48,7 +48,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo unset($drops[$k]); } } - $drops = array_merge($drops, BlockFactory::getInstance()->get(self::ORE_TIERS[$key + 1], 0)->getDrops(VanillaItems::DIAMOND_PICKAXE())); + $drops = array_merge($drops, $this->getOreDrops(self::ORE_TIERS[$key + 1])); $event->setDrops($drops); } } @@ -59,4 +59,17 @@ public function getPriority(): int { return 3; } + + public function getOreDrops(int $tier): array + { + $drop = match ($tier) { + BlockTypeIds::COAL_ORE => VanillaBlocks::COAL_ORE(), + BlockTypeIds::IRON_ORE => VanillaBlocks::IRON_ORE(), + BlockTypeIds::GOLD_ORE => VanillaBlocks::GOLD_ORE(), + BlockTypeIds::DIAMOND_ORE => VanillaBlocks::DIAMOND_ORE(), + BlockTypeIds::EMERALD_ORE => VanillaBlocks::EMERALD_ORE(), + default => VanillaBlocks::AIR(), + }; + return $drop->getDrops(VanillaItems::DIAMOND_PICKAXE()); + } } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php index 537f2613..b7fff41d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/traits/ReactiveTrait.php @@ -23,7 +23,7 @@ trait ReactiveTrait protected PiggyCustomEnchants $plugin; /** @var float[] */ - public $chanceMultiplier; + public array $chanceMultiplier; public function canReact(): bool { @@ -94,7 +94,7 @@ public function shouldReactToDamaged(): bool public static function attemptReaction(Player $player, Event $event): void { - if ($player->getInventory() === null) return; + if (!$player->spawned) return; if ($event instanceof EntityDamageByChildEntityEvent || $event instanceof ProjectileHitBlockEvent) { $projectile = $event instanceof EntityDamageByEntityEvent ? $event->getChild() : $event->getEntity(); if ($projectile instanceof Projectile && ProjectileTracker::isTrackedProjectile($projectile)) { diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php index 2f97f2ca..0304a569 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmingEnchant.php @@ -22,7 +22,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $entity = $event->getEntity(); if ($entity instanceof Player) { - if (count($contents = $entity->getInventory()->getContents(false)) > 0) { + if (count($contents = $entity->getInventory()->getContents()) > 0) { $item = $contents[array_rand($contents)]; $entity->getInventory()->removeItem($item); $entity->dropItem($item); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php index a8b9f604..4d0c6859 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/DisarmorEnchant.php @@ -21,7 +21,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo if ($event instanceof EntityDamageByEntityEvent) { $entity = $event->getEntity(); if ($entity instanceof Player) { - if (count($armorContents = $entity->getArmorInventory()->getContents(false)) > 0) { + if (count($armorContents = $entity->getArmorInventory()->getContents()) > 0) { $item = $armorContents[array_rand($armorContents)]; $entity->getArmorInventory()->removeItem($item); $entity->dropItem($item); diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php index 7e19493e..c1a9abc0 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/HallucinationEnchant.php @@ -5,8 +5,6 @@ namespace DaPigGuy\PiggyCustomEnchants\enchants\weapons; use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment; -use pocketmine\block\BlockFactory; -use pocketmine\block\BlockLegacyIds; use pocketmine\block\tile\Sign; use pocketmine\block\tile\Tile; use pocketmine\block\VanillaBlocks; @@ -16,7 +14,8 @@ use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\mcpe\convert\RuntimeBlockMapping; +use pocketmine\network\mcpe\convert\TypeConverter; +use pocketmine\network\mcpe\NetworkBroadcastUtils; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer; use pocketmine\network\mcpe\protocol\types\BlockPosition; @@ -32,8 +31,7 @@ class HallucinationEnchant extends ReactiveEnchantment public string $name = "Hallucination"; public int $rarity = Rarity::MYTHIC; - /** @var NetworkNbtSerializer */ - public $nbtWriter = null; + public ?NetworkNbtSerializer $nbtWriter = null; /** @var bool[] */ public static array $hallucinating; @@ -54,7 +52,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo $block = VanillaBlocks::BEDROCK(); if ($position->equals($originalPosition)) $block = VanillaBlocks::LAVA(); if ($position->equals($originalPosition->add(0, 1, 0))) { - $block = BlockFactory::getInstance()->get(BlockLegacyIds::WALL_SIGN, 2); + $block = VanillaBlocks::OAK_WALL_SIGN(); if ($this->nbtWriter === null) $this->nbtWriter = new NetworkNbtSerializer(); $packets[] = BlockActorDataPacket::create(BlockPosition::fromVector3($position->floor()), new CacheableNbt( CompoundTag::create()-> @@ -68,11 +66,12 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo ]) ))); } - $packets[] = UpdateBlockPacket::create(BlockPosition::fromVector3($position->floor()), RuntimeBlockMapping::getInstance()->toRuntimeId($block->getFullId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL); + $blockTranslator = TypeConverter::getInstance()->getBlockTranslator(); + $packets[] = UpdateBlockPacket::create(BlockPosition::fromVector3($position->floor()), $blockTranslator->internalIdToNetworkId($block->getStateId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL); } } } - $entity->getServer()->broadcastPackets([$entity], $packets); + NetworkBroadcastUtils::broadcastPackets([$entity], $packets); })), 1); $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function () use ($originalPosition, $entity, $task): void { $task->getHandler()->cancel(); @@ -84,7 +83,7 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo } } } - $entity->getServer()->broadcastPackets([$entity], $entity->getWorld()->createBlockUpdatePackets($blocks)); + NetworkBroadcastUtils::broadcastPackets([$entity], $entity->getWorld()->createBlockUpdatePackets($blocks)); unset(self::$hallucinating[$entity->getName()]); }), 20 * 60); } diff --git a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php index c318cfe4..c0ffd5fc 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php +++ b/src/DaPigGuy/PiggyCustomEnchants/enchants/weapons/bows/BountyHunterEnchant.php @@ -11,8 +11,7 @@ use pocketmine\inventory\Inventory; use pocketmine\item\enchantment\Rarity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\VanillaItems; use pocketmine\player\Player; class BountyHunterEnchant extends ReactiveEnchantment @@ -37,29 +36,30 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo { if ($event instanceof EntityDamageByChildEntityEvent) { $bountyDrop = $this->getBounty(); - $player->getInventory()->addItem(ItemFactory::getInstance()->get($bountyDrop, 0, mt_rand(1, $this->extraData["base"] + $level * $this->extraData["multiplier"]))); + $bountyDrop->setCount(mt_rand(1, $this->extraData["base"] + $level * $this->extraData["multiplier"])); + $player->getInventory()->addItem($bountyDrop); } } - public function getBounty(): int + public function getBounty(): Item { $random = mt_rand(0, 75); $currentChance = 2.5; if ($random < $currentChance) { - return ItemIds::EMERALD; + return VanillaItems::EMERALD(); } $currentChance += 5; if ($random < $currentChance) { - return ItemIds::DIAMOND; + return VanillaItems::DIAMOND(); } $currentChance += 15; if ($random < $currentChance) { - return ItemIds::GOLD_INGOT; + return VanillaItems::GOLD_INGOT(); } $currentChance += 27.5; if ($random < $currentChance) { - return ItemIds::IRON_INGOT; + return VanillaItems::IRON_INGOT(); } - return ItemIds::COAL; + return VanillaItems::COAL(); } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php index f54e1be6..f6cfdc5b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PigProjectile.php @@ -4,14 +4,15 @@ namespace DaPigGuy\PiggyCustomEnchants\entities; +use pocketmine\block\BlockTypeIds; use pocketmine\entity\Attribute; use pocketmine\entity\Entity; use pocketmine\entity\EntitySizeInfo; use pocketmine\entity\Location; use pocketmine\entity\object\ItemEntity; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; +use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\AddActorPacket; @@ -27,22 +28,17 @@ class PigProjectile extends PiggyProjectile * @const array */ const PORK_LEVELS = [ - //level => [damage, dinnerbone, zombie, drop id, drop name] - 1 => [1, false, false, ItemIds::AIR, ""], - 2 => [2, false, false, ItemIds::RAW_PORKCHOP, "Mysterious Raw Pork"], - 3 => [2, false, false, ItemIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], - 4 => [3, true, false, ItemIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], - 5 => [5, false, true, ItemIds::ROTTEN_FLESH, "Mysterious Rotten Pork"], - 6 => [6, true, true, ItemIds::ROTTEN_FLESH, "Mysterious Rotten Pork"] + // level => [damage, dinnerbone, zombie, drop id, drop name] + 1 => [1, false, false, BlockTypeIds::AIR, ""], + 2 => [2, false, false, ItemTypeIds::RAW_PORKCHOP, "Mysterious Raw Pork"], + 3 => [2, false, false, ItemTypeIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 4 => [3, true, false, ItemTypeIds::COOKED_PORKCHOP, "Mysterious Cooked Pork"], + 5 => [5, false, true, ItemTypeIds::ROTTEN_FLESH, "Mysterious Rotten Pork"], + 6 => [6, true, true, ItemTypeIds::ROTTEN_FLESH, "Mysterious Rotten Pork"] ]; /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 1.5; + protected float $damage = 1.5; private int $porkLevel; private bool $zombie; @@ -96,9 +92,15 @@ public function isZombie(): bool public function getDrops(): array { $values = self::PORK_LEVELS[$this->getPorkLevel()]; - return [ - ItemFactory::getInstance()->get($values[3], 0, 1)->setCustomName(TextFormat::RESET . TextFormat::WHITE . $values[4]) - ]; + + $drop = match ($values[3]) { + ItemTypeIds::RAW_PORKCHOP => VanillaItems::RAW_PORKCHOP(), + ItemTypeIds::COOKED_PORKCHOP => VanillaItems::COOKED_PORKCHOP(), + ItemTypeIds::ROTTEN_FLESH => VanillaItems::ROTTEN_FLESH(), + default => VanillaItems::AIR(), + }; + + return [$drop->setCount(1)->setCustomName(TextFormat::RESET . TextFormat::WHITE . $values[4])]; } protected function sendSpawnPacket(Player $player): void diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php index e9fbdfe4..ddde3224 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyFireball.php @@ -16,13 +16,7 @@ class PiggyFireball extends PiggyProjectile { - /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 5; + protected float $damage = 5; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php index 470e2091..198c8883 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyLightning.php @@ -54,4 +54,14 @@ protected function getInitialSizeInfo(): EntitySizeInfo { return new EntitySizeInfo(1.8, 0.3); } + + protected function getInitialDragMultiplier(): float + { + return 0; + } + + protected function getInitialGravity(): float + { + return 0; + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php index 4694a95e..0c03c579 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyProjectile.php @@ -17,4 +17,14 @@ public function canSaveWithChunk(): bool { return false; } + + protected function getInitialDragMultiplier(): float + { + return 0.01; + } + + protected function getInitialGravity(): float + { + return 0.05; + } } \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php index b417cad9..ad6f185b 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyTNT.php @@ -7,7 +7,7 @@ use DaPigGuy\PiggyCustomEnchants\utils\PiggyExplosion; use pocketmine\entity\Location; use pocketmine\entity\object\PrimedTNT; -use pocketmine\event\entity\ExplosionPrimeEvent; +use pocketmine\event\entity\EntityPreExplodeEvent; use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\world\Position; @@ -28,11 +28,11 @@ public function explode(): void if (!$ownerEntity instanceof Player) { return; } - $ev = new ExplosionPrimeEvent($this, 4); + $ev = new EntityPreExplodeEvent($this, 4); $ev->setBlockBreaking($this->worldDamage); $ev->call(); if (!$ev->isCancelled()) { - $explosion = new PiggyExplosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->location->world), $ev->getForce(), $ownerEntity); + $explosion = new PiggyExplosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->location->world), $ev->getRadius(), $ownerEntity); if ($ev->isBlockBreaking()) $explosion->explodeA(); $explosion->explodeB(); } diff --git a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php index a2a56a2f..2135426a 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php +++ b/src/DaPigGuy/PiggyCustomEnchants/entities/PiggyWitherSkull.php @@ -16,13 +16,7 @@ class PiggyWitherSkull extends PiggyProjectile { - /** @var float */ - protected $drag = 0.01; - /** @var float */ - protected $gravity = 0.05; - - /** @var float */ - protected $damage = 0; + protected float $damage = 0; public function onHitEntity(Entity $entityHit, RayTraceResult $hitResult): void { diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php b/src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php new file mode 100644 index 00000000..75b29467 --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/items/CustomItemsRegistry.php @@ -0,0 +1,44 @@ + + */ + public static function getAll(): array + { + /** @var Item[] $result */ + $result = self::_registryGetAll(); + return $result; + } + + protected static function setup(): void + { + $itemFactory = CustomiesItemFactory::getInstance(); + self::register("enchanted_book", $itemFactory->get("piggyce:enchanted_book")); + } +} \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php b/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php new file mode 100644 index 00000000..efd52a6b --- /dev/null +++ b/src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php @@ -0,0 +1,24 @@ +initComponent("book_enchanted"); + } + + public function getMaxStackSize(): int + { + return 1; + } +} \ No newline at end of file diff --git a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php index 48e7ab51..e5a3b8cc 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php +++ b/src/DaPigGuy/PiggyCustomEnchants/tasks/TickEnchantmentsTask.php @@ -6,11 +6,11 @@ use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant; use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants; use DaPigGuy\PiggyCustomEnchants\utils\Utils; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\scheduler\Task; use pocketmine\Server; use pocketmine\utils\TextFormat; @@ -27,9 +27,9 @@ public function onRun(): void foreach ($this->plugin->getServer()->getOnlinePlayers() as $player) { $successfulEnchantments = []; foreach ($player->getInventory()->getContents() as $slot => $content) { - if ($content->getId() === ItemIds::BOOK) { + if ($content->getTypeId() === ItemTypeIds::BOOK) { if (count($content->getEnchantments()) > 0) { - $enchantedBook = ItemFactory::getInstance()->get(ItemIds::ENCHANTED_BOOK, 0, $content->getCount(), $content->getNamedTag()); + $enchantedBook = CustomItemsRegistry::ENCHANTED_BOOK()->setNamedTag($content->getNamedTag())->setCount($content->getCount()); $enchantedBook->setCustomName(TextFormat::RESET . TextFormat::YELLOW . "Enchanted Book" . TextFormat::RESET); $enchantedBook->addEnchantment(...$content->getEnchantments()); $player->getInventory()->setItem($slot, $enchantedBook); diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php b/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php index 2d02aebe..1e8d8bad 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/AllyChecks.php @@ -11,7 +11,7 @@ class AllyChecks { - /** @var mixed[][] */ + /** @var array[] */ private static array $checks = []; /** diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php b/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php index 5e5a4a62..f7280608 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/PiggyExplosion.php @@ -21,15 +21,15 @@ class PiggyExplosion extends Explosion { - public function __construct(Position $center, float $size, protected Player $player, protected bool $entityDamage = true) + public function __construct(Position $center, float $radius, protected Player $player, protected bool $entityDamage = true) { - parent::__construct($center, $size, $this->player); + parent::__construct($center, $radius, $this->player); } public function explodeB(): bool { $source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor(); - $yield = (1 / $this->size) * 100; + $yield = (1 / $this->radius) * 100; $ev = new EntityExplodeEvent($this->player, $this->source, $this->affectedBlocks, $yield); $ev->call(); @@ -39,7 +39,7 @@ public function explodeB(): bool $this->affectedBlocks = $ev->getBlockList(); } - $explosionSize = $this->size * 2; + $explosionSize = $this->radius * 2; $minX = (int)floor($this->source->x - $explosionSize - 1); $maxX = (int)ceil($this->source->x + $explosionSize + 1); $minY = (int)floor($this->source->y - $explosionSize - 1); diff --git a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php index ea4fd11d..2e7b694d 100644 --- a/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php +++ b/src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php @@ -11,8 +11,8 @@ use DaPigGuy\PiggyCustomEnchants\entities\PiggyFireball; use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull; use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile; +use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry; use InvalidArgumentException; -use jojoe77777\FormAPI\SimpleForm; use pocketmine\entity\Location; use pocketmine\entity\projectile\Arrow; use pocketmine\entity\projectile\Projectile; @@ -26,7 +26,7 @@ use pocketmine\item\enchantment\Rarity; use pocketmine\item\Hoe; use pocketmine\item\Item; -use pocketmine\item\ItemIds; +use pocketmine\item\ItemTypeIds; use pocketmine\item\Pickaxe; use pocketmine\item\Shears; use pocketmine\item\Shovel; @@ -37,6 +37,7 @@ use pocketmine\player\Player; use pocketmine\plugin\PluginDescription; use pocketmine\utils\TextFormat; +use Vecnavium\FormsUI\SimpleForm; class Utils { @@ -129,7 +130,7 @@ public static function isBoots(Item $item): bool public static function itemMatchesItemType(Item $item, int $itemType): bool { - if ($item->getId() === ItemIds::BOOK || $item->getId() === ItemIds::ENCHANTED_BOOK) return true; + if ($item->getTypeId() === ItemTypeIds::BOOK || $item->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId()) return true; return match ($itemType) { CustomEnchant::ITEM_TYPE_GLOBAL => true, CustomEnchant::ITEM_TYPE_DAMAGEABLE => $item instanceof Durable, @@ -141,7 +142,8 @@ public static function itemMatchesItemType(Item $item, int $itemType): bool CustomEnchant::ITEM_TYPE_AXE => $item instanceof Axe, CustomEnchant::ITEM_TYPE_SHOVEL => $item instanceof Shovel, CustomEnchant::ITEM_TYPE_HOE => $item instanceof Hoe, - CustomEnchant::ITEM_TYPE_ARMOR => $item instanceof Armor || $item->getId() === ItemIds::ELYTRA, + // TODO: $item->getTypeId() === ItemTypeIds::ELYTRA + CustomEnchant::ITEM_TYPE_ARMOR => $item instanceof Armor, CustomEnchant::ITEM_TYPE_HELMET => self::isHelmet($item), CustomEnchant::ITEM_TYPE_CHESTPLATE => self::isChestplate($item), CustomEnchant::ITEM_TYPE_LEGGINGS => self::isLeggings($item),