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

Entity drop Inventory

Discussion in 'Development' started by yBriisMC, Mar 7, 2022.

  1. yBriisMC

    yBriisMC Silverfish

    Messages:
    19
    I'm trying to make the entities when killed drop into the player's inventory that executed that entity
    I'm On Pocketmine Version 3.28.0 - PM3
    PHP:
    <?php

    namespace MasterFeio\entity\mob;

    use 
    pocketmine\entity\Animal;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDeathEvent;
    class 
    IronGolem extends Animal
    {

        public const 
    NETWORK_ID self::IRON_GOLEM;

        public 
    $width 1.4;
        public 
    $height 2.7;

        public function 
    getName(): string
        
    {
            return 
    "Iron Golem";
        }

        public function 
    initEntity(): void{
            
    $this->setMaxHealth(100);
            
    parent::initEntity();
        }

        public function 
    getDrops(): array
        {
            
    $lootingL 1;
            
    $cause $this->lastDamageCause;
            if(
    $cause instanceof EntityDamageByEntityEvent){
                
    $dmg $cause->getDamager();
                if(
    $dmg instanceof Player){
                 
                    
    $looting $dmg->getInventory()->getItemInHand()->getEnchantment(Enchantment::LOOTING);
                    if(
    $looting !== null){
                        
    $lootingL $looting->getLevel();
                    }else{
                        
    $lootingL 1;
                }
                }
            }
            
    $iron Item::get(Item::IRON_INGOT0mt_rand(1$lootingL));
            
    $rose Item::get(Item::RED_FLOWER0$lootingL);
            if(
    mt_rand(05) === 0) {
                return [
    $iron$rose];
            }
            return [
    $iron];
        }
    }
    //I'm using this code in my entities.
     
  2. yBriisMC

    yBriisMC Silverfish

    Messages:
    19
    This code would be inside the if that is the enchant or where is the items I was in doubt
     
  3. yBriisMC

    yBriisMC Silverfish

    Messages:
    19
    Ok, more and Plunder would be like this code just for me to understand and have a base
     
  4. yBriisMC

    yBriisMC Silverfish

    Messages:
    19
    By the way, what
    well I went to test the code, I just didn't understand where to put the entity's item inside the "return [];" Get more drops on the floor
     
  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.