Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/pocketmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ chunk-ticking:
#Number of blocks inside ticking areas' subchunks that get ticked every tick. Higher values will accelerate events
#like tree and plant growth, but at a higher performance cost.
blocks-per-subchunk-per-tick: 3
blocks-per-subchunk-per-world-per-tick:
# List of worlds with custom blocks-per-subchunk-per-tick values
# world: 5
#IDs of blocks not to perform random ticking on.
disable-block-ticking:
#- grass
Expand Down
1 change: 1 addition & 0 deletions src/YmlServerProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private function __construct(){
public const CHUNK_SENDING_SPAWN_RADIUS = 'chunk-sending.spawn-radius';
public const CHUNK_TICKING = 'chunk-ticking';
public const CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_TICK = 'chunk-ticking.blocks-per-subchunk-per-tick';
public const CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_WORLD_PER_TICK = 'chunk-ticking.blocks-per-subchunk-per-world-per-tick';
public const CHUNK_TICKING_DISABLE_BLOCK_TICKING = 'chunk-ticking.disable-block-ticking';
public const CHUNK_TICKING_TICK_RADIUS = 'chunk-ticking.tick-radius';
public const CONSOLE = 'console';
Expand Down
44 changes: 44 additions & 0 deletions src/event/world/WorldTickedBlocksChangeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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\event\world;

use pocketmine\world\World;

class WorldTickedBlocksChangeEvent extends WorldEvent{
public function __construct(
World $world,
private int $oldNumber,
private int $newNumber
){
parent::__construct($world);
}

public function getOldNumberOfBlocks() : int{
return $this->oldNumber;
}

public function getNewNumberOfBlocks() : int{
return $this->newNumber;
}
}
34 changes: 33 additions & 1 deletion src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use pocketmine\event\world\WorldParticleEvent;
use pocketmine\event\world\WorldSaveEvent;
use pocketmine\event\world\WorldSoundEvent;
use pocketmine\event\world\WorldTickedBlocksChangeEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser;
Expand Down Expand Up @@ -119,6 +120,8 @@
use function get_class;
use function gettype;
use function is_a;
use function is_array;
use function is_int;
use function is_object;
use function lcg_value;
use function max;
Expand Down Expand Up @@ -520,7 +523,7 @@ public function __construct(
$this->logger->warning("\"chunk-ticking.per-tick\" setting is deprecated, but you've used it to disable chunk ticking. Set \"chunk-ticking.tick-radius\" to 0 in \"pocketmine.yml\" instead.");
$this->chunkTickRadius = 0;
}
$this->tickedBlocksPerSubchunkPerTick = $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_TICK, self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK);
$this->initTickedBlocksPerSubchunkPerTick($cfg);
$this->maxConcurrentChunkPopulationTasks = $cfg->getPropertyInt(YmlServerProperties::CHUNK_GENERATION_POPULATION_QUEUE_SIZE, 2);

$this->initRandomTickBlocksFromConfig($cfg);
Expand Down Expand Up @@ -3461,4 +3464,33 @@ public function unloadChunks(bool $force = false) : void{
}
}
}

private function initTickedBlocksPerSubchunkPerTick(ServerConfigGroup $cfg) : void {
$defaultTick = $cfg->getPropertyInt(YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_TICK, self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK);
$worlds = $cfg->getProperty(YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_WORLD_PER_TICK, []);
if(!is_array($worlds)){
throw new \InvalidArgumentException("Expected array for " . YmlServerProperties::CHUNK_TICKING_BLOCKS_PER_SUBCHUNK_PER_WORLD_PER_TICK . " but got " . gettype($worlds));
}
foreach($worlds as $world => $blocksPerTick){
if($world === $this->getFolderName()){
if(is_int($blocksPerTick) && $blocksPerTick >= 0){
$this->setTickedBlocksPerSubchunkPerTick($blocksPerTick);
return;
}
}
}
$this->setTickedBlocksPerSubchunkPerTick($defaultTick);
}

public function setTickedBlocksPerSubchunkPerTick(int $tickedBlocksPerSubchunkPerTick) : void{
$old = $this->tickedBlocksPerSubchunkPerTick ?? null;
$this->tickedBlocksPerSubchunkPerTick = $tickedBlocksPerSubchunkPerTick;
if($old !== null){
(new WorldTickedBlocksChangeEvent($this, $old, $tickedBlocksPerSubchunkPerTick))->call();
}
}

public function getTickedBlocksPerSubchunkPerTick() : int{
return $this->tickedBlocksPerSubchunkPerTick;
}
}