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

Remove drop of a crop when breaking the farm land.

Discussion in 'Development' started by VincBros, Apr 3, 2020.

  1. VincBros

    VincBros Silverfish

    Messages:
    19
    GitHub:
    vincbros
    Hey! Here's what I want to do: When you break a beetroot crop, I only want the crop to drop beetroot seeds. But I discovered that when you break the farmland under it, it drops a beetroot. Here's what I came up with, but it dosen't seem to work.
    Code:
    
        public function onBreak(BlockBreakEvent $event){
            $block = $event->getBlock();
            $player = $event->getPlayer();
            $level = $player->getLevel();
            $under = $block->add(0, -1, 0);
            $above = $block->add(0, 1, 0);
            if ($block->getId() == Block::BEETROOT_BLOCK and $block->getDamage() >= 4) {
                $event->setDrops([Item::get(458, 0 , mt_rand(1, 2))]);
                $event->setDrops([Item::get(457, 0, 0)]);
            }
            if ($block->getId() == 60 and $block->getLevel()->getBlock($above)->getId() == Block::BEETROOT_BLOCK and $block->getLevel()->getBlock($above)->getDamage() >= 4) {
                $event->setDrops([Item::get(458, 0 , mt_rand(1, 2))]);
                $event->setDrops([Item::get(457, 0, 0)]);
                $event->setDrops([Item::get(3, 0, 1)]);
            }
     
    60 is the id of a farm land block by the way.
    Sorry for my bad english, I am french.
     
  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.