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

Solved Check if player breaks kelp plant

Discussion in 'Development' started by StevenS, Jul 2, 2019.

  1. StevenS

    StevenS Spider

    Messages:
    8
    Hey guys,

    I'm new to pocketmine but I used to code spigot plugins.

    I was wondering how I could check if a player breaks the kelp plant in the ocean?

    Here's my code

    public function onBlockBreak(BlockBreakEvent $event) : void {
    $block = $event->getBlock()->getId();
    $p = $event->getPlayer();
    if($block === BLOCK::KELP_PLANT){
    $p->sendMessage("You broke some kelp.");
    } else {
    $p->sendMessage("You didn't break kelp.");
    }
    }

    It seems that KELP_PLANT isn't a thing. KELP also doesn't work. I get an internal error disconnect whenever I break a block.

    Any ideas? Thanks!
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    An internal error prints the error in the console. Errors let you know which line in your code has an error. You can read the error message or if you still don't understand the error, paste the message here.
     
  3. StevenS

    StevenS Spider

    Messages:
    8
    Hey,

    Thanks for responding. The error tells me that "BLOCK::KELP_PLANT" isn't a block basically. What is the block ID for the kelp in the game that grows underwater? The green stuff lol? I just want to check when ppl break it.

    Steven
     
  4. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    393 and pocketmine doesnt generate that
     
  5. StevenS

    StevenS Spider

    Messages:
    8
    Okay, thanks. What do u mean pocketmine doesn't generate it? Like kelp doesn't grow in pocket edition?
     
  6. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    It does but pocketmines world generator doesnt grow this
     
  7. StevenS

    StevenS Spider

    Messages:
    8
    Ah. Can I place the kelp myself in water?

    And should this code work to check if someone breaks the kelp?

    public function onBlockBreak(BlockBreakEvent $event) : void {
    $block = $event->getBlock()->getId();
    $p = $event->getPlayer();
    if($block === 393){
    $p->sendMessage("You broke some kelp.");
    } else {
    $p->sendMessage("You didn't break kelp.");
    }
    }
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    DO NOT HARD-CODE BLOCK IDS
    Sooner or later, mojang would change block IDs and you'll need to go through all your code and replace the 393 with the new block IDs. Use Block::KELP constant instead.
     
  9. StevenS

    StevenS Spider

    Messages:
    8
    Hey, yeah I tried that but it doesn't know what "KELP" is so you get an internal error. I've changed around my strategy because I didn't know the world didn't generate kelp and I'm fine now.

    Thanks for the help guys!
     
  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.