I don't think anyone wants to sit here and explain every process of making a custom enchant, but I will because I'm nice enough to do that!!!!!!! :smile: First step is to register your own enchantment. This is how I did it to keep things organized! 1. Create Main class and CustomEnchantment class! PHP: use pocketmine\plugin\PluginBase;// We'll use these lateruse pocketmine\item\Item;use pocketmine\nbt\NBT;use pocketmine\utils\TextFormat as C;use pocketmine\command\{ Command, CommandSender, ConsoleCommandSender};use pocketmine\item\enchantment\{ Enchantment, EnchantmentInstance};use pocketmine\nbt\tag\{ CompoundTag, ShortTag, ListTag};class Main extends PluginBase{ public function onEnable(): void{ new CustomEnchantment();} Then go to CustomEnchantment.php file you created. PHP: use pocketmine\item\enchantment\Enchantment;use HealthStealer;class CustomEnchantment { public const HEALTHSTEALER = 100; // Enchant ID // repeat with different number to create more enchants public function __construct(){ $this->init(); } public function init(){ Enchantment::registerEnchantment(new Enchantment(self::HEALTHSTEALER, "Health Stealer", Enchantment::RARITY_COMMON, Enchantment::SLOT_SWORD, Enchantment::SLOT_NONE, 5)); new HealthStealer(); // repeat. I'm pretty sure you know what to do now. }} Then create a file named HealthStealer.php which will work as our listener. PHP: use pocketmine\Player;use pocketmine\event\Listener;use pocketmine\event\entity\{ EntityDamageEvent, EntityDamageByEntityEvent};use MainClass;class HealthStealer implements Listener { public function __construct() { MainClass::get()->getServer()->getPluginManager()->registerEvents($this, MainClass::get()); } public function onDamage(EntityDamageEvent $event): void { if($event instanceof EntityDamageByEntityEvent){ $damager = $event->getDamager(); $entity = $event->getEntity(); if($event->isCancelled()) return; // Prevent CE working even when on attack cooldown. if($damager->getInventory()->getItemInHand()->getEnchantment(100)) { // Checks for the enchantment $chance = rand(1, 200); // You can add a simple activation chance using this! if ($chance === 198) { // You can add a simple activation chance using this! $damager->setHealth($damager->getHealth() + 5 > $damager->getMaxHealth() ? $damager->getMaxHealth() : $damager->getHealth() + 5); $damager->sendMessage("§7>> §cYou stole health from ".$entity->getName()."!"); } } } }} Now let's display those enchantments! Back to your main file! PHP: public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool{ if($cmd->getName() == "customenchant"){ if(count($args) < 2){ $sender->sendMessage("Usage: /ceenchant <player> <enchantment> <level>"); return false; } if(!$this->getServer()->getPlayer($args[0])){ $sender->sendMessage("Player ". $args[0] . " cannot be found."); return false; } $player = $this->getServer()->getPlayer($args[0]); $inv = $player->getInventory(); if($inv->getItemInHand() === null){ $player->sendMessage("You must hold an item to proceed."); $sender->sendMessage($player->getName() . " Is not holding an item!"); return false; } if(is_numeric($args[1])){ $enchantment = Enchantment::getEnchantment((int) $args[1]); }else{ $enchantment = Enchantment::getEnchantmentByName($args[1]); } if($args[1] < 100 || !$enchantment instanceof Enchantment){ $sender->sendMessage("That enchantment cannot be found."); return false; } $item = $inv->getItemInHand(); $this->addEnchantment($item, new EnchantmentInstance($enchantment, (int) ($args[2] ?? 1)), $enchantment); $inv->setItemInHand($item); } } public function addEnchantment(Item $item, EnchantmentInstance $enchantment, Enchantment $e): void{ if($item->hasEnchantment($enchantment->getId())){ $lvl = $item->getEnchantment($enchantment->getId())->getLevel(); $lore = $item->getLore(); $name = array_search($e->getName() . " " . $lvl, $lore); unset($lore[$name]); $item->setLore($lore); $item->removeEnchantment($enchantment->getId()); } $found = false; $ench = $item->getNamedTagEntry(Item::TAG_ENCH); if(!($ench instanceof ListTag)){ $ench = new ListTag(Item::TAG_ENCH, [], NBT::TAG_Compound); }else{ foreach($ench as $k => $entry){ if($entry->getShort("id") == $enchantment->getId()){ $nbt = new CompoundTag("", [ new ShortTag("id", $enchantment->getId()), new ShortTag("lvl", $enchantment->getLevel()) ]); $ench->set($k, $nbt); $item->setLore(array_merge($item->getLore(), [$e->getName() . " " . $this->roman($enchantment->getLevel())])); $found = true; break; } } } if(!$found){ $nbt = new CompoundTag("", [ new ShortTag("id", $enchantment->getId()), new ShortTag("lvl", $enchantment->getLevel()) ]); $ench->push($nbt); $item->setLore(array_merge($item->getLore(), [$e->getName() . " " . $this->roman($enchantment->getLevel())])); } $item->setNamedTagEntry($ench); } public function roman(int $lvl): string{ $string = ""; $romans = [ "C" => 100, "L" => 50, "XL" => 40, "X" => 10, "IX" => 9, "VIII" => 8, "VII" => 7, "VI" => 6, "V" => 5, "IV" => 4, "III" => 3, "II" => 2, "I" => 1 ]; while($lvl > 0){ foreach($romans as $roman => $int){ if($lvl >= $int){ $lvl -= $int; $string .= $roman; break; } } } return $string; } Simplest way to create custom enchant!
hello could you help me? I wanted to make a Custom Enchant Plugin, but for version 0.15.10 or 1.1.5, DaPiggyGuy's api is very complex so I wanted to know if you could explain it to me ( in the versions I mentioned the enchantment api is different :/ ) Why I use such an old version? Performance and still have a good amount of players playing lol
Yes i can https://drive.google.com/file/d/1GYeQVURcME5WdaHga0ymG001NPg1aKFC/view?usp=drivesdk Note: As I want to learn how to make the plugin described above , this version which I use is a pmmp fork do you have any problem with that ? because I haven't found an official version of pmmp for 0.15.10
and no. As long as I can understand what the version is doing, I can help you through! If you have discord, please add me: minijaham#3259
What bro don't use this version. Use the latest version of pocketmine. : https://github.com/pmmp/Pocketmine-MP/releases
I sent the request to Discord, https://github.com/GenisysPro/GenisysPro esta é a api que estou usando no momento
I cannot test if the method works, since I'm unable to get on the version of minecraft, but here. Simply register the enchantment first: PHP: const TYPE_WEAPON_ENCHANTNAME;Enchantment::registerEnchantment(self::TYPE_WEAPON_ENCHANTNAME, "Vampire", Enchantment::RARITY_COMMON, Enchantment::ACTIVATION_EQUIP, Enchantment::SLOT_SWORD);new CustomEnchantName(); Then, implement the enchantment: PHP: class CustomEnchantName implements Listener { public function __construct() { MainClass::get()->getServer()->getPluginManager()->registerEvents($this, MainClass::get()); } public function onDamage(EntityDamageEvent $event) : void { // the event can vary depending on what you're trying to do if($event instanceof EntityDamageByEntityEvent){ // code } }} Now, when you're trying to enchant the custom enchant: PHP: if($item->hasEnchantment($enchantment->getId())) { // If the item has this enchantment $level = $item->getEnchantment($enchant)->getLevel(); $lore = $item->getLore(); $name = array_search($enchant->getName() . " " . $this->convert($level), $lore); unset($lore[$name]); $item->setLore($lore); $item->removeEnchantment($enchant); } $item->setLore(array_merge($item->getLore(), [$enchant->getName() . " " . $this->convert($enchantment->getLevel())])); } public function convert(int $lvl) : string // converts the enchantment level to roman numeral { $string = ""; $romans = [ 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 ]; while($lvl > 0){ foreach($romans as $roman => $int){ if($lvl >= $int){ $lvl -= $int; $string .= $roman; break; } } } return $string; } Do something like this. I can't really figure out how I can make this work in this version :l perhaps,...someone else can continue with this and help?