World: Check placed block collision boxes after place()

since we write these into a transaction instead of actually modifying the world directly, we can use the transaction to verify that the placement location is OK before setting the blocks.
closes #4248
This commit is contained in:
Dylan K. Taylor 2021-06-18 19:07:38 +01:00
parent 735c656f9d
commit d96fc17339
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1795,9 +1795,17 @@ class World implements ChunkManager{
return false;
}
foreach($hand->getCollisionBoxes() as $collisionBox){
if(count($this->getCollidingEntities($collisionBox)) > 0){
return false; //Entity in block
$tx = new BlockTransaction($this);
if(!$hand->place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
return false;
}
foreach($tx->getBlocks() as [$x, $y, $z, $block]){
$block->position($this, $x, $y, $z);
foreach($block->getCollisionBoxes() as $collisionBox){
if(count($entities = $this->getCollidingEntities($collisionBox)) > 0){
return false; //Entity in block
}
}
}
@ -1829,8 +1837,7 @@ class World implements ChunkManager{
}
}
$tx = new BlockTransaction($this);
if(!$hand->place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player) or !$tx->apply()){
if(!$tx->apply()){
return false;
}
foreach($tx->getBlocks() as [$x, $y, $z, $_]){