GithubHelp home page GithubHelp logo

jamestiotio / thanos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aternosorg/thanos

0.0 1.0 0.0 54 KB

PHP library to automatically detect and remove unused chunks from Minecraft worlds.

Home Page: https://packagist.org/packages/aternos/thanos

License: MIT License

PHP 100.00%

thanos's Introduction

Thanos

About

Thanos is a PHP library to automatically detect and remove unused chunks from Minecraft worlds. This can reduce the file size of a world by more than 50%.

Other than existing tools, this library does not use blocklists. Instead, the inhabited time value is used to determine whether a chunk is used or not. This prevents used chunks from sometimes being removed by accident and makes this library compatible with most mods and plugins.

Currently, only the Minecraft Anvil world format (Minecraft Java Edition) is supported.

Installation

composer require aternos/thanos

Usage

CLI tool

This library includes a simple cli tool.

./thanos.php /path/to/world/directory [/path/to/output/directory]

Worlds

A world object represents a Minecraft world with all its files. It allows iteration over all chunks and provides a function to copy all non-region files to the output directory.

$world = new Aternos\Thanos\World\AnvilWorld("/path/to/world/directory", "/path/to/output/directory");
$world->copyOtherFiles(); //copy non-region files

foreach ($world as $chunk){
  echo $chunk->getInhabitedTime() . "\n"; //output inhabited time for each chunk
}

After iterating over all chunks of a region file, it will be automatically saved to the output directory.

Methods

getPath() : string Get world directory path

getDestination() : string Get world output directory

getOtherFiles() : string[] Get all files, that are not region directories

copyOtherFiles() : void Copy all files, that are not region directories, to the output directory

static isWorld(string $path) : bool Check if $path is world directory

Chunks

A chunk object represents a Minecraft world chunk. Due to performance reasons, chunk data is not completely parsed but only used to find metadata that helps to determine whether a chunk is used.

if($chunk->getInhabitedTime() > 0){
  $chunk->save();
}

If a chunk is not marked as saved, it will not be written to the output directory.

Methods

getOffset() : int Get offset of chunk data within the region file

getLength() : int Get length of raw chunk data

getData() : string Get raw chunk data

getInhabitedTime() : int Get InhabitedTime value from chunk data. Returns -1 if InhabitedTime could not be read.

getLastUpdate() : int Get LastUpdate value from chunk data. Returns -1 if LastUpdate could not be read.

setTimestamp(int $timestamp) : void Set last modification time

getTimestamp() : int Get last modification time

save() : void Mark chunk as saved

isSaved() : bool Check whether this chunk is marked as saved

Thanos

Thanos automatically finds unused chunks in a world and reduces them to atoms.

$thanos = new Aternos\Thanos\Thanos();
$thanos->setMaxInhabitedTime(0);
$world = new Aternos\Thanos\World\AnvilWorld("/path/to/world/directory", "/path/to/output/directory");
$removedChunks = $thanos->snap($world);
echo "Removed $removedChunks chunks\n";

Methods

setMinInhabitedTime(int $minInhabitedTime) : void Set min inhabited time for a chunk to not be removed

getMinInhabitedTime() : int Get min inhabited time

snap(WorldInterface $world) : int Remove unused chunks, returns the amount of chunks removed

thanos's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.