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

When you kill pig the pork goes to your inventory but also drops to the ground

Discussion in 'Development' started by Levi, Jan 3, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I'm using AUtoInv @Jack Noordhuis and teaspoon by @CortexPE
    I killed a pig and the pork drops to the ground but also goes to your inventory.. it doubles.. i want to stop that

    pretty sure this is the code to set drops of pigs in TeaSpoon

    PHP:
    public function getDrops(): array{
            
    $cause $this->lastDamageCause;
            if(
    $cause instanceof EntityDamageByEntityEvent){
                
    $damager $cause->getDamager();
                if(
    $damager instanceof Player){
                    
    //$looting = $damager->getInventory()->getItemInHand()->getEnchantment(Enchantment::LOOTING);
                    //if($looting !== null){
                        //$lootingL = $looting->getLevel();
                    //}else{
                        //$lootingL = 0;
                    //}

                    
    return [
                        
    Item::get(Item::RAW_PORKCHOP0mt_rand(13)),
                    ];
                }
            }

            return [];
        }
    and this is the code in Autoinv that add the entity drops to your inventory
    PHP:
    public function onDeath(EntityDeathEvent $event) {
            
    $victim $event->getEntity();
            
    $cause $victim->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
                
    $killer $cause->getDamager();
                if(
    $killer instanceof InventoryHolder) {
                    foreach(
    $event->getDrops() as $drop) {
                        
    $killer->getInventory()->addItem($drop);
                    }
                }
            } else {
                
    $event->setDrops([]);
            }
            return;
        }
    how can i stop the pork from dropping to the ground? I want it to only go to my inventory straight
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    PHP:
    public function getDrops(): array{
            
    $cause $this->lastDamageCause;
            if(
    $cause instanceof EntityDamageByEntityEvent){
                
    $damager $cause->getDamager();
                if(
    $damager instanceof Player){
                    
    //$looting = $damager->getInventory()->getItemInHand()->getEnchantment(Enchantment::LOOTING);
                    //if($looting !== null){
                        //$lootingL = $looting->getLevel();
                    //}else{
                        //$lootingL = 0;
                    //}

                    
    return [];
                }
            }

            return [];
        }
    Try this.
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Plugin errors go in the plugin help section
     
    iiFlamiinBlaze and EdwardHamHam like this.
  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.