1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Delete a Craft

Discussion in 'Development' started by Matrox, Feb 25, 2019.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Hello I would like to delete a craft?
     
  2. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    What do you mean?
     
  3. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    I created craft custom but the problem is that I would like to remove crafts to avoid that for example a sword can be crafter with a bousolle
     
  4. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    I'm confused. You want to create a custom crafting recipe right? Are you saying that you'd like to remove one you've already made, or to delete a default one so yours replaces it?
     
  5. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    A default
     
  6. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    It is not currently possible to unregister crafting recipes.
     
    jasonwynn10 and EdwardHamHam like this.
  7. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Can I use the craft event function? And like that I give back the items that created the item
     
  8. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Does works help me please :/

    PHP:
    <?php

    namespace dellitem;

    use 
    pocketmine\Server;
    use 
    pocketmine\event\Cancellable;
    use 
    pocketmine\event\CancellableTrait;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\inventory\CraftingRecipe;
    use 
    pocketmine\inventory\transaction\CraftingTransaction;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\player\PlayerInteractEvent;

    class 
    Main extends PluginBase{

        public function 
    onEnable(){

                
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
          }

        public function 
    onDisable(){
            
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
        }



        public function 
    OnCraftEvent(CraftItemEvent $event){
         
           if(
    $event->getRecipe()->getResult()->getId() === Item::BED){
              
    $event->setCancelled();
           
           }
        }
    }
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You forgot to register events
    PHP:
    class Main extends PluginBase implements Listener{
    PHP:
    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
    }
     
    jasonwynn10 likes this.
  10. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    Also, you're importing a lot of unneeded namespaces. Be sure to delete the ones you don't need.
     
  11. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    PHP:
    public function onCraftEvent(CraftItemEvent $event){
            foreach(
    $event->getRecipe()->getResults() as $results)
                if(
    $results->getId() === Item::BONE){
                    
    $event->setCancelled();
                }
                if(
    $results->getId() === Item::BLAZE_ROD){
                
    $event->setCancelled();
                break;
                }
        }
    I have a problem with "onCraftEvent"
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Please specify the problem. Is the server crashing? Is your computer exploding? Did the code become self aware?? You have to specify because I don't think we can deal with a terminator right now :confused:
     
  13. MusicNOvas

    MusicNOvas Spider Jockey

    Messages:
    43
    My server has crash
     
  14. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you should post a new thread, but okay

    what's the error message?
     
  15. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    My full code

    PHP:
    public function OnCraftEvent(CraftItemEvent $event){
         
          foreach(
    $event->getRecipe()->getResults() as $result)
               if(
    $result->getId() === Item::SEALANTERN or $result->getId() === Item::MAGMA or $result->getId() === Item::PRISMARINE or $result->getId() === Item::DYE or $result->getId() === Item::END_ROD or $result->getId() === Item::IRON_TRAPDOOR or $result->getId() === Item::END_ROD or $result->getId() === Item::BLAZE_POWDER or $result->getId() === Item::BREWING_STAND){

                  
    $event->setCancelled();
                  
    $event->getPlayer()->sendTip("§4Cette item n'est pas disponible !!");

                  if (
    $result->getId() === 167 && $result->getCustomName() == "§lHidenTrap") {
                    
    $event->setCancelled(false);
                    
    $event->getPlayer()->sendTip(" ");
                  }
     
  16. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    maybe the if statement doesn't go through, you should check it
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.