diff --git a/common/src/main/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadData.java b/common/src/main/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadData.java index 5437408..97e7962 100644 --- a/common/src/main/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadData.java +++ b/common/src/main/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadData.java @@ -61,6 +61,7 @@ public class RoadData { DO NOT DELETE THIS FILE!!! This rest of this file may look like gibberish, but it's not. This stores all the road data for Mojang Maps. If you delete this file, you'll delete all your Mojang Maps data and essentially start from scratch. + Even editing this file, or this message, will brick Mojang Maps. --- """; private final static Path FILE_PATH = Path.of(MojangMaps.loaderInfo.getConfig().getDataDirectory().toString(), "roads.mmd"); @@ -116,7 +117,7 @@ public void generateRoadData(List roads) { MojangMaps.loaderInfo.getConfig().getDataDirectory().toFile().mkdirs(); } - if (FILE_PATH.toFile().exists()) { + if (!FILE_PATH.toFile().exists()) { FILE_PATH.toFile().createNewFile(); } @@ -219,9 +220,13 @@ public List readRoadData() { switch (files[i]) { case 0x06: + if (i + 2 > files.length - 1) continue; + if (files[i + 2] != 0x07) continue; version = files[i + 1]; case 0x07: - compressedArray = Arrays.copyOfRange(files, i + 1, files.length); + if (files[i - 2] != 0x06) continue; + compressedArray = Arrays.copyOfRange(files, MESSAGE.getBytes(StandardCharsets.UTF_8).length + 3, files.length); + break; } diff --git a/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/TestSettings.java b/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/TestSettings.java new file mode 100644 index 0000000..4752050 --- /dev/null +++ b/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/TestSettings.java @@ -0,0 +1,27 @@ +/* + * nl.abelkrijgtalles.mojangmaps.mojang_maps.fabric.test + * Copyright (C) 2024 Abel van Hulst/Abelkrijgtalles/Abelpro678 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package nl.abelkrijgtalles.mojangmaps; + +public class TestSettings { + // please edit the values if needed + + // How many times to repeat a RepeatedTest + public final static int REPEATED_TEST_COUNT = 100; + +} diff --git a/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadDataTest.java b/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadDataTest.java index ff2638f..a8eaa7c 100644 --- a/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadDataTest.java +++ b/fabric/src/test/java/nl/abelkrijgtalles/mojangmaps/common/config/roads/RoadDataTest.java @@ -24,6 +24,7 @@ import java.util.Random; import net.minecraft.core.Position; import net.minecraft.world.phys.Vec3; +import nl.abelkrijgtalles.mojangmaps.TestSettings; import nl.abelkrijgtalles.mojangmaps.common.model.Road; import nl.abelkrijgtalles.mojangmaps.fabric.MojangMapsFabric; import org.junit.jupiter.api.BeforeEach; @@ -33,19 +34,20 @@ public class RoadDataTest { - @RepeatedTest(5) + @RepeatedTest(TestSettings.REPEATED_TEST_COUNT) void testGeneratingRoadData(RepetitionInfo repetitionInfo) { List roads = new ArrayList<>(); Random rand = new Random(); Faker faker = new Faker(); RoadData roadData = new RoadData(); + int numberOfRoadsAndWaypointsPerRoad = repetitionInfo.getCurrentRepetition(); - for (int i = 0; i < repetitionInfo.getCurrentRepetition(); i++) { + for (int i = 0; i < numberOfRoadsAndWaypointsPerRoad; i++) { List waypoints = new ArrayList<>(); - for (int j = 0; j < repetitionInfo.getCurrentRepetition(); j++) { + for (int j = 0; j < numberOfRoadsAndWaypointsPerRoad; j++) { waypoints.add(new Vec3(rand.nextDouble(1000), rand.nextDouble(256), rand.nextDouble(1000))); @@ -56,7 +58,32 @@ void testGeneratingRoadData(RepetitionInfo repetitionInfo) { } roadData.generateRoadData(roads); - assertEquals(roads, roadData.readRoadData()); + + // doing this cause junit does weird + List readRoads = roadData.readRoadData(); + for (int i = 0; i < roads.size(); i++) { + + Road road = roads.get(i); + Road readRoad = readRoads.get(i); + + assertEquals(road.getName(), readRoad.getName()); + assertEquals(road.getWorldName(), readRoad.getWorldName()); + + List roadWaypoints = road.getWaypoints(); + List readRoadWaypoints = readRoad.getWaypoints(); + + for (int j = 0; j < roadWaypoints.size(); j++) { + + Position position = roadWaypoints.get(j); + Position readPosition = readRoadWaypoints.get(j); + + assertEquals((int) position.x(), (int) readPosition.x()); + assertEquals((int) position.y(), (int) readPosition.y()); + assertEquals((int) position.z(), (int) readPosition.z()); + + } + + } }