When I try to check if a block's tag is lb (lucky block), I run into this error. Code: Error: "Call to undefined method pocketmine\block\Sponge::getNamedTag()" (EXCEPTION) in "plugins/LuridCore/src/NickteeChunky/LCore/Core" at line 145 Here is my code: PHP: public function onBreak(BlockBreakEvent $e){ $p = $e->getPlayer(); $b = $e->getBlock(); $nbt = $b->getNamedTag(); // Line 145 if($b->getId() == 19){ if($nbt->hasTag("lb", StringTag::class)){ $p->sendMessage("Lucky block opened."); } } }
Just save the luckyblock's position and then check it. I don't think it is possible to create tile from sponge.
Okay, I've done that but how am I supposed to check each and every lucky block's position to find out it's value, if you save any lucky block's position, once you place another and haven't broken the previous one, the previous one's value changes. I'd really appreciate if you can help me further with this. Thanks in advance.
I normally haven't using sponge on my builds. So if I wanted luckyblock plugin, I just check the block id, if it's sponge.
However if you wanted to save every lucky block when it's placed, you can try this code PHP: /** @var array $blocks */public $blocks;/*** @param BlockPlaceEvent $event*/public function onPlace(BlockPlaceEvent $event) { $player = $event->getPlayer(); $block = $event->getBlock(); $this->blocks[] = "$block->x:$block->y:$block->z";}/*** @param BlockBreakEvent $event*/public function onBreak(BlockBreakEvent $event) { $player = $event->getPlayer(); $block = $event->getBlock(); if($block->getId() == Block::SPONGE && in_array("$block->x:$block->y:$block->z", $this->blocks)) { // your code unset($this->blocks[array_search("$block->x:$block->y:$block->z", $this->blocks) - 1]); }}
Sorry for going missing, I never received a notification regarding your reply and have been busy. Anyways, I've done as you've shown, and it stores the lucky block's position but what I'm trying to do here is store it's success rate, as in lucky block luck rate. How am I to check it from it's position now and get it's tag? @GamakCZ
It isn't possible to create a visible tile from a sponge, but a tile can still occupy the same position to hold NBT. A poggit virion was recently made to help handle tiles for block data storage which may help this case situation. What needs to be done is on block place, create tile with the same position. Then using the tile, store the namedTag. https://github.com/DenielWorld/EzTiles