Start using transactions for block placement

This commit is contained in:
Dylan K. Taylor
2019-06-08 18:56:27 +01:00
parent f84040a7ad
commit c1f900ab18
50 changed files with 172 additions and 129 deletions

View File

@@ -1830,15 +1830,19 @@ class World implements ChunkManager, Metadatable{
}
}
if(!$hand->place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
$tx = new BlockTransaction($this);
if(!$hand->place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player) or !$tx->apply()){
return false;
}
$tile = $this->getTile($hand);
if($tile !== null){
//TODO: seal this up inside block placement
$tile->copyDataFromItem($item);
foreach($tx->getBlocks() as [$x, $y, $z, $_]){
$tile = $this->getTileAt($x, $y, $z);
if($tile !== null){
//TODO: seal this up inside block placement
$tile->copyDataFromItem($item);
}
$this->getBlockAt($x, $y, $z)->onPostPlace();
}
$hand->onPostPlace();
if($playSound){
$this->addSound($hand, new BlockPlaceSound($hand));