mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-10 15:59:39 +00:00
SubChunkExplorer::moveTo() now returns a status
this can be used by SubChunkExplorer subclasses to implement specialized logic.
This commit is contained in:
parent
390bc631c8
commit
31c2c3abb5
@ -40,6 +40,7 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\world\particle\HugeExplodeSeedParticle;
|
||||
use pocketmine\world\sound\ExplodeSound;
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
use function ceil;
|
||||
use function floor;
|
||||
use function mt_rand;
|
||||
@ -123,7 +124,7 @@ class Explosion{
|
||||
$pointerY += $shiftY;
|
||||
$pointerZ += $shiftZ;
|
||||
|
||||
if(!$this->subChunkExplorer->moveTo($vBlockX, $vBlockY, $vBlockZ, false)){
|
||||
if($this->subChunkExplorer->moveTo($vBlockX, $vBlockY, $vBlockZ, false) === SubChunkExplorerStatus::INVALID){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\utils\Limits;
|
||||
use pocketmine\world\format\Chunk;
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
|
||||
class SimpleChunkManager implements ChunkManager{
|
||||
|
||||
@ -50,14 +51,14 @@ class SimpleChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
public function getBlockAt(int $x, int $y, int $z) : Block{
|
||||
if($this->terrainPointer->moveTo($x, $y, $z, false)){
|
||||
if($this->terrainPointer->moveTo($x, $y, $z, false) !== SubChunkExplorerStatus::INVALID){
|
||||
return BlockFactory::getInstance()->fromFullBlock($this->terrainPointer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf));
|
||||
}
|
||||
return VanillaBlocks::AIR();
|
||||
}
|
||||
|
||||
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) !== SubChunkExplorerStatus::INVALID){
|
||||
$this->terrainPointer->currentSubChunk->setFullBlock($x & 0xf, $y & 0xf, $z & 0xf, $block->getFullId());
|
||||
$this->terrainPointer->currentChunk->setDirtyFlag(Chunk::DIRTY_FLAG_TERRAIN, true);
|
||||
}else{
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\world\light;
|
||||
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
use function max;
|
||||
|
||||
class BlockLightUpdate extends LightUpdate{
|
||||
@ -50,7 +51,7 @@ class BlockLightUpdate extends LightUpdate{
|
||||
}
|
||||
|
||||
public function recalculateNode(int $x, int $y, int $z) : void{
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false) !== SubChunkExplorerStatus::INVALID){
|
||||
$block = $this->subChunkExplorer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
|
||||
$this->setAndUpdateLight($x, $y, $z, max($this->lightEmitters[$block], $this->getHighestAdjacentLight($x, $y, $z) - $this->lightFilters[$block]));
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\world\light;
|
||||
|
||||
use pocketmine\world\format\LightArray;
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
use pocketmine\world\World;
|
||||
use function max;
|
||||
|
||||
@ -65,7 +66,7 @@ abstract class LightUpdate{
|
||||
abstract public function recalculateNode(int $x, int $y, int $z) : void;
|
||||
|
||||
protected function getEffectiveLight(int $x, int $y, int $z) : int{
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false) !== SubChunkExplorerStatus::INVALID){
|
||||
return $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
|
||||
}
|
||||
return 0;
|
||||
@ -95,7 +96,7 @@ abstract class LightUpdate{
|
||||
private function prepareNodes() : LightPropagationContext{
|
||||
$context = new LightPropagationContext();
|
||||
foreach($this->updateNodes as $blockHash => [$x, $y, $z, $newLevel]){
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false)){
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false) !== SubChunkExplorerStatus::INVALID){
|
||||
$oldLevel = $this->currentLightArray->get($x & 0xf, $y & 0xf, $z & 0xf);
|
||||
|
||||
if($oldLevel !== $newLevel){
|
||||
@ -131,7 +132,7 @@ abstract class LightUpdate{
|
||||
];
|
||||
|
||||
foreach($points as [$cx, $cy, $cz]){
|
||||
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false)){
|
||||
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false) !== SubChunkExplorerStatus::INVALID){
|
||||
$this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight, $context);
|
||||
}elseif($this->getEffectiveLight($cx, $cy, $cz) > 0 and !isset($context->spreadVisited[$index = World::blockHash($cx, $cy, $cz)])){
|
||||
$context->spreadVisited[$index] = true;
|
||||
@ -161,7 +162,7 @@ abstract class LightUpdate{
|
||||
];
|
||||
|
||||
foreach($points as [$cx, $cy, $cz]){
|
||||
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false)){
|
||||
if($this->subChunkExplorer->moveTo($cx, $cy, $cz, false) !== SubChunkExplorerStatus::INVALID){
|
||||
$this->computeSpreadLight($cx, $cy, $cz, $newAdjacentLight, $context);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\world\light;
|
||||
|
||||
use pocketmine\world\utils\SubChunkExplorer;
|
||||
use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
use pocketmine\world\World;
|
||||
use function max;
|
||||
|
||||
@ -59,7 +60,7 @@ class SkyLightUpdate extends LightUpdate{
|
||||
}
|
||||
|
||||
public function recalculateNode(int $x, int $y, int $z) : void{
|
||||
if(!$this->subChunkExplorer->moveTo($x, $y, $z, false)){
|
||||
if($this->subChunkExplorer->moveTo($x, $y, $z, false) === SubChunkExplorerStatus::INVALID){
|
||||
return;
|
||||
}
|
||||
$chunk = $this->subChunkExplorer->currentChunk;
|
||||
|
@ -55,7 +55,10 @@ class SubChunkExplorer{
|
||||
$this->world = $world;
|
||||
}
|
||||
|
||||
public function moveTo(int $x, int $y, int $z, bool $create) : bool{
|
||||
/**
|
||||
* @phpstan-return SubChunkExplorerStatus::*
|
||||
*/
|
||||
public function moveTo(int $x, int $y, int $z, bool $create) : int{
|
||||
if($this->currentChunk === null or $this->currentX !== ($x >> 4) or $this->currentZ !== ($z >> 4)){
|
||||
$this->currentX = $x >> 4;
|
||||
$this->currentZ = $z >> 4;
|
||||
@ -63,7 +66,7 @@ class SubChunkExplorer{
|
||||
|
||||
$this->currentChunk = $this->world->getChunk($this->currentX, $this->currentZ, $create);
|
||||
if($this->currentChunk === null){
|
||||
return false;
|
||||
return SubChunkExplorerStatus::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +75,7 @@ class SubChunkExplorer{
|
||||
|
||||
if($this->currentY < 0 or $this->currentY >= $this->currentChunk->getHeight()){
|
||||
$this->currentSubChunk = null;
|
||||
return false;
|
||||
return SubChunkExplorerStatus::INVALID;
|
||||
}
|
||||
|
||||
$newSubChunk = $this->currentChunk->getSubChunk($y >> 4);
|
||||
@ -81,12 +84,16 @@ class SubChunkExplorer{
|
||||
if($this->onSubChunkChangeFunc !== null){
|
||||
($this->onSubChunkChangeFunc)();
|
||||
}
|
||||
return SubChunkExplorerStatus::MOVED;
|
||||
}
|
||||
|
||||
return true;
|
||||
return SubChunkExplorerStatus::OK;
|
||||
}
|
||||
|
||||
public function moveToChunk(int $chunkX, int $chunkY, int $chunkZ, bool $create) : bool{
|
||||
/**
|
||||
* @phpstan-return SubChunkExplorerStatus::*
|
||||
*/
|
||||
public function moveToChunk(int $chunkX, int $chunkY, int $chunkZ, bool $create) : int{
|
||||
//this is a cold path, so we don't care much if it's a bit slower (extra fcall overhead)
|
||||
return $this->moveTo($chunkX << 4, $chunkY << 4, $chunkZ << 4, $create);
|
||||
}
|
||||
|
37
src/world/utils/SubChunkExplorerStatus.php
Normal file
37
src/world/utils/SubChunkExplorerStatus.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\world\utils;
|
||||
|
||||
final class SubChunkExplorerStatus{
|
||||
private function __construct(){
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/** We encountered terrain not accessible by the current terrain provider */
|
||||
public const INVALID = 0;
|
||||
/** We remained inside the same (sub)chunk */
|
||||
public const OK = 1;
|
||||
/** We moved to a different (sub)chunk */
|
||||
public const MOVED = 2;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user