Skip to content

Commit

Permalink
Merge remote-tracking branch 'pmmp/minor-next' into stable
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/world/World.php
  • Loading branch information
DavyCraft648 committed Oct 27, 2023
2 parents a51fd47 + b41960d commit 9898901
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,13 @@ public function generateStatePermutations() : \Generator{

/**
* Called when this block is created, set, or has a neighbouring block update, to re-detect dynamic properties which
* are not saved on the world.
*
* Clears any cached precomputed objects, such as bounding boxes. Remove any outdated precomputed things such as
* AABBs and force recalculation.
* are not saved in the blockstate ID.
* If any such properties are updated, don't forget to clear things like AABB caches if necessary.
*
* A replacement block may be returned. This is useful if the block type changed due to reading of world data (e.g.
* data from a block entity).
*/
public function readStateFromWorld() : Block{
$this->collisionBoxes = null;

return $this;
}

Expand Down Expand Up @@ -612,6 +608,7 @@ final public function getPosition() : Position{
*/
final public function position(World $world, int $x, int $y, int $z) : void{
$this->position = new Position($x, $y, $z, $world);
$this->collisionBoxes = null;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/block/Door.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();

$this->collisionBoxes = null;

//copy door properties from other half
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door && $other->hasSameTypeId($this)){
Expand Down
2 changes: 2 additions & 0 deletions src/block/Fence.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function getThickness() : float{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();

$this->collisionBoxes = null;

foreach(Facing::HORIZONTAL as $facing){
$block = $this->getSide($facing);
if($block instanceof static || $block instanceof FenceGate || $block->getSupportType(Facing::opposite($facing)) === SupportType::FULL){
Expand Down
2 changes: 2 additions & 0 deletions src/block/Stair.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();

$this->collisionBoxes = null;

$clockwise = Facing::rotateY($this->facing, true);
if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){
$this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT;
Expand Down
2 changes: 2 additions & 0 deletions src/block/Thin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Thin extends Transparent{
public function readStateFromWorld() : Block{
parent::readStateFromWorld();

$this->collisionBoxes = null;

foreach(Facing::HORIZONTAL as $facing){
$side = $this->getSide($facing);
if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){
Expand Down
2 changes: 1 addition & 1 deletion src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ public function getXpDropAmount() : int{
}

protected function checkGroundState(float $wantedX, float $wantedY, float $wantedZ, float $dx, float $dy, float $dz) : void{
if($this->isSpectator()){
if($this->gamemode === GameMode::SPECTATOR){
$this->onGround = false;
}else{
$bb = clone $this->boundingBox;
Expand Down
13 changes: 4 additions & 9 deletions src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,7 @@ protected function actuallyDoTick(int $currentTick) : void{
$this->providerGarbageCollectionTicker = 0;
}

//Do block updates
$this->timings->scheduledBlockUpdates->startTiming();

//Delayed updates
while($this->scheduledBlockUpdateQueue->count() > 0 && $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){
/** @var Vector3 $vec */
Expand All @@ -1034,7 +1032,9 @@ protected function actuallyDoTick(int $currentTick) : void{
$block->onScheduledUpdate();
}
}
$this->timings->scheduledBlockUpdates->stopTiming();

$this->timings->neighbourBlockUpdates->startTiming();
//Normal updates
while($this->neighbourBlockUpdateQueue->count() > 0){
$index = $this->neighbourBlockUpdateQueue->dequeue();
Expand All @@ -1045,12 +1045,7 @@ protected function actuallyDoTick(int $currentTick) : void{
}

foreach([0, 1] as $layer){
$block = $this->getBlockAtLayer($x, $y, $z, $layer);
$replacement = $block->readStateFromWorld(); //for blocks like fences, force recalculation of connected AABBs
if($replacement !== $block){
$replacement->position($this, $x, $y, $z);
$block = $replacement;
}
$block = $this->getBlockAt($x, $y, $z);

if(BlockUpdateEvent::hasHandlers()){
$ev = new BlockUpdateEvent($block);
Expand All @@ -1066,7 +1061,7 @@ protected function actuallyDoTick(int $currentTick) : void{
}
}

$this->timings->scheduledBlockUpdates->stopTiming();
$this->timings->neighbourBlockUpdates->stopTiming();

$this->timings->entityTick->startTiming();
//Update entities that need update
Expand Down
2 changes: 2 additions & 0 deletions src/world/WorldTimings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class WorldTimings{

public TimingsHandler $doChunkUnload;
public TimingsHandler $scheduledBlockUpdates;
public TimingsHandler $neighbourBlockUpdates;
public TimingsHandler $randomChunkUpdates;
public TimingsHandler $randomChunkUpdatesChunkSelection;
public TimingsHandler $doChunkGC;
Expand Down Expand Up @@ -77,6 +78,7 @@ public function __construct(World $world){

$this->doChunkUnload = self::newTimer($name, "Unload Chunks");
$this->scheduledBlockUpdates = self::newTimer($name, "Scheduled Block Updates");
$this->neighbourBlockUpdates = self::newTimer($name, "Neighbour Block Updates");
$this->randomChunkUpdates = self::newTimer($name, "Random Chunk Updates");
$this->randomChunkUpdatesChunkSelection = self::newTimer($name, "Random Chunk Updates - Chunk Selection");
$this->doChunkGC = self::newTimer($name, "Garbage Collection");
Expand Down

0 comments on commit 9898901

Please sign in to comment.