Hey, I am actually trying to remove blocks under a player on PlayerMoveEvent for exemple. The problem is that the player can be supported by 2 blocks and when he is I want to remove these blocks. So my question is : How to know the number of blocks on which the player is ? I tried to use the getCollisonCubes fonction but I have an error (Maybe because I don't have know how to get the boundingBox ?) PHP: $sender->getLevel()->getCollisionCubes($sender, $sender->boundingBox , false)); Thanks for your help
PHP: if($player->onGround){ // make sure the player is standing on ground $bb = $player->getBoundingBox(); // $bb is the player BB which collides with the blocks' BBs such that the blocks can support the player $tv = new Vector3(0, (int) $player->y, 0); // $tv is a temporary vector to hold the three coordinates. This is micro-optimization to prevent instantiating a new Vector3 object every iteration. // $tv->y is a constant since the blocks that support the player are always at the same altitude // $tv->x and $tv->z are overwritten in the for loops below almost immediately, so the two 0s above are just placeholders used to initialize the Vector3. for($tv->x = (int) $b->minX; $tv->x <= (int) $b->maxX; ++$tv->x){ // iterate over $tv->x for($tv->z = (int) $b->minZ; $tv->z <= (int) $b->maxZ; ++$tv->z){ // iterate over $tv->z yield $player->getLevel()->getBlock($tv); } }} This method only works if the player is standing on a full block. If the player is standing on an incomplete block, think of your own way to fix the Y-coordinate
Thanks @SOFe ! EDIT : It doesn’t work, blocks are destroyed but they are next to the player and sometimes the calculation doesn’t work and don’t find any blocks @SOFe
No problem, I think it’s coming from the floor() func, who should be replaced by round(), need to check that
I checked and idk why but I still have the issue @SOFe :/, is it coming from the bounding box ? PHP: $bb = $p->getBoundingBox();$tv = new Vector3(0, (int) (round($p->y)), 0); for($tv->x = (int) round($bb->minX); $tv->x <= (int) round($bb->maxX); ++$tv->x){ for($tv->z = (int) round($bb->minZ); $tv->z <= (int) $bb->maxZ; ++$tv->z){ //remove the block } }
Code: NOTE: The figures were looking perfectly aligned on my machine. [X] = Blocks you are checking \0/ = Player /\ Possibilities since $bb->minX, $bb->maxX, $bb->minZ, $bb->maxZ are floats: 1. If player is standing right on the center of a block. \0/ [Y][X][Y] - You are checking the block on player's foot! Probably air! 2. If player is standing in the center of 4 blocks. \0/ [X][X] - 3D wise, you will be checking all the 4 blocks... NOT. You'll be checking the blocks above all the four blocks! 3. If player is jumping \0/ /\ [Y][Y] - No blocks! TL;DR PHP: $tv = new Vector3(0, (int) (round($p->y)), 0);//^is incorrect, it should've actually been:$tv = new Vector3(0, (int) (round($p->y) - 1), 0); But why (int) cast something rounded with a precision of 0?
I don't know why you want to round the Y-coordinate. Do you assume that the player is standing on the chest when he's supported by a chest block, but standing on the ground below the redstone repeater when he is supported by a redstone repeater (height < 0.5) block? Why not use ceil()? Also note that the y axis may sometimes not be what you expect it to be. After jumping a few times, the player may be slightly above/below the ground by several millimeters. Not sure if it is still like this now, but it was like this back a few versions