-
Notifications
You must be signed in to change notification settings - Fork 4
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
Showing
18 changed files
with
718 additions
and
189 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,114 @@ | ||
<?php | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
use Aternos\Hawk\File; | ||
use Aternos\Hawk\Hawk; | ||
use Aternos\Hawk\McCoordinatesFloat; | ||
use Aternos\Hawk\Region; | ||
|
||
|
||
if (!isset($argc)) { | ||
echo "argc and argv disabled. check php.ini " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$yes = ["Y", "y", false]; | ||
$no = ["N", "n"]; | ||
|
||
switch ($argc) { | ||
case 1: | ||
case 2: | ||
case 3: | ||
echo "too few params given. | ||
\targument 1: path of world folder " . PHP_EOL . " | ||
\targument 2: name of block entity e.g. 'minecraft:chest' " . PHP_EOL . " | ||
\targument 3: block entity coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
|
||
case 4: | ||
if (!file_exists($argv[1])) { | ||
echo "directory does not exist. " . PHP_EOL; | ||
return; | ||
} | ||
break; | ||
|
||
default: | ||
echo "too many params given. choose: " . PHP_EOL . " | ||
\targument 1: path of world folder " . PHP_EOL . " | ||
\targument 2: name of block entity e.g. 'minecraft:chest' " . PHP_EOL . " | ||
\targument 3: block entity coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$inputPath = $argv[1]; | ||
$entityName = $argv[2]; | ||
$coordinates = explode(",", $argv[3]); | ||
if (count($coordinates) !== 3) { | ||
echo "Wrong coordinates " . PHP_EOL; | ||
return; | ||
} | ||
$entityPos = new McCoordinatesFloat($coordinates[0], $coordinates[1], $coordinates[2]); | ||
|
||
$fileName = Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)); | ||
$blockPath = $inputPath . "/region/" . $fileName; | ||
|
||
$blockFiles = (file_exists($blockPath)) ? [new File($blockPath)] : []; | ||
|
||
$hawk = new Hawk(blockFiles: $blockFiles); | ||
$entities = $hawk->getBlockEntities($entityName, $entityPos); | ||
switch (count($entities)) { | ||
case 0: | ||
throw new Exception("How did you get here?"); | ||
case 1: | ||
$hawk->deleteBlockEntity($entities[0]); | ||
echo "1 entity deleted " . PHP_EOL; | ||
save(); | ||
return; | ||
default: | ||
$count = count($entities); | ||
foreach ($entities as $index => $entity) { | ||
echo $index . ": " . $entity->getName() . " at " . $entity->getCoordinates() . " " . PHP_EOL; | ||
} | ||
echo $count . ": delete all " . PHP_EOL; | ||
$answer = ""; | ||
while (true) { | ||
$answer = readline("Choose which entity will be deleted. -1 will cancel. " . PHP_EOL); | ||
if (!is_numeric($answer) || intval($answer) > $count) { | ||
echo "Wrong input try again. " . PHP_EOL; | ||
continue; | ||
} | ||
switch (intval($answer)) { | ||
case -1: | ||
echo "Exiting... " . PHP_EOL; | ||
closeFiles(); | ||
return; | ||
case $count: | ||
foreach ($entities as $entity) { | ||
$hawk->deleteBlockEntity($entity); | ||
} | ||
save(); | ||
return; | ||
default: | ||
$hawk->deleteBlockEntity($entities[intval($answer)]); | ||
save(); | ||
return; | ||
} | ||
|
||
} | ||
} | ||
|
||
function save(): void | ||
{ | ||
global $hawk; | ||
$hawk->save(); | ||
closeFiles(); | ||
} | ||
|
||
function closeFiles(): void | ||
{ | ||
global $blockFiles; | ||
foreach ($blockFiles as $file) { | ||
$file->close(); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
use Aternos\Hawk\Chunk; | ||
use Aternos\Hawk\File; | ||
use Aternos\Hawk\Hawk; | ||
use Aternos\Hawk\McCoordinates3D; | ||
use Aternos\Hawk\Region; | ||
|
||
|
||
if (!isset($argc)) { | ||
echo "argc and argv disabled. check php.ini " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$yes = ["Y", "y", false]; | ||
$no = ["N", "n"]; | ||
|
||
switch ($argc) { | ||
case 1: | ||
case 2: | ||
echo "too few params given. | ||
\targument 1: path of world folder " . PHP_EOL . " | ||
\targument 2: block coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
|
||
case 3: | ||
if (!file_exists($argv[1])) { | ||
echo "$argv[1] does not exist. " . PHP_EOL; | ||
return; | ||
} | ||
break; | ||
|
||
default: | ||
echo "too many params given. choose: " . PHP_EOL . " | ||
\targument 1: path of word folder " . PHP_EOL . " | ||
\targument 2: block coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$inputPath = $argv[1]; | ||
$coordinates = explode(",", $argv[2]); | ||
if(count($coordinates) !== 3){ | ||
echo "Wrong coordinates " . PHP_EOL; | ||
return; | ||
} | ||
$blockPos = new McCoordinates3D($coordinates[0], $coordinates[1], $coordinates[2]); | ||
|
||
$fileName = Region::getRegionFileNameFromBlock($blockPos); | ||
$blockPath = $inputPath . "/region/" . $fileName; | ||
|
||
$blockFiles = (file_exists($blockPath)) ? [new File($blockPath)] : []; | ||
|
||
$hawk = new Hawk(blockFiles: $blockFiles); | ||
$entities = $hawk->getAllBlockEntitiesFromChunk($blockPos); | ||
foreach ($entities as $entity){ | ||
echo $entity . " " . PHP_EOL; | ||
} | ||
echo count($entities) . " entities in chunk " . Chunk::getChunkCoordinatesFromBlock($blockPos) . " " . PHP_EOL; | ||
|
||
// Close files | ||
|
||
foreach ($blockFiles as $file){ | ||
$file->close(); | ||
} |
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,76 @@ | ||
<?php | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
|
||
use Aternos\Hawk\File; | ||
use Aternos\Hawk\Hawk; | ||
use Aternos\Hawk\McCoordinatesFloat; | ||
use Aternos\Hawk\Region; | ||
|
||
|
||
if (!isset($argc)) { | ||
echo "argc and argv disabled. check php.ini " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$yes = ["Y", "y", false]; | ||
$no = ["N", "n"]; | ||
|
||
switch ($argc) { | ||
case 1: | ||
case 2: | ||
case 3: | ||
echo "too few params given. | ||
\targument 1: path of world folder " . PHP_EOL . " | ||
\targument 2: name of block entity e.g. 'minecraft:chest' " . PHP_EOL . " | ||
\targument 3: block entity coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
|
||
case 4: | ||
if (!file_exists($argv[1])) { | ||
echo "directory does not exist. " . PHP_EOL; | ||
return; | ||
} | ||
break; | ||
|
||
default: | ||
echo "too many params given. | ||
\targument 1: path of world folder " . PHP_EOL . " | ||
\targument 2: name of block entity e.g. 'minecraft:chest' " . PHP_EOL . " | ||
\targument 3: block entity coordinates(x,y,z) " . PHP_EOL; | ||
return; | ||
} | ||
|
||
$inputPath = $argv[1]; | ||
$entityName = $argv[2]; | ||
$coordinates = explode(",", $argv[3]); | ||
if(count($coordinates) !== 3){ | ||
echo "Wrong coordinates " . PHP_EOL; | ||
return; | ||
} | ||
$entityPos = new McCoordinatesFloat($coordinates[0], $coordinates[1], $coordinates[2]); | ||
|
||
$fileName = Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)); | ||
$blockPath = $inputPath . "/region/" . $fileName; | ||
|
||
$blockFiles = (file_exists($blockPath)) ? [new File($blockPath)] : []; | ||
|
||
$hawk = new Hawk(blockFiles: $blockFiles); | ||
$entities = $hawk->getBlockEntities($entityName,$entityPos); | ||
|
||
foreach ($entities as $index => $entity) { | ||
echo $index . ": " . $entity->getName() . " at " . $entity->getCoordinates() . " " . PHP_EOL; | ||
} | ||
|
||
$count = count($entities); | ||
$message = " entity found " . PHP_EOL; | ||
if($count !== 1){ | ||
$message = " entities found " . PHP_EOL; | ||
} | ||
echo $count . $message; | ||
|
||
// Close files | ||
|
||
foreach ($blockFiles as $file){ | ||
$file->close(); | ||
} |
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
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
Oops, something went wrong.