removed return value of ChunkManager->setBlockAt() and World->setBlock()

This commit is contained in:
Dylan K. Taylor 2019-07-21 18:55:22 +01:00
parent 703ae3a172
commit 80d277f1b5
5 changed files with 12 additions and 17 deletions

View File

@ -268,7 +268,8 @@ class Block extends Position{
if(($t = $this->world->getTile($this)) !== null){ if(($t = $this->world->getTile($this)) !== null){
$t->onBlockDestroyed(); $t->onBlockDestroyed();
} }
return $this->getWorld()->setBlock($this, VanillaBlocks::AIR()); $this->getWorld()->setBlock($this, VanillaBlocks::AIR());
return true;
} }
/** /**

View File

@ -43,7 +43,8 @@ class Ice extends Transparent{
public function onBreak(Item $item, ?Player $player = null) : bool{ public function onBreak(Item $item, ?Player $player = null) : bool{
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){ if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){
return $this->getWorld()->setBlock($this, VanillaBlocks::WATER()); $this->getWorld()->setBlock($this, VanillaBlocks::WATER());
return true;
} }
return parent::onBreak($item, $player); return parent::onBreak($item, $player);
} }

View File

@ -47,9 +47,9 @@ interface ChunkManager{
* @param int $z * @param int $z
* @param Block $block * @param Block $block
* *
* @return bool TODO: remove * @throws \InvalidArgumentException
*/ */
public function setBlockAt(int $x, int $y, int $z, Block $block) : bool; public function setBlockAt(int $x, int $y, int $z, Block $block) : void;
/** /**
* @param int $chunkX * @param int $chunkX

View File

@ -58,13 +58,13 @@ class SimpleChunkManager implements ChunkManager{
return VanillaBlocks::AIR(); return VanillaBlocks::AIR();
} }
public function setBlockAt(int $x, int $y, int $z, Block $block) : bool{ public function setBlockAt(int $x, int $y, int $z, Block $block) : void{
if($this->terrainPointer->moveTo($x, $y, $z, true)){ if($this->terrainPointer->moveTo($x, $y, $z, true)){
$this->terrainPointer->currentSubChunk->setFullBlock($x & 0xf, $y & 0xf, $z & 0xf, $block->getFullId()); $this->terrainPointer->currentSubChunk->setFullBlock($x & 0xf, $y & 0xf, $z & 0xf, $block->getFullId());
$this->terrainPointer->currentChunk->setChanged(true); $this->terrainPointer->currentChunk->setChanged(true);
return true; }else{
throw new \InvalidArgumentException("Cannot set block at coordinates x=$x,y=$y,z=$z, terrain is not loaded or out of bounds");
} }
return false;
} }
/** /**

View File

@ -1446,18 +1446,15 @@ class World implements ChunkManager{
/** /**
* Sets the block at the given Vector3 coordinates. * Sets the block at the given Vector3 coordinates.
* @see World::setBlockAt()
* *
* @param Vector3 $pos * @param Vector3 $pos
* @param Block $block * @param Block $block
* @param bool $update * @param bool $update
* *
* @return bool Whether the block has been updated or not
*
* @throws \InvalidArgumentException if the position is out of the world bounds * @throws \InvalidArgumentException if the position is out of the world bounds
*/ */
public function setBlock(Vector3 $pos, Block $block, bool $update = true) : bool{ public function setBlock(Vector3 $pos, Block $block, bool $update = true) : void{
return $this->setBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $block, $update); $this->setBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $block, $update);
} }
/** /**
@ -1472,11 +1469,9 @@ class World implements ChunkManager{
* @param Block $block * @param Block $block
* @param bool $update * @param bool $update
* *
* @return bool Whether the block has been updated or not
*
* @throws \InvalidArgumentException if the position is out of the world bounds * @throws \InvalidArgumentException if the position is out of the world bounds
*/ */
public function setBlockAt(int $x, int $y, int $z, Block $block, bool $update = true) : bool{ public function setBlockAt(int $x, int $y, int $z, Block $block, bool $update = true) : void{
if(!$this->isInWorld($x, $y, $z)){ if(!$this->isInWorld($x, $y, $z)){
throw new \InvalidArgumentException("Pos x=$x,y=$y,z=$z is outside of the world bounds"); throw new \InvalidArgumentException("Pos x=$x,y=$y,z=$z is outside of the world bounds");
} }
@ -1511,8 +1506,6 @@ class World implements ChunkManager{
} }
$this->timings->setBlock->stopTiming(); $this->timings->setBlock->stopTiming();
return true;
} }
/** /**