I'm trying to spawn a chest and add items to it and one of the problems I've encountered is spawning it at ground level how would I do that?
I'm trying to make y groundlevel so it always spawns on the ground insteade of y being like 80 its groundlevel for the block its at or I should say one block above ground level
Ah so you want to get the highest real block (not air) at a position (X,Y) PHP: /** @var $level pocketmine\level\Level *//** @var $x int *//** @var $y int */$highestBlockY = $level->getHighestBlockAt($x, $z);$y = $highestBlockY + 1;//now spawn your chest at $x, $y, $z
Y'all know that this won't work right ? Chest can't be opened when it's far more than blocks from the player (Client side)
he is populating a map with random chests for players to find. Your comment is useless to this thread.
If you want to avoid placing the chest block on a non-solid block to make it look natural, you can check for transparency of the block at $highestBlockY (from robske's reply) PHP: $blockBeneath = $level->getBlockAt($x, $highestBlockY, $z);$canPlaceChest = !$blockBeneath->isTransparent() && !$blockBeneath->isFlowable();if($canPlaceChest){ //place chest at ($x, $y, $z)} This is just to avoid things like these from happening, but will also avoid chest from being placed on glass too.