-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 53d908e
Showing
21 changed files
with
1,291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2018-2024 Aternos GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
This is a small Minecraft tool written in PHP to fix missing end or nether dimension compound tags in the level.dat file. If the tags are missing, the portals do not work. | ||
|
||
# Usage CLI | ||
|
||
```bash | ||
php repair.php input_file [output_file] | ||
``` | ||
|
||
If no output file path is given, the output directory is the current directory. | ||
|
||
# Usage PHP code | ||
|
||
```php | ||
$fileName = 'level.dat' | ||
$fileContent = file_get_contents($filename) | ||
$creabit = new Creabit($fileContent) | ||
file_put_contents($fileName, $creabit->repair()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "aternos/creabit", | ||
"description": "This is a small Minecraft tool written in PHP to fix missing end or nether dimension compound tags in the level.dat file.", | ||
"type": "library", | ||
"license": "MIT", | ||
"require": { | ||
"aternos/nbt": "^1.4.1", | ||
"ext-readline": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Aternos\\Creabit\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Riccardo", | ||
"email": "[email protected]" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
require_once "vendor/autoload.php"; | ||
|
||
use Aternos\Creabit\Creabit; | ||
use Aternos\Creabit\Enums\DimensionType; | ||
use Aternos\Creabit\Enums\SettingsType; | ||
use Aternos\Creabit\Enums\GeneratorType; | ||
|
||
if (!isset($argc)) { | ||
echo "argc and argv disabled. check php.ini\n"; | ||
return; | ||
} | ||
|
||
$no = ["N", "n"]; | ||
|
||
function setup(string $filename): Creabit { | ||
if (!file_exists($filename)) { | ||
echo "input file does not exist\n"; | ||
exit; | ||
} | ||
$filePtr = fopen($filename, "r"); | ||
$fileContent = fread($filePtr, filesize($filename)); | ||
fclose($filePtr); | ||
return new Creabit($fileContent); | ||
} | ||
|
||
switch ($argc) { | ||
case 1: | ||
echo "too few params given. choose:\n1 argument:\n\t1: path of input file -> output is current dir\n2 arguments:\n\t1: path of input file\n\t2: path of output file\n"; | ||
return; | ||
|
||
case 2: | ||
$levelRepairer = setup($argv[1]); | ||
$writtenBytes = file_put_contents("new_level.dat", $levelRepairer->repair()); | ||
break; | ||
case 3: | ||
$levelRepairer = setup($argv[1]); | ||
$fileName = $argv[2]; | ||
if (!file_exists(dirname($argv[2]))) mkdir(dirname($argv[2]), recursive: true); | ||
if (file_exists($argv[2]) === true) { | ||
$answer = readline("output file does already exist.\ndo you want to overwrite it?(Y/n)\n"); | ||
if (in_array($answer, $no)) { | ||
while (file_exists($fileName)) { | ||
$numeric = substr($fileName, strlen($argv[2])); | ||
if (!empty($numeric)) $fileName = $argv[2] . strval(intval($numeric) + 1); | ||
else $fileName = $fileName . "1"; | ||
} | ||
} | ||
} | ||
$writtenBytes = file_put_contents($fileName, $levelRepairer->repair()); | ||
break; | ||
default: | ||
echo "too many params given. choose:\n1 argument:\n\t1: path of input file -> output is current dir\n2 arguments:\n\t1: path of input file\n\t2: path of output file\n"; | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Aternos\Creabit; | ||
|
||
use Aternos\Nbt\Tag\CompoundTag; | ||
use Aternos\Nbt\Tag\StringTag; | ||
use Exception; | ||
use Aternos\Creabit\Enums\BiomeSourceType; | ||
|
||
class BiomeSource | ||
{ | ||
protected ?Preset $preset; | ||
|
||
protected Seed $seed; | ||
|
||
protected Type $type; | ||
|
||
/** | ||
* Overloaded | ||
*/ | ||
protected function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param CompoundTag $tag | ||
* @return static | ||
*/ | ||
public static function newFromTag(CompoundTag $tag): static | ||
{ | ||
$biomeSource = new static(); | ||
$biomeSource->type = Type::newFromTag($tag->getString("type")); | ||
|
||
$presetString = $tag->getString("preset"); | ||
$biomeSource->preset = $presetString ? Preset::newFromTag($presetString) : null; | ||
|
||
$seed = $tag->getLong("seed"); | ||
if ($seed !== null) { | ||
$biomeSource->seed = new Seed($seed->getValue()); | ||
} | ||
|
||
return $biomeSource; | ||
} | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param BiomeSourceType $type | ||
* @param Seed|null $seed | ||
* @param Preset|null $preset | ||
* @return static | ||
*/ | ||
public static function new(BiomeSourceType $type, Seed $seed = null, Preset $preset = null): static | ||
{ | ||
$biomeSource = new static(); | ||
$biomeSource->type = Type::newBiomeSourceType($type); | ||
if ($seed !== null) { | ||
$biomeSource->seed = $seed; | ||
} | ||
if ($preset !== null) { | ||
$biomeSource->preset = $preset; | ||
} | ||
return $biomeSource; | ||
} | ||
|
||
/** | ||
* @return Preset|null | ||
*/ | ||
public function getPreset(): ?Preset | ||
{ | ||
return $this->preset; | ||
} | ||
|
||
/** | ||
* @return Type | ||
*/ | ||
public function getType(): Type | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @return Seed | ||
*/ | ||
public function getSeed(): Seed | ||
{ | ||
return $this->seed; | ||
} | ||
|
||
/** | ||
* Creates "biome_source" tag | ||
* | ||
* @return CompoundTag | ||
* @throws Exception | ||
*/ | ||
public function createTag(): CompoundTag | ||
{ | ||
$tag = new CompoundTag(); | ||
$tag["type"] = $this->getType()->createTag(); | ||
if (isset($this->seed)) { | ||
$tag["seed"] = $this->getSeed()->createTag(); | ||
} | ||
if (isset($this->preset)) { | ||
$tag["preset"] = (new StringTag())->setValue($this->getPreset()->getName()); | ||
} | ||
return $tag; | ||
} | ||
} |
Oops, something went wrong.