PHP code example of aternos / hawk

1. Go to this page and download the library: Download aternos/hawk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aternos / hawk example snippets


$file = new File("your/region/file");

$file = new File();
$file->setContent(file_get_contents("your/region/file"));
$file->setFileName("your/file/name");
"...do stuff here..."
$contentToBeWritten = $file->getContent();

// New block coordinates
$blockPos = new McCoordinates3D(1, 2, 3);

// Path to your region file and calculating the filename from the coordinates
$inputPath = "/your/world/region/directory";
$blockFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock($blockPos));

// Instantiating Hawk only with blockFiles
$hawk = new Hawk(blockFiles: $blockFiles);

// New entity coordinates
$entityPos = new McCoordinatesFloat(1.2, 2.3, 3.4);

// Path to your region file and calculating the filename from the coordinates
$inputPath = "/your/world/region/directory";
$entitiesFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)));

// Instantiating Hawk only with blockFiles because entities used to be in the same file
$hawk = new Hawk(blockFiles: $entitiesFiles);

// Path to your entities directory and calculating the filename from the coordinates
$inputPath = "/your/world/entities/directory";
$entitiesFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)));

$hawk = new Hawk(entitiesFiles: $entitiesFiles);

$block = $hawk->getBlock($blockPos);

$hawk->replaceBlock($blockPos, "minecraft:wool");
$hawk->save();

$entities = $hawk->getAllEntitiesFromChunk(McCoordinatesFloat::get3DCoordinates($entityPos));

$entities = $hawk->getEntities($entityName,$entityPos);

$entities = $hawk->getEntities($entityName,$entityPos);
$hawk->deleteEntity($entities[0]);
$hawk->save();


$entities = $hawk->getAllBlockEntitiesFromChunk(McCoordinatesFloat::get3DCoordinates($entityPos));

$entities = $hawk->getBlockEntities($entityName,$entityPos);

$entities = $hawk->getBlockEntities($entityName,$entityPos);
$hawk->deleteBlockEntity($entities[0]);
$hawk->save();