diff --git a/.gitignore b/.gitignore index 930a7b2..08c198e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ vendor/ .idea/ tests/files/ create_versions_folder.php -src/Versions/v1139 src/Versions/v1241 src/Versions/v1343 \ No newline at end of file diff --git a/README.md b/README.md index e82a826..0d611f7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,10 @@ Hawk is a PHP library to get and/or replace blocks and get and/or delete entities in Minecraft region files. This allows the user to replace blocks or delete entities that will crash the server when loaded. -Currently, only the Minecraft Anvil world format (Minecraft Java Edition Version 1.16+) is supported. +Currently, following versions are supported: + + 1.12+ for entities + 1.16+ for blocks ### Installation @@ -43,7 +46,7 @@ $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); +$blockFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock($blockPos)); // Instantiating Hawk only with blockFiles $hawk = new Hawk(blockFiles: $blockFiles); @@ -57,7 +60,7 @@ $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)); +$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); @@ -68,7 +71,7 @@ Setup for entities starting from 1.17: ```php // 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)); +$entitiesFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos))); $hawk = new Hawk(entitiesFiles: $entitiesFiles); ``` diff --git a/examples/resources/versions/1.12(1139)/region/r.-1.-1.mca b/examples/resources/versions/1.12(1139)/region/r.-1.-1.mca new file mode 100644 index 0000000..afd51d5 Binary files /dev/null and b/examples/resources/versions/1.12(1139)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.12(1139)/region/r.-1.0.mca b/examples/resources/versions/1.12(1139)/region/r.-1.0.mca new file mode 100644 index 0000000..0875aab Binary files /dev/null and b/examples/resources/versions/1.12(1139)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.12(1139)/region/r.0.-1.mca b/examples/resources/versions/1.12(1139)/region/r.0.-1.mca new file mode 100644 index 0000000..c36527a Binary files /dev/null and b/examples/resources/versions/1.12(1139)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.12(1139)/region/r.0.0.mca b/examples/resources/versions/1.12(1139)/region/r.0.0.mca new file mode 100644 index 0000000..1e8d7ee Binary files /dev/null and b/examples/resources/versions/1.12(1139)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.12.1(1241)/region/r.-1.-1.mca b/examples/resources/versions/1.12.1(1241)/region/r.-1.-1.mca new file mode 100644 index 0000000..afd51d5 Binary files /dev/null and b/examples/resources/versions/1.12.1(1241)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.12.1(1241)/region/r.-1.0.mca b/examples/resources/versions/1.12.1(1241)/region/r.-1.0.mca new file mode 100644 index 0000000..56a89ff Binary files /dev/null and b/examples/resources/versions/1.12.1(1241)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.12.1(1241)/region/r.0.-1.mca b/examples/resources/versions/1.12.1(1241)/region/r.0.-1.mca new file mode 100644 index 0000000..c36527a Binary files /dev/null and b/examples/resources/versions/1.12.1(1241)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.12.1(1241)/region/r.0.0.mca b/examples/resources/versions/1.12.1(1241)/region/r.0.0.mca new file mode 100644 index 0000000..3ba7bcf Binary files /dev/null and b/examples/resources/versions/1.12.1(1241)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.12.2(1343)/region/r.-1.-1.mca b/examples/resources/versions/1.12.2(1343)/region/r.-1.-1.mca new file mode 100644 index 0000000..afd51d5 Binary files /dev/null and b/examples/resources/versions/1.12.2(1343)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.12.2(1343)/region/r.-1.0.mca b/examples/resources/versions/1.12.2(1343)/region/r.-1.0.mca new file mode 100644 index 0000000..2fae4ae Binary files /dev/null and b/examples/resources/versions/1.12.2(1343)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.12.2(1343)/region/r.0.-1.mca b/examples/resources/versions/1.12.2(1343)/region/r.0.-1.mca new file mode 100644 index 0000000..c36527a Binary files /dev/null and b/examples/resources/versions/1.12.2(1343)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.12.2(1343)/region/r.0.0.mca b/examples/resources/versions/1.12.2(1343)/region/r.0.0.mca new file mode 100644 index 0000000..1e8d7ee Binary files /dev/null and b/examples/resources/versions/1.12.2(1343)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-1.-1.mca b/examples/resources/versions/1.13(1519)/region/r.-1.-1.mca new file mode 100644 index 0000000..3e14e87 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-1.0.mca b/examples/resources/versions/1.13(1519)/region/r.-1.0.mca new file mode 100644 index 0000000..0331462 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-1.1.mca b/examples/resources/versions/1.13(1519)/region/r.-1.1.mca new file mode 100644 index 0000000..3585180 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-2.-1.mca b/examples/resources/versions/1.13(1519)/region/r.-2.-1.mca new file mode 100644 index 0000000..21f8f8e Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-2.0.mca b/examples/resources/versions/1.13(1519)/region/r.-2.0.mca new file mode 100644 index 0000000..b734373 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.-2.1.mca b/examples/resources/versions/1.13(1519)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.0.-1.mca b/examples/resources/versions/1.13(1519)/region/r.0.-1.mca new file mode 100644 index 0000000..67c7113 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.0.0.mca b/examples/resources/versions/1.13(1519)/region/r.0.0.mca new file mode 100644 index 0000000..c166b7a Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.13(1519)/region/r.0.1.mca b/examples/resources/versions/1.13(1519)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13(1519)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-1.-1.mca b/examples/resources/versions/1.13.1(1628)/region/r.-1.-1.mca new file mode 100644 index 0000000..986177b Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-1.0.mca b/examples/resources/versions/1.13.1(1628)/region/r.-1.0.mca new file mode 100644 index 0000000..aa7da6f Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-1.1.mca b/examples/resources/versions/1.13.1(1628)/region/r.-1.1.mca new file mode 100644 index 0000000..0901631 Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-2.-1.mca b/examples/resources/versions/1.13.1(1628)/region/r.-2.-1.mca new file mode 100644 index 0000000..2b4337e Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-2.0.mca b/examples/resources/versions/1.13.1(1628)/region/r.-2.0.mca new file mode 100644 index 0000000..2bede79 Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.-2.1.mca b/examples/resources/versions/1.13.1(1628)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.0.-1.mca b/examples/resources/versions/1.13.1(1628)/region/r.0.-1.mca new file mode 100644 index 0000000..59f8efc Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.0.0.mca b/examples/resources/versions/1.13.1(1628)/region/r.0.0.mca new file mode 100644 index 0000000..8c9e6f4 Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.13.1(1628)/region/r.0.1.mca b/examples/resources/versions/1.13.1(1628)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13.1(1628)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-1.-1.mca b/examples/resources/versions/1.13.2(1631)/region/r.-1.-1.mca new file mode 100644 index 0000000..b6c8f94 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-1.0.mca b/examples/resources/versions/1.13.2(1631)/region/r.-1.0.mca new file mode 100644 index 0000000..b51eefe Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-1.1.mca b/examples/resources/versions/1.13.2(1631)/region/r.-1.1.mca new file mode 100644 index 0000000..8965dcf Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-2.-1.mca b/examples/resources/versions/1.13.2(1631)/region/r.-2.-1.mca new file mode 100644 index 0000000..ff83910 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-2.0.mca b/examples/resources/versions/1.13.2(1631)/region/r.-2.0.mca new file mode 100644 index 0000000..d671d3e Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.-2.1.mca b/examples/resources/versions/1.13.2(1631)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.0.-1.mca b/examples/resources/versions/1.13.2(1631)/region/r.0.-1.mca new file mode 100644 index 0000000..9832774 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.0.0.mca b/examples/resources/versions/1.13.2(1631)/region/r.0.0.mca new file mode 100644 index 0000000..0c3e436 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.13.2(1631)/region/r.0.1.mca b/examples/resources/versions/1.13.2(1631)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.13.2(1631)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-1.-1.mca b/examples/resources/versions/1.14(1952)/region/r.-1.-1.mca new file mode 100644 index 0000000..744b7e1 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-1.0.mca b/examples/resources/versions/1.14(1952)/region/r.-1.0.mca new file mode 100644 index 0000000..472299b Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-1.1.mca b/examples/resources/versions/1.14(1952)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-2.-1.mca b/examples/resources/versions/1.14(1952)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-2.0.mca b/examples/resources/versions/1.14(1952)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.-2.1.mca b/examples/resources/versions/1.14(1952)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.0.-1.mca b/examples/resources/versions/1.14(1952)/region/r.0.-1.mca new file mode 100644 index 0000000..dad04a0 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.0.0.mca b/examples/resources/versions/1.14(1952)/region/r.0.0.mca new file mode 100644 index 0000000..7f44446 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.14(1952)/region/r.0.1.mca b/examples/resources/versions/1.14(1952)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14(1952)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-1.-1.mca b/examples/resources/versions/1.14.1(1957)/region/r.-1.-1.mca new file mode 100644 index 0000000..eb19973 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-1.0.mca b/examples/resources/versions/1.14.1(1957)/region/r.-1.0.mca new file mode 100644 index 0000000..11ceb7e Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-1.1.mca b/examples/resources/versions/1.14.1(1957)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-2.-1.mca b/examples/resources/versions/1.14.1(1957)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-2.0.mca b/examples/resources/versions/1.14.1(1957)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.-2.1.mca b/examples/resources/versions/1.14.1(1957)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.0.-1.mca b/examples/resources/versions/1.14.1(1957)/region/r.0.-1.mca new file mode 100644 index 0000000..da60fd2 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.0.0.mca b/examples/resources/versions/1.14.1(1957)/region/r.0.0.mca new file mode 100644 index 0000000..dd509a4 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.14.1(1957)/region/r.0.1.mca b/examples/resources/versions/1.14.1(1957)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.1(1957)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-1.-1.mca b/examples/resources/versions/1.14.2(1963)/region/r.-1.-1.mca new file mode 100644 index 0000000..2e3805d Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-1.0.mca b/examples/resources/versions/1.14.2(1963)/region/r.-1.0.mca new file mode 100644 index 0000000..29d3805 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-1.1.mca b/examples/resources/versions/1.14.2(1963)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-2.-1.mca b/examples/resources/versions/1.14.2(1963)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-2.0.mca b/examples/resources/versions/1.14.2(1963)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.-2.1.mca b/examples/resources/versions/1.14.2(1963)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.0.-1.mca b/examples/resources/versions/1.14.2(1963)/region/r.0.-1.mca new file mode 100644 index 0000000..761a420 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.0.0.mca b/examples/resources/versions/1.14.2(1963)/region/r.0.0.mca new file mode 100644 index 0000000..7b24088 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.14.2(1963)/region/r.0.1.mca b/examples/resources/versions/1.14.2(1963)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.2(1963)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-1.-1.mca b/examples/resources/versions/1.14.3(1968)/region/r.-1.-1.mca new file mode 100644 index 0000000..c4e0055 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-1.0.mca b/examples/resources/versions/1.14.3(1968)/region/r.-1.0.mca new file mode 100644 index 0000000..5cd4e0d Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-1.1.mca b/examples/resources/versions/1.14.3(1968)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-2.-1.mca b/examples/resources/versions/1.14.3(1968)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-2.0.mca b/examples/resources/versions/1.14.3(1968)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.-2.1.mca b/examples/resources/versions/1.14.3(1968)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.0.-1.mca b/examples/resources/versions/1.14.3(1968)/region/r.0.-1.mca new file mode 100644 index 0000000..3871bfe Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.0.0.mca b/examples/resources/versions/1.14.3(1968)/region/r.0.0.mca new file mode 100644 index 0000000..613ee82 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.14.3(1968)/region/r.0.1.mca b/examples/resources/versions/1.14.3(1968)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.3(1968)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-1.-1.mca b/examples/resources/versions/1.14.4(1976)/region/r.-1.-1.mca new file mode 100644 index 0000000..07870c1 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-1.0.mca b/examples/resources/versions/1.14.4(1976)/region/r.-1.0.mca new file mode 100644 index 0000000..76fde32 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-1.1.mca b/examples/resources/versions/1.14.4(1976)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-2.-1.mca b/examples/resources/versions/1.14.4(1976)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-2.0.mca b/examples/resources/versions/1.14.4(1976)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.-2.1.mca b/examples/resources/versions/1.14.4(1976)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.0.-1.mca b/examples/resources/versions/1.14.4(1976)/region/r.0.-1.mca new file mode 100644 index 0000000..75070f3 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.0.0.mca b/examples/resources/versions/1.14.4(1976)/region/r.0.0.mca new file mode 100644 index 0000000..a739872 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.14.4(1976)/region/r.0.1.mca b/examples/resources/versions/1.14.4(1976)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.14.4(1976)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-1.-1.mca b/examples/resources/versions/1.15(2225)/region/r.-1.-1.mca new file mode 100644 index 0000000..287de0a Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-1.0.mca b/examples/resources/versions/1.15(2225)/region/r.-1.0.mca new file mode 100644 index 0000000..d7710c9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-1.1.mca b/examples/resources/versions/1.15(2225)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-2.-1.mca b/examples/resources/versions/1.15(2225)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-2.0.mca b/examples/resources/versions/1.15(2225)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.-2.1.mca b/examples/resources/versions/1.15(2225)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.0.-1.mca b/examples/resources/versions/1.15(2225)/region/r.0.-1.mca new file mode 100644 index 0000000..9e3454d Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.0.0.mca b/examples/resources/versions/1.15(2225)/region/r.0.0.mca new file mode 100644 index 0000000..3ba5061 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.15(2225)/region/r.0.1.mca b/examples/resources/versions/1.15(2225)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15(2225)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-1.-1.mca b/examples/resources/versions/1.15.1(2227)/region/r.-1.-1.mca new file mode 100644 index 0000000..e77d4e0 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-1.0.mca b/examples/resources/versions/1.15.1(2227)/region/r.-1.0.mca new file mode 100644 index 0000000..a68624e Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-1.1.mca b/examples/resources/versions/1.15.1(2227)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-2.-1.mca b/examples/resources/versions/1.15.1(2227)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-2.0.mca b/examples/resources/versions/1.15.1(2227)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.-2.1.mca b/examples/resources/versions/1.15.1(2227)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.0.-1.mca b/examples/resources/versions/1.15.1(2227)/region/r.0.-1.mca new file mode 100644 index 0000000..3ab9804 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.0.0.mca b/examples/resources/versions/1.15.1(2227)/region/r.0.0.mca new file mode 100644 index 0000000..b09397c Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.15.1(2227)/region/r.0.1.mca b/examples/resources/versions/1.15.1(2227)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.1(2227)/region/r.0.1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-1.-1.mca b/examples/resources/versions/1.15.2(2230)/region/r.-1.-1.mca new file mode 100644 index 0000000..0163447 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-1.-1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-1.0.mca b/examples/resources/versions/1.15.2(2230)/region/r.-1.0.mca new file mode 100644 index 0000000..8fb078c Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-1.0.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-1.1.mca b/examples/resources/versions/1.15.2(2230)/region/r.-1.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-1.1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-2.-1.mca b/examples/resources/versions/1.15.2(2230)/region/r.-2.-1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-2.-1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-2.0.mca b/examples/resources/versions/1.15.2(2230)/region/r.-2.0.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-2.0.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.-2.1.mca b/examples/resources/versions/1.15.2(2230)/region/r.-2.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.-2.1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.0.-1.mca b/examples/resources/versions/1.15.2(2230)/region/r.0.-1.mca new file mode 100644 index 0000000..bd95cb3 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.0.-1.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.0.0.mca b/examples/resources/versions/1.15.2(2230)/region/r.0.0.mca new file mode 100644 index 0000000..b1a4929 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.0.0.mca differ diff --git a/examples/resources/versions/1.15.2(2230)/region/r.0.1.mca b/examples/resources/versions/1.15.2(2230)/region/r.0.1.mca new file mode 100644 index 0000000..6d17cf9 Binary files /dev/null and b/examples/resources/versions/1.15.2(2230)/region/r.0.1.mca differ diff --git a/src/BlockChunk.php b/src/BlockChunk.php index a991cdf..2441364 100644 --- a/src/BlockChunk.php +++ b/src/BlockChunk.php @@ -2,6 +2,7 @@ namespace Aternos\Hawk; +use Aternos\Hawk\Exceptions\VersionNotSupportedException; use Aternos\Nbt\IO\Writer\ZLibCompressedStringWriter; use Aternos\Nbt\NbtFormat; use Aternos\Nbt\Tag\CompoundTag; @@ -44,8 +45,10 @@ public function __construct(int $location, int $offset, int $compressedDataLengt { parent::__construct($location, $offset, $compressedDataLength, $compressionScheme, $tag, $coordinates, $version); $this->version = $version; - $this->loadSections(); $this->loadBlockEntities(); + if (VersionHelper::areBlocksSupported($this->version)) { + $this->loadSections(); + } } /** @@ -111,6 +114,9 @@ public function getSections(): array */ public function getBlock(McCoordinates3D $coordinates): DataBlock { + if (!VersionHelper::areBlocksSupported($this->version)) { + throw new VersionNotSupportedException($this->version); + } $section = $this->getSection($coordinates); if ($section === null) { throw new Exception("No such section."); @@ -130,6 +136,9 @@ public function getBlock(McCoordinates3D $coordinates): DataBlock */ public function replaceBlock(McCoordinates3D $coordinates, string $blockName = "minecraft:stone"): void { + if (!VersionHelper::areBlocksSupported($this->version)) { + throw new VersionNotSupportedException($this->version); + } $section = $this->getSection($coordinates); if ($section === null) { $section = $this->addEmptySection($coordinates); diff --git a/src/VersionHelper.php b/src/VersionHelper.php index d445bda..752b483 100644 --- a/src/VersionHelper.php +++ b/src/VersionHelper.php @@ -4,6 +4,7 @@ use Aternos\Hawk\Exceptions\VersionNotSupportedException; +use Aternos\Hawk\Versions\v1139\BlockChunkV1139; use Aternos\Hawk\Versions\v2566\BlockChunkV2566; use Aternos\Hawk\Versions\v2567\BlockChunkV2567; use Aternos\Hawk\Versions\v2578\BlockChunkV2578; @@ -20,19 +21,22 @@ class VersionHelper { - private const VERSIONS = [ + private const BLOCK_SUPPORT = 2566; + private const DATA_VERSIONS = [ 3218 => [ "name" => "1.19.3", "class" => BlockChunkV3105::class, "level" => false, "entities" => false, - ],3120 => [ + ], + 3120 => [ "name" => "1.19.2", "class" => BlockChunkV3105::class, "level" => false, "entities" => false, - ],3117 => [ + ], + 3117 => [ "name" => "1.19.1", "class" => BlockChunkV3105::class, "level" => false, @@ -110,11 +114,81 @@ class VersionHelper "level" => true, "entities" => true, ], - - /* Unsupported + 2230 => [ + "name" => "1.15.2", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 2227 => [ + "name" => "1.15.1", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 2225 => [ + "name" => "1.15", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1976 => [ + "name" => "1.14.4", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1968 => [ + "name" => "1.14.3", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1963 => [ + "name" => "1.14.2", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1957 => [ + "name" => "1.14.1", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1952 => [ + "name" => "1.14", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1631 => [ + "name" => "1.13.2", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1628 => [ + "name" => "1.13.1", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1519 => [ + "name" => "1.13", + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], 1343 => [ "name" => "1.12.2", - "class" => BlockChunkV1343::class, + "class" => BlockChunkV1139::class, + "level" => true, + "entities" => true, + ], + 1241 => [ + "name" => "1.12.1", + "class" => BlockChunkV1139::class, "level" => true, "entities" => true, ], @@ -123,51 +197,68 @@ class VersionHelper "class" => BlockChunkV1139::class, "level" => true, "entities" => true, - ],*/ + ], ]; /** - * @param int $version - * @return void + * @param int $dataVersion + * @return int * @throws Exception */ - protected static function versionSupported(int $version): void + protected static function getSupportedVersion(int $dataVersion): int + { + if (array_key_exists($dataVersion, static::DATA_VERSIONS)) { + return $dataVersion; + } + $latest = max(array_keys(static::DATA_VERSIONS)); + if ($dataVersion > $latest) { + return $latest; + } + throw new VersionNotSupportedException(static::DATA_VERSIONS[$dataVersion]["name"]); + } + + /** + * @param int $dataVersion + * @return bool + */ + public static function areBlocksSupported(int $dataVersion): bool { - if (!array_key_exists($version, static::VERSIONS)) { - throw new VersionNotSupportedException(static::VERSIONS[$version]["name"]); + if ($dataVersion >= self::BLOCK_SUPPORT) { + return true; } + return false; } /** - * @param int $version + * @param int $dataVersion * @return string * @throws Exception */ - public static function getChunkClassFromVersion(int $version): string + public static function getChunkClassFromVersion(int $dataVersion): string { - self::versionSupported($version); - return static::VERSIONS[$version]["class"]; + $dataVersion = self::getSupportedVersion($dataVersion); + return static::DATA_VERSIONS[$dataVersion]["class"]; } /** - * @param int $version + * @param int $dataVersion * @return bool * @throws Exception */ - public static function hasLevelTag(int $version): bool + public static function hasLevelTag(int $dataVersion): bool { - self::versionSupported($version); - return static::VERSIONS[$version]["level"]; + $dataVersion = self::getSupportedVersion($dataVersion); + return static::DATA_VERSIONS[$dataVersion]["level"]; } /** - * @param int $version + * @param int $dataVersion * @return bool * @throws Exception */ - public static function hasEntitiesTag(int $version): bool + public static function hasEntitiesTag(int $dataVersion): bool { - self::versionSupported($version); - return static::VERSIONS[$version]["entities"]; + $dataVersion = self::getSupportedVersion($dataVersion); + return static::DATA_VERSIONS[$dataVersion]["entities"]; } } \ No newline at end of file diff --git a/src/Versions/v1139/BlockChunkV1139.php b/src/Versions/v1139/BlockChunkV1139.php new file mode 100644 index 0000000..9596cc6 --- /dev/null +++ b/src/Versions/v1139/BlockChunkV1139.php @@ -0,0 +1,35 @@ + $int64) { + //$debugDataBlocks = []; //only for AbstractTest.php, Breakpoint with condition $int64 !== 0 + for ($blockCounter = 0; $blockCounter < $numberOfBlocks && $counter < Section::BLOCKS_PER_SECTION; $blockCounter++, $counter++) { + $intBitLength = $this->getBitLength($int64); + //check for fractions + if ($intBitLength < $bitLength) { + $fractioned = true; + $fraction = $int64; + } + if ($fractioned === true) { + // combine both fractions + $fractionBitLength = $this->getBitLength($fraction); + $diff = $bitLength - $fractionBitLength; + $dummyRef = $int64 >> (64 - ($diff)); + $dummyRef <<= $fractionBitLength; + $ref = $dummyRef & $fraction; + $fractioned = false; + $fraction = 0; + } else { + // Get the last $bitLength bits of int64 which equal the index of the palette block in the palette + $ref = $int64 & $bitmask; + } + + $this->dataBlocks[] = new DataBlock($ref, $paletteBlocks[$ref]); + //$debugDataBlocks[] = new DataBlock($ref, $paletteBlocks[$ref]); //only for AbstractTest.php + + // Shifts $bitLength bits to the right -> cut off last index + $int64 = $int64 >> $bitLength; + $int64 &= 0x7FFFFFFFFFFFFFFF; + } + } + } + + /** + * @param int $bitLength + * @param int $section + * @return LongArrayTag + */ + public function writeInts(int $bitLength, int $section): LongArrayTag + { + $data = new LongArrayTag(); + // Number of blocks that fit into an int + $numberOfBlocks = ceil(static::INTEGER_SIZE / $bitLength); + $dataArrayLength = ceil(Section::BLOCKS_PER_SECTION * $bitLength / static::INTEGER_SIZE); + $blockCounter = 0; // Counts to max amount of blocks in section + $offset = 0; + $fraction = 0; // Part of a block int that overflows + for ($i = 0; $i < $dataArrayLength; $i++) { + $int64 = 0; // New compressed int64 filled with 0's + for ($j = 0; $j < $numberOfBlocks && $blockCounter < Section::BLOCKS_PER_SECTION; $j++, $blockCounter++) { + $int64Length = $this->getBitLength($int64); // Current bit length of $int64 + $bitLengthDiff = static::INTEGER_SIZE - $int64Length; + $ref = $this->dataBlocks[$blockCounter]->getId(); + if ($bitLengthDiff < $bitLength) { + $fraction = $ref >> $bitLengthDiff; // Datablock ref bit shifted by $bitLengthDiff to get the overflow bit(s) + $bitmask = $this->getBitMask($bitLengthDiff); + $fillUp = $ref & $bitmask; // Get the bit(s) that fill(s) the gap + $fillUp <<= $int64Length; // Shift the bit(s) to the left most position + $int64 |= $fillUp; // Add the bit(s) to $int64 + } + if ($fraction !== 0) { + $int64 = $fraction; + $offset = $this->getBitLength($fraction); + $fraction = 0; + } else { + // Building int64 from right to left. + // Left shift $ref to the next zeroed position. + $shiftedRef = $ref << ($j * $bitLength + $offset); + // Write $shiftedRef into int64 + $int64 |= $shiftedRef; + } + } + $data[] = $int64; + } + return $data; + } + +} \ No newline at end of file diff --git a/src/Versions/v1139/SectionV1139.php b/src/Versions/v1139/SectionV1139.php new file mode 100644 index 0000000..af2446f --- /dev/null +++ b/src/Versions/v1139/SectionV1139.php @@ -0,0 +1,187 @@ +coordinates = $coordinates; + $section->version = $version; + + $paletteBlocks[] = PaletteBlock::new(); + $section->palette = static::newPalette($paletteBlocks); + + + $dataBlocks = []; + $dataBlock = new DataBlock(0, $paletteBlocks[0]); + for ($i = 0; $i < static::BLOCKS_PER_SECTION; $i++) { + $dataBlocks[] = $dataBlock; + } + + $section->data = static::newData($dataBlocks); + return $section; + } + + /** + * @inheritDoc + */ + public static function newFromTag(CompoundTag $tag, McCoordinates2D $coordinates, int $version): ?Section + { + $section = new static(); + $section->tag = $tag; + $section->version = $version; + $section->coordinates = new McCoordinates3D($coordinates->x, $tag->getByte("Y")->getValue(), $coordinates->z); + $paletteTag = $tag->getList($section->paletteTagName); + if ($paletteTag === null) { + return null; + } + $section->palette = $section->newPaletteFromTag($paletteTag); + $section->data = $section->newDataFromTag($section, $tag, $section->coordinates->y); + return $section; + } + + /** + * @param array $dataBlocks + * @return Data + */ + protected static function newData(array $dataBlocks): Data + { + return DataV1139::new($dataBlocks); + } + + /** + * @param Section $section + * @param CompoundTag $tag + * @param int $sectionY + * @return Data + */ + protected static function newDataFromTag(Section $section, CompoundTag $tag, int $sectionY): Data + { + return DataV1139::newFromTag($tag->getLongArray($section->dataTagName), $section->palette, $section->version, $sectionY); + } + + /** + * @param array $paletteBlocks + * @return Palette + */ + protected static function newPalette(array $paletteBlocks): Palette + { + return Palette::new($paletteBlocks); + } + + /** + * @param ListTag $paletteTag + * @return Palette + */ + protected static function newPaletteFromTag(ListTag $paletteTag): Palette + { + return Palette::newFromTag($paletteTag); + } + + /** + * @inheritDoc + */ + public function getBlock(McCoordinates3D $coordinates): DataBlock + { + $index = $this->calcDataBlocksIndex(Section::getBlockCoordinates($coordinates)); + + // If section is empty + if (isset($this->palette) && $this->getPalette()->getLength() === 1 && $this->getPalette()->getPaletteBlocks()[0]->getName() === "minecraft:air") { + return new DataBlock(0, $this->getPalette()->getPaletteBlocks()[0]); + } + return $this->getData()->getDataBlock($index); + } + + /** + * @inheritDoc + */ + public function replaceBlock(McCoordinates3D $coordinates, string $blockName = "minecraft:stone"): void + { + $index = $this->calcDataBlocksIndex(Section::getBlockCoordinates($coordinates)); + $dataBlock = $this->createDataBlock($blockName); + $this->getData()->setDataBlock($index, $dataBlock); + } + + /** + * @inheritDoc + */ + public function createTag(): CompoundTag + { + $section = new CompoundTag(); + $section->set("Y", (new ByteTag())->setValue($this->coordinates->y)); + $section->set($this->dataTagName, $this->data->createTag($this->getPalette()->getLength(), $this->coordinates->y)); + $section->set($this->paletteTagName, $this->palette->createTag()); + return $section; + } + + /** + * @return Palette + */ + public function getPalette(): Palette + { + return $this->palette; + } + + /** + * @return Data + */ + public function getData(): Data + { + return $this->data; + } + + /** + * @param string $name + * @param array $properties + * @return PaletteBlock + */ + public function createPaletteBlock(string $name = "minecraft:air", array $properties = []): PaletteBlock + { + $paletteBlock = PaletteBlock::new($name, $properties); + $this->getPalette()->addPaletteBlock($paletteBlock); + return $paletteBlock; + } + + /** + * @param string $blockName + * @return DataBlock + */ + public function createDataBlock(string $blockName = "minecraft:stone"): DataBlock + { + $paletteBlock = $this->getPalette()->findPaletteBlock($blockName); + if ($paletteBlock === null) { + $paletteBlock = $this->createPaletteBlock($blockName); + } + $arraySearch = array_search($paletteBlock, $this->palette->getPaletteBlocks()); + + return new DataBlock($arraySearch, $this->getPalette()->getPaletteBlocks()[$arraySearch]); + } +} \ No newline at end of file diff --git a/tests/integration/HawkTest.php b/tests/integration/HawkTest.php index efd7ba1..5a84135 100644 --- a/tests/integration/HawkTest.php +++ b/tests/integration/HawkTest.php @@ -4,6 +4,7 @@ use Aternos\Hawk\BlockEntity; use Aternos\Hawk\Entity; +use Aternos\Hawk\Exceptions\VersionNotSupportedException; use Aternos\Hawk\File; use Aternos\Hawk\Hawk; use Aternos\Hawk\McCoordinates3D; @@ -56,10 +57,10 @@ public function getExactNegativeEntityCoords(): McCoordinatesFloat function copyTestFiles($src = null, $dst = null) { - if($src === null){ + if ($src === null) { $src = __DIR__ . "/../../examples/resources/versions"; } - if($dst === null){ + if ($dst === null) { $dst = __DIR__ . "/../files/versions"; } @@ -162,8 +163,13 @@ public function provideNegativeSingleBlockFile(): array public function testGetBlock(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk(blockFiles: $blockFiles, entitiesFiles: $entitiesFiles); - $block = $hawk->getBlock($this->getBlockCoords()); - $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + try { + $block = $hawk->getBlock($this->getBlockCoords()); + $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getBlockCoords()); + } $this->closeFiles($blockFiles, $entitiesFiles); } @@ -177,8 +183,13 @@ public function testGetBlock(array $blockFiles, array $entitiesFiles): void public function testGetBlockNegative(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk(blockFiles: $blockFiles, entitiesFiles: $entitiesFiles); - $block = $hawk->getBlock($this->getNegativeBlockCoords()); - $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + try { + $block = $hawk->getBlock($this->getNegativeBlockCoords()); + $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getNegativeBlockCoords()); + } $this->closeFiles($blockFiles, $entitiesFiles); } @@ -192,7 +203,13 @@ public function testGetBlockNegative(array $blockFiles, array $entitiesFiles): v public function testReplaceBlock(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk(blockFiles: $blockFiles, entitiesFiles: $entitiesFiles); - $block = $hawk->getBlock($this->getBlockCoords()); + try { + $block = $hawk->getBlock($this->getBlockCoords()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getBlockCoords()); + return; + } $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); $hawk->replaceBlock($this->getBlockCoords(), "minecraft:wool"); $hawk->save(); @@ -213,7 +230,13 @@ public function testReplaceBlock(array $blockFiles, array $entitiesFiles): void public function testReplaceBlockNegative(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk(blockFiles: $blockFiles, entitiesFiles: $entitiesFiles); - $block = $hawk->getBlock($this->getNegativeBlockCoords()); + try { + $block = $hawk->getBlock($this->getNegativeBlockCoords()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getNegativeBlockCoords()); + return; + } $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); $hawk->replaceBlock($this->getNegativeBlockCoords(), "minecraft:wool"); $hawk->save(); @@ -291,7 +314,7 @@ public function testGetNegativeEntities(array $blockFiles, array $entitiesFiles) foreach ($entities as $entity) { $this->assertInstanceOf(Entity::class, $entity); $this->assertEquals("minecraft:chicken", $entity->getName()); - $this->assertTrue($entity->getCoordinates()->equals($this->getExactNegativeEntityCoords(),0.1)); + $this->assertTrue($entity->getCoordinates()->equals($this->getExactNegativeEntityCoords(), 0.1)); } $this->closeFiles($blockFiles, $entitiesFiles); } @@ -337,6 +360,7 @@ public function testDeleteNegativeEntity(array $blockFiles, array $entitiesFiles $this->assertEmpty($entities); $this->closeFiles($blockFiles, $entitiesFiles); } + /** * @dataProvider provideSingleBlockFile * @param array $blockFiles diff --git a/tests/unit/BlockRegionTest.php b/tests/unit/BlockRegionTest.php index f568ac1..685d36b 100644 --- a/tests/unit/BlockRegionTest.php +++ b/tests/unit/BlockRegionTest.php @@ -4,6 +4,7 @@ use Aternos\Hawk\BlockRegion; use Aternos\Hawk\DataBlock; +use Aternos\Hawk\Exceptions\VersionNotSupportedException; use Aternos\Hawk\File; use Exception; @@ -28,6 +29,12 @@ protected function tearDown(): void public function testGetBlock(array $blockFiles, array $entitiesFiles): void { $region = new BlockRegion($blockFiles[0]); + try { + $block = $region->getBlock($this->getBlockCoords()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $region->getBlock($this->getBlockCoords()); + } $block = $region->getBlock($this->getBlockCoords()); $this->assertInstanceOf(DataBlock::class, $block); $this->closeFiles($blockFiles, $entitiesFiles); @@ -43,7 +50,14 @@ public function testGetBlock(array $blockFiles, array $entitiesFiles): void public function testReplaceBlock(array $blockFiles, array $entitiesFiles): void { $region = new BlockRegion($blockFiles[0]); - $block = $region->getBlock($this->getBlockCoords()); + + try { + $block = $region->getBlock($this->getBlockCoords()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $region->getBlock($this->getBlockCoords()); + return; + } $this->assertInstanceOf(DataBlock::class, $block); $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); $region->replaceBlock($this->getBlockCoords(), "minecraft:wool"); diff --git a/tests/unit/HawkTest.php b/tests/unit/HawkTest.php index 65d258c..3cf5152 100644 --- a/tests/unit/HawkTest.php +++ b/tests/unit/HawkTest.php @@ -7,6 +7,7 @@ use Aternos\Hawk\DataBlock; use Aternos\Hawk\EntitiesRegion; use Aternos\Hawk\Entity; +use Aternos\Hawk\Exceptions\VersionNotSupportedException; use Aternos\Hawk\Hawk; use Aternos\Hawk\Property; use Exception; @@ -273,9 +274,14 @@ public function testGetEntitiesRegionFromChunk(array $blockFiles, array $entitie public function testGetBlock(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk($blockFiles, $entitiesFiles); - $block = $hawk->getBlock($this->getBlockCoords()); - $this->assertInstanceOf(DataBlock::class, $block); - $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + try { + $block = $hawk->getBlock($this->getBlockCoords()); + $this->assertInstanceOf(DataBlock::class, $block); + $this->assertEquals("minecraft:furnace", $block->getPaletteBlock()->getName()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getBlockCoords()); + } $this->closeFiles($blockFiles, $entitiesFiles); } @@ -289,7 +295,12 @@ public function testGetBlock(array $blockFiles, array $entitiesFiles): void public function testReplaceBlock(array $blockFiles, array $entitiesFiles): void { $hawk = new Hawk($blockFiles, $entitiesFiles); - $block = $hawk->getBlock($this->getBlockCoords()); + try { + $block = $hawk->getBlock($this->getBlockCoords()); + } catch (VersionNotSupportedException $e) { + $this->expectException(VersionNotSupportedException::class); + $hawk->getBlock($this->getBlockCoords()); + } $hawk->replaceBlock($this->getBlockCoords(), "minecraft:wool"); $this->assertInstanceOf(DataBlock::class, $block); $this->assertEquals("minecraft:wool", $hawk->getBlock($this->getBlockCoords())->getPaletteBlock()->getName()); diff --git a/tests/unit/HawkTestCase.php b/tests/unit/HawkTestCase.php index 638d3f9..0c9e6c1 100644 --- a/tests/unit/HawkTestCase.php +++ b/tests/unit/HawkTestCase.php @@ -36,6 +36,20 @@ protected function closeFiles(array $blockFiles, array $entitiesFiles) { public array $files = []; public const VERSIONS_WITHOUT_ENTITIES_FILES = [ + "1.12", + "1.12.1", + "1.12.2", + "1.13", + "1.13.1", + "1.13.2", + "1.14", + "1.14.1", + "1.14.2", + "1.14.3", + "1.14.4", + "1.15", + "1.15.1", + "1.15.2", "1.16", "1.16.1", "1.16.2",