Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

PM5 Update #419

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 3 additions & 4 deletions .poggit.yml
Original file line number Diff line number Diff line change
@@ -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
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
7 changes: 3 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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.#"
checkMissingIterableValueType: false
5 changes: 3 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/DaPigGuy/PiggyCustomEnchants/CustomEnchantManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
22 changes: 13 additions & 9 deletions src/DaPigGuy/PiggyCustomEnchants/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
29 changes: 22 additions & 7 deletions src/DaPigGuy/PiggyCustomEnchants/PiggyCustomEnchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -31,20 +36,21 @@
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
{
foreach (
[
"Commando" => BaseCommand::class,
"libformapi" => Form::class,
"FormsUI" => Form::class,
"libPiggyUpdateChecker" => libPiggyUpdateChecker::class
] as $virion => $class
) {
Expand All @@ -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);

Expand Down Expand Up @@ -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",
);
}
}
42 changes: 42 additions & 0 deletions src/DaPigGuy/PiggyCustomEnchants/blocks/CustomBlocksRegistry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace DaPigGuy\PiggyCustomEnchants\blocks;

use customiesdevs\customies\block\CustomiesBlockFactory;
use pocketmine\block\Block;
use pocketmine\utils\CloningRegistryTrait;

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

private function __construct()
{
//NOOP
}

protected static function register(string $name, Block $block): void
{
self::_registryRegister($name, $block);
}

/**
* @return Block[]
* @phpstan-return array<string, Block>
*/
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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"));
Expand Down
Loading
Loading