Rail: detect state and then place, not vice versa

This commit is contained in:
Dylan K. Taylor 2018-09-30 14:35:57 +01:00
parent 1a2312418b
commit 274a4d892f

View File

@ -98,9 +98,9 @@ abstract class BaseRail extends Flowable{
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
if(!$blockReplace->getSide(Facing::DOWN)->isTransparent() and parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){
$this->tryReconnect(); $this->tryReconnect();
return true; return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
} }
return false; return false;
@ -240,7 +240,8 @@ abstract class BaseRail extends Flowable{
if(isset($otherPossible[$otherSide])){ if(isset($otherPossible[$otherSide])){
$otherConnections[] = $otherSide; $otherConnections[] = $otherSide;
$other->updateState($otherConnections); $other->setConnections($otherConnections);
$other->level->setBlock($other, $other);
$changed = true; $changed = true;
$thisConnections[] = $thisSide; $thisConnections[] = $thisSide;
@ -252,11 +253,11 @@ abstract class BaseRail extends Flowable{
}while($continue); }while($continue);
if($changed){ if($changed){
$this->updateState($thisConnections); $this->setConnections($thisConnections);
} }
} }
private function updateState(array $connections) : void{ private function setConnections(array $connections) : void{
if(count($connections) === 1){ if(count($connections) === 1){
$connections[] = Facing::opposite($connections[0] & ~self::FLAG_ASCEND); $connections[] = Facing::opposite($connections[0] & ~self::FLAG_ASCEND);
}elseif(count($connections) !== 2){ }elseif(count($connections) !== 2){
@ -264,7 +265,6 @@ abstract class BaseRail extends Flowable{
} }
$this->connections = $connections; $this->connections = $connections;
$this->level->setBlock($this, $this, false); //avoid recursion
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{