World: never delete entities in setChunk()

entities exist completely independently from chunks now, so there is no need to interact with them whatsoever.
As I wrote in #4520, there's no sense in deleting entities here, since a chunk replacement is essentially just a mass block update.

On that theme, it might be a good idea to call Entity->onNearbyBlockChange() for all entities in the target and adjacent chunks when replacing a chunk, to ensure that they get the proper movement updates.
This commit is contained in:
Dylan K. Taylor 2021-10-28 23:42:28 +01:00
parent d78801b9d5
commit c66790b6a6
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2125,18 +2125,13 @@ class World implements ChunkManager{
}
/**
* @param bool $deleteEntitiesAndTiles Whether to delete entities and tiles on the old chunk, or transfer them to the new one
* @param bool $deleteTiles Whether to delete tiles on the old chunk, or transfer them to the new one
*/
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk, bool $deleteEntitiesAndTiles = true) : void{
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk, bool $deleteTiles = true) : void{
$chunkHash = World::chunkHash($chunkX, $chunkZ);
$oldChunk = $this->loadChunk($chunkX, $chunkZ);
if($oldChunk !== null and $oldChunk !== $chunk){
if($deleteEntitiesAndTiles){
foreach($this->getChunkEntities($chunkX, $chunkZ) as $entity){
if(!($entity instanceof Player)){
$entity->close();
}
}
if($deleteTiles){
foreach($oldChunk->getTiles() as $tile){
$tile->close();
}