In my code I teleport a player to 10 blocks above it, and there I need to create a cage to trap it, how do I do that?
PHP: $X = $player->getFloorX();$Y = $player->getFloorY();$Z = $player->getFloorZ();$size = 3;for($x = $X - $size;$x <= $X + $size;$x++){ for($y=$Y - $size;$y <= $Y + $size;$y++){ for($z = $Z - $size;$z <= $Z+$size;$z++){ if(!($x === $X && $z === $Z && ($y === $Y || $y === $Y+1))){ $player->level->setBlockIdAt($x,$y,$z,7); } } }}
Error in this code Code: [13:50:31] [Server thread/CRITICAL]: Error: "Call to a member function setBlockIdAt() on null" (EXCEPTION) in "/Admin/src/DanielYTK/Coder/code" at line 197
I think the player can glitch through the blocks easily. The block could spawn where the player is, so the player's body is half inside the block already. Once you've setBlockIdAt(), teleport the player in the middle of the boxed prison. PHP: $player->teleport($player->floor());
I tried this, just need to test PHP: $X = $entity->getFloorX(); $Y = $entity->getFloorY(); $Z = $entity->getFloorZ(); $entity->getLevel()->setBlockIdAt($X -1,$Y,$Z,7); //Isso seta os blocos da cage $entity->getLevel()->setBlockIdAt($X +1,$Y,$Z,7); $entity->getLevel()->setBlockIdAt($X +1,$Y -1,$\,7); $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z,7); $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z -1,7); $entity->getLevel()->setBlockIdAt($X -1,$Y +2,$Z +1,7);
Hmmm... logic error XD replace the if statement with this PHP: if(!($x === $X && $z === $Z && ($y === $Y || $y === $Y+1))){ $player->level->setBlockIdAt($x,$y,$z,7);}