Skip to content

Commit

Permalink
Use Customies for enchant book / magmawalker obsidian
Browse files Browse the repository at this point in the history
  • Loading branch information
Aericio committed Sep 29, 2023
1 parent e88a082 commit 60cde4b
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 82 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
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/216831/Commando_dev-34.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@5.3.0
with:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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`.
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ api: 5.3.0
load: POSTWORLD
author: DaPigGuy
website: "https://github.com/DaPigGuy/PiggyCustomEnchants/"
depend: ["Customies"]
permissions:
piggycustomenchants:
default: false
Expand Down
8 changes: 4 additions & 4 deletions src/DaPigGuy/PiggyCustomEnchants/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use DaPigGuy\PiggyCustomEnchants\enchants\tools\DrillerEnchant;
use DaPigGuy\PiggyCustomEnchants\entities\BombardmentTNT;
use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT;
use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook;
use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry;
use DaPigGuy\PiggyCustomEnchants\utils\ProjectileTracker;
use DaPigGuy\PiggyCustomEnchants\utils\Utils;
use pocketmine\block\BlockTypeIds;
Expand Down Expand Up @@ -304,9 +304,9 @@ public function onTransaction(InventoryTransactionEvent $event): void
if (count($actions) === 2) {
foreach ($actions as $i => $action) {
if ($action instanceof SlotChangeAction && ($otherAction = $actions[($i + 1) % 2]) instanceof SlotChangeAction &&
($itemClickedWith = $action->getTargetItem())->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() &&
($itemClickedWith = $action->getTargetItem())->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() &&
($itemClicked = $action->getSourceItem())->getTypeId() !== BlockTypeIds::AIR &&
($itemClicked->getTypeId() !== EnchantedBook::ENCHANTED_BOOK()->getTypeId() || count($itemClicked->getEnchantments()) >= count($itemClickedWith->getEnchantments()))) {
($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) {
Expand All @@ -328,7 +328,7 @@ public function onTransaction(InventoryTransactionEvent $event): void
) ||
$itemClicked->getCount() !== 1 ||
$newLevel > $enchantmentType->getMaxLevel() ||
($itemClicked->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) ||
($itemClicked->getTypeId() === CustomItemsRegistry::ENCHANTED_BOOK()->getTypeId() && count($itemClicked->getEnchantments()) === 0) ||
$itemClicked->getTypeId() === ItemTypeIds::BOOK
) continue;
$itemClicked->addEnchantment(new EnchantmentInstance($enchantmentType, $newLevel));
Expand Down
52 changes: 13 additions & 39 deletions src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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\PiggyObsidianBlock;
use DaPigGuy\PiggyCustomEnchants\commands\CustomEnchantsCommand;
use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant;
use DaPigGuy\PiggyCustomEnchants\enchants\ToggleableEnchantment;
Expand All @@ -17,25 +20,21 @@
use DaPigGuy\PiggyCustomEnchants\entities\PiggyTNT;
use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull;
use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile;
use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook;
use DaPigGuy\PiggyCustomEnchants\items\PiggyEnchantedBookItem;
use DaPigGuy\PiggyCustomEnchants\tasks\CheckDisabledEnchantsTask;
use DaPigGuy\PiggyCustomEnchants\tasks\TickEnchantmentsTask;
use pocketmine\block\Block;
use pocketmine\block\RuntimeBlockStateRegistry;
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\data\bedrock\item\ItemTypeNames;
use pocketmine\data\bedrock\item\SavedItemData;
use pocketmine\entity\effect\Effect;
use pocketmine\entity\EntityDataHelper;
use pocketmine\entity\EntityFactory;
use pocketmine\item\Item;
use pocketmine\item\StringToItemParser;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\world\format\io\GlobalBlockStateHandlers;
use pocketmine\world\format\io\GlobalItemDataHandlers;
use pocketmine\world\World;
use Vecnavium\FormsUI\Form;

Expand Down Expand Up @@ -159,35 +158,10 @@ public function areFormsEnabled(): bool

private static function registerItemsAndBlocks(): void
{
self::registerItem(ItemTypeNames::ENCHANTED_BOOK, EnchantedBook::ENCHANTED_BOOK(), ["enchanted_book"]);
// self::registerBlock(BlockTypeNames::OBSIDIAN, PiggyObsidian::PIGGY_OBSIDIAN(), ["piggy_obsidian"]);
}

/**
* @param string[] $stringToItemParserNames
*/
private static function registerBlock(string $id, Block $block, array $stringToItemParserNames): void
{
RuntimeBlockStateRegistry::getInstance()->register($block);

GlobalBlockStateHandlers::getDeserializer()->mapSimple($id, fn() => clone $block);
GlobalBlockStateHandlers::getSerializer()->mapSimple($block, $id);

foreach ($stringToItemParserNames as $name) {
StringToItemParser::getInstance()->registerBlock($name, fn() => clone $block);
}
}

/**
* @param string[] $stringToItemParserNames
*/
private static function registerItem(string $id, Item $item, array $stringToItemParserNames): void
{
GlobalItemDataHandlers::getDeserializer()->map($id, fn() => clone $item);
GlobalItemDataHandlers::getSerializer()->map($item, fn() => new SavedItemData($id));

foreach ($stringToItemParserNames as $name) {
StringToItemParser::getInstance()->register($name, fn() => clone $item);
}
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",
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

namespace DaPigGuy\PiggyCustomEnchants\blocks;

use customiesdevs\customies\block\CustomiesBlockFactory;
use pocketmine\block\Block;
use pocketmine\block\BlockBreakInfo;
use pocketmine\block\BlockIdentifier;
use pocketmine\block\BlockTypeIds;
use pocketmine\block\BlockTypeInfo;
use pocketmine\utils\CloningRegistryTrait;

/**
* @method static PiggyObsidianBlock PIGGY_OBSIDIAN()
* @method static PiggyObsidianBlock OBSIDIAN()
*/
final class PiggyObsidian
final class CustomBlocksRegistry
{
use CloningRegistryTrait;

Expand All @@ -39,6 +36,7 @@ public static function getAll(): array

protected static function setup(): void
{
self::register("piggy_obsidian", new PiggyObsidianBlock(new BlockIdentifier(BlockTypeIds::newId()), "Magmawalker Obsidian", new BlockTypeInfo(BlockBreakInfo::instant())));
$blockFactory = CustomiesBlockFactory::getInstance();
self::register("obsidian", $blockFactory->get("piggyce:magmawalker_obsidian"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use pocketmine\item\Item;
use pocketmine\player\Player;

class PiggyObsidianBlock extends Opaque
final class PiggyObsidianBlock extends Opaque
{
private int $age = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use CortexPE\Commando\BaseSubCommand;
use CortexPE\Commando\exception\ArgumentOrderException;
use DaPigGuy\PiggyCustomEnchants\CustomEnchantManager;
use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook;
use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry;
use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants;
use DaPigGuy\PiggyCustomEnchants\utils\Utils;
use pocketmine\command\CommandSender;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function onRun(CommandSender $sender, string $aliasUsed, array $args): vo
return;
}
}
if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::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"]));
Expand Down Expand Up @@ -115,7 +115,7 @@ public function onRunForm(CommandSender $sender, string $aliasUsed, array $args)
return;
}
}
if ($item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId() || $item->getTypeId() === ItemTypeIds::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]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

namespace DaPigGuy\PiggyCustomEnchants\enchants\armor\boots;

use DaPigGuy\PiggyCustomEnchants\blocks\PiggyObsidian;
use DaPigGuy\PiggyCustomEnchants\blocks\CustomBlocksRegistry;
use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant;
use DaPigGuy\PiggyCustomEnchants\enchants\ReactiveEnchantment;
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;
Expand Down Expand Up @@ -45,8 +49,8 @@ public function react(Player $player, Item $item, Inventory $inventory, int $slo
for ($z = -$radius; $z <= $radius; $z++) {
$b = $world->getBlock($player->getPosition()->add($x, -1, $z));
if ($world->getBlock($b->getPosition()->add(0, 1, 0))->getTypeId() === BlockTypeIds::AIR) {
if ($b instanceof Lava && $b->getStateId() === 0) {
$world->setBlock($b->getPosition()->asVector3(), PiggyObsidian::PIGGY_OBSIDIAN());
if ($b instanceof Lava && $b->isSource()) {
$world->setBlock($b->getPosition()->asVector3(), CustomBlocksRegistry::OBSIDIAN());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace DaPigGuy\PiggyCustomEnchants\items;

use customiesdevs\customies\item\CustomiesItemFactory;
use pocketmine\item\Item;
use pocketmine\item\ItemIdentifier;
use pocketmine\item\ItemTypeIds;
use pocketmine\utils\CloningRegistryTrait;

/**
* @method static Item ENCHANTED_BOOK()
* @method static PiggyEnchantedBookItem ENCHANTED_BOOK()
*/
final class EnchantedBook
final class CustomItemsRegistry
{
use CloningRegistryTrait;

Expand All @@ -39,6 +38,7 @@ public static function getAll(): array

protected static function setup(): void
{
self::register("enchanted_book", new EnchantedBookItem(new ItemIdentifier(ItemTypeIds::newId()), "Enchanted Book"));
$itemFactory = CustomiesItemFactory::getInstance();
self::register("enchanted_book", $itemFactory->get("piggyce:enchanted_book"));
}
}
13 changes: 0 additions & 13 deletions src/DaPigGuy/PiggyCustomEnchants/items/EnchantedBookItem.php

This file was deleted.

24 changes: 24 additions & 0 deletions src/DaPigGuy/PiggyCustomEnchants/items/PiggyEnchantedBookItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace DaPigGuy\PiggyCustomEnchants\items;

use customiesdevs\customies\item\ItemComponents;
use customiesdevs\customies\item\ItemComponentsTrait;
use pocketmine\item\Item;
use pocketmine\item\ItemIdentifier;

final class PiggyEnchantedBookItem extends Item implements ItemComponents
{
use ItemComponentsTrait;

public function __construct(ItemIdentifier $identifier, string $name = "Enchanted Book")
{
parent::__construct($identifier, $name);
$this->initComponent("enchanted_book");
}

public function getMaxStackSize(): int
{
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use DaPigGuy\PiggyCustomEnchants\enchants\CustomEnchant;
use DaPigGuy\PiggyCustomEnchants\enchants\TickingEnchantment;
use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook;
use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry;
use DaPigGuy\PiggyCustomEnchants\PiggyCustomEnchants;
use DaPigGuy\PiggyCustomEnchants\utils\Utils;
use pocketmine\item\Item;
Expand All @@ -29,7 +29,7 @@ public function onRun(): void
foreach ($player->getInventory()->getContents() as $slot => $content) {
if ($content->getTypeId() === ItemTypeIds::BOOK) {
if (count($content->getEnchantments()) > 0) {
$enchantedBook = EnchantedBook::ENCHANTED_BOOK()->setNamedTag($content->getNamedTag())->setCount($content->getCount());
$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);
Expand Down
4 changes: 2 additions & 2 deletions src/DaPigGuy/PiggyCustomEnchants/utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use DaPigGuy\PiggyCustomEnchants\entities\PiggyFireball;
use DaPigGuy\PiggyCustomEnchants\entities\PiggyWitherSkull;
use DaPigGuy\PiggyCustomEnchants\entities\PigProjectile;
use DaPigGuy\PiggyCustomEnchants\items\EnchantedBook;
use DaPigGuy\PiggyCustomEnchants\items\CustomItemsRegistry;
use InvalidArgumentException;
use pocketmine\entity\Location;
use pocketmine\entity\projectile\Arrow;
Expand Down Expand Up @@ -130,7 +130,7 @@ public static function isBoots(Item $item): bool

public static function itemMatchesItemType(Item $item, int $itemType): bool
{
if ($item->getTypeId() === ItemTypeIds::BOOK || $item->getTypeId() === EnchantedBook::ENCHANTED_BOOK()->getTypeId()) 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,
Expand Down

0 comments on commit 60cde4b

Please sign in to comment.