aternosorg / thanos

PHP library to automatically detect and remove unused chunks from Minecraft worlds.
https://packagist.org/packages/aternos/thanos
MIT License
221 stars 20 forks source link

Thanos trying to get the inhabited time of null #1

Closed JulianVennen closed 5 years ago

JulianVennen commented 5 years ago

I just tested thanos on a world and got the following error:

Fatal error: Uncaught Error: Call to a member function getInhabitedTime() on null in C:\Users\julia\Desktop\Coding\Minecraft\thanos\vendor\aternos\thanos\src\Thanos.php:49
Stack trace:
#0 C:\Users\julia\Desktop\Coding\Minecraft\thanos\thanos.php(42): Aternos\Thanos\Thanos->snap(Object(Aternos\Thanos\World\AnvilWorld))
#1 {main}
  thrown in C:\Users\julia\Desktop\Coding\Minecraft\thanos\vendor\aternos\thanos\src\Thanos.php on line 49

i changed the snap function from

public function snap(WorldInterface $world): int
    {
        $world->copyOtherFiles();
        $removedChunks = 0;
        foreach ($world as $chunk) {
              $time = $chunk->getInhabitedTime();
              if ($time > $this->minInhabitedTime || $time === -1) {
                  $chunk->save();
              } else {
                  $removedChunks++;
              }
        }
        return $removedChunks;
    }

to

public function snap(WorldInterface $world): int
    {
        $world->copyOtherFiles();
        $removedChunks = 0;
        foreach ($world as $chunk) {
            if(!$chunk == null){
              $time = $chunk->getInhabitedTime();
              if ($time > $this->minInhabitedTime || $time === -1) {
                  $chunk->save();
              } else {
                  $removedChunks++;
              }
            }
        }
        return $removedChunks;
    }

and after doing that it worked.

KurtThiemann commented 5 years ago

Hi, Generally, $chunk should never be null. Are you sure you are using the latest version (v0.1.1) of Thanos?

If updating does not solve the problem, please send me the Minecraft world the problem occurs with.

JulianVennen commented 5 years ago

i used the newest version of thanos and here is my world(send to a zip): https://www.dropbox.com/s/buux7ef5nmb735r/world.zip?dl=0