disable-block-ticking directive now supports names a la /give

This commit is contained in:
Dylan K. Taylor 2022-01-07 21:06:06 +00:00
parent 0bc578b8fc
commit 3faeb5a556
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 25 additions and 4 deletions

View File

@ -128,7 +128,9 @@ chunk-ticking:
blocks-per-subchunk-per-tick: 3
#IDs of blocks not to perform random ticking on.
disable-block-ticking:
#- 2 # grass
#- grass
#- ice
#- fire
chunk-generation:
#Max. amount of chunks in the waiting queue to be populated

View File

@ -54,6 +54,7 @@ use pocketmine\event\world\WorldSaveEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser;
use pocketmine\item\StringToItemParser;
use pocketmine\item\VanillaItems;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\math\AxisAlignedBB;
@ -95,7 +96,6 @@ use pocketmine\world\sound\BlockPlaceSound;
use pocketmine\world\sound\Sound;
use pocketmine\world\utils\SubChunkExplorer;
use function abs;
use function array_fill_keys;
use function array_filter;
use function array_key_exists;
use function array_map;
@ -118,6 +118,7 @@ use function morton2d_encode;
use function morton3d_decode;
use function morton3d_encode;
use function mt_rand;
use function preg_match;
use function spl_object_id;
use function strtolower;
use function trim;
@ -453,10 +454,28 @@ class World implements ChunkManager{
$this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt("chunk-ticking.blocks-per-subchunk-per-tick", self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK);
$this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt("chunk-generation.population-queue-size", 2);
$dontTickBlocks = array_fill_keys($cfg->getProperty("chunk-ticking.disable-block-ticking", []), true);
$dontTickBlocks = [];
$parser = StringToItemParser::getInstance();
foreach($cfg->getProperty("chunk-ticking.disable-block-ticking", []) as $name){
$name = (string) $name;
$item = $parser->parse($name);
if($item !== null){
$block = $item->getBlock();
}elseif(preg_match("/^-?\d+$/", $name) === 1){
$block = BlockFactory::getInstance()->get((int) $name, 0);
}else{
//TODO: we probably ought to log an error here
continue;
}
if($block->getId() !== BlockLegacyIds::AIR){
$dontTickBlocks[$block->getTypeId()] = $name;
}
}
foreach(BlockFactory::getInstance()->getAllKnownStates() as $state){
if(!isset($dontTickBlocks[$state->getId()]) and $state->ticksRandomly()){
$dontTickName = $dontTickBlocks[$state->getTypeId()] ?? null;
if($dontTickName === null && !$state->ticksRandomly()){
$this->randomTickBlocks[$state->getFullId()] = true;
}
}