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

Get position of a block

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

  1. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    So for a KitPvP plugin I'm making, I want it so that when a player hits green wool, it gives them an item. Here is what I have so far (onInteract):
    PHP:
     elseif($block->getId() == 35){
            if(
    $block->getDamage() == 13){
                if(isset(
    $this->soup[$player->getName()])){
                    
    $player->sendMessage(TextFormat::BOLD TextFormat::GREEN "You got one free soup!");
                    
    $player->getInventory()->addItem(Item::get(28201));
                    
    $level->addSound(new PopSound($player));
                } else {
                    
    $player->sendMessage(TextFormat::BOLD TextFormat::GREEN "You got one free healing potion!");
                    
    $player->getInventory()->addItem(Item::get(438221));
                    
    $level->addSound(new PopSound($player));
                }
            }
        }
    The problem with this however, is that there is alot of green wool on my map, and if I interact with those, it will also give me the item. That's why I want to get the position (the X, the Y, and the Z) of the block so it doesn't just go off giving players free stuff anywhere.

    Thanks in advance!

    P.S: On a completely unrelated topic, do you know that sound whenever you buy an item in Bedwars in Hypixel makes? Is that sound in Pocketmine too or no?
     
  2. AlicanCopur

    AlicanCopur Creeper

    Messages:
    5
    GitHub:
    alicancopur
    Use this.
    PHP:
    elseif($block->getId() == 35){
            if(
    $block->getDamage() == 13 and floor($block->getX()) == 10 and floor($block->getY()) == 20 and floor($block->getZ()) == 10){
                if(isset(
    $this->soup[$player->getName()])){
                    
    $player->sendMessage(TextFormat::BOLD TextFormat::GREEN "You got one free soup!");
                    
    $player->getInventory()->addItem(Item::get(28201));
                    
    $level->addSound(new PopSound($player));
                } else {
                    
    $player->sendMessage(TextFormat::BOLD TextFormat::GREEN "You got one free healing potion!");
                    
    $player->getInventory()->addItem(Item::get(438221));
                    
    $level->addSound(new PopSound($player));
                }
            }
        }
     
    HimbeersaftLP and ethaniccc 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.