|
9 | 9 | import com.github.rfresh2.model.JMWaypointLegacy; |
10 | 10 | import com.github.rfresh2.model.JMWaypointModern; |
11 | 11 | import com.github.rfresh2.model.XaeroWaypoint; |
| 12 | +import com.viaversion.nbt.io.NBTIO; |
| 13 | +import com.viaversion.nbt.tag.CompoundTag; |
| 14 | +import com.viaversion.nbt.tag.Tag; |
12 | 15 | import org.slf4j.Logger; |
13 | 16 | import org.slf4j.LoggerFactory; |
14 | 17 |
|
|
20 | 23 | import java.nio.file.OpenOption; |
21 | 24 | import java.nio.file.Path; |
22 | 25 | import java.nio.file.StandardOpenOption; |
| 26 | +import java.util.ArrayList; |
23 | 27 | import java.util.Arrays; |
24 | 28 | import java.util.List; |
25 | 29 | import java.util.Objects; |
@@ -60,7 +64,31 @@ public static void main(final String[] args) { |
60 | 64 | } |
61 | 65 |
|
62 | 66 | private static List<XaeroWaypoint> convertWaypoints(Path inputFolder) { |
63 | | - return Arrays.stream(Objects.requireNonNull(inputFolder.toFile().listFiles())) |
| 67 | + File inputFolderFile = inputFolder.toFile(); |
| 68 | + List<File> files = Arrays.asList(Objects.requireNonNull(inputFolderFile.listFiles())); |
| 69 | + |
| 70 | + for (File file : files) { |
| 71 | + if (file.getName().equals("WaypointData.dat")) { |
| 72 | + LOG.info("Found JourneyMap NBT waypoint data file: {}", file.getAbsolutePath()); |
| 73 | + try { |
| 74 | + List<JMWaypointModern> jmWaypoints = readNbtWaypoints(file.toPath()); |
| 75 | + return jmWaypoints.stream() |
| 76 | + .peek(wp -> LOG.info("Found {} JM waypoint: {} [{}, {}, {}]", |
| 77 | + "nbt", |
| 78 | + wp.getName(), |
| 79 | + wp.getX(), |
| 80 | + wp.getY(), |
| 81 | + wp.getZ())) |
| 82 | + .map(JourneyMapWaypointsToXaero::convertWaypoint) |
| 83 | + .collect(Collectors.toList()); |
| 84 | + } catch (Exception e) { |
| 85 | + LOG.error("Error reading WaypointData.dat file: {}", file.getAbsolutePath(), e); |
| 86 | + throw new RuntimeException(e); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + return files.stream() |
64 | 92 | .map(JourneyMapWaypointsToXaero::parseJourneyMapWaypointFile) |
65 | 93 | .filter(Objects::nonNull) |
66 | 94 | .peek(wp -> LOG.info("Found {} JM waypoint: {} [{}, {}, {}]", |
@@ -140,4 +168,26 @@ public static XaeroWaypoint convertWaypoint(final IJMWaypoint jmWaypoint) { |
140 | 168 | dimension |
141 | 169 | ); |
142 | 170 | } |
| 171 | + |
| 172 | + public static List<JMWaypointModern> readNbtWaypoints(Path nbtSrc) throws Exception { |
| 173 | + List<JMWaypointModern> waypoints = new ArrayList<>(); |
| 174 | + CompoundTag tag = (CompoundTag) NBTIO.reader().named().read(nbtSrc, false); |
| 175 | + CompoundTag waypointsTag = tag.getCompoundTag("waypoints"); |
| 176 | + for (Tag waypointTagEntry : waypointsTag.values()) { |
| 177 | + CompoundTag e = (CompoundTag) waypointTagEntry; |
| 178 | + String waypointName = e.getString("name"); |
| 179 | + CompoundTag posTag = e.getCompoundTag("pos"); |
| 180 | + int x = posTag.getInt("x"); |
| 181 | + int y = posTag.getInt("y"); |
| 182 | + int z = posTag.getInt("z"); |
| 183 | + String dimension = posTag.getString("dimension"); |
| 184 | + int color = e.getInt("color"); |
| 185 | + int r = color >> 16 & 0xFF; |
| 186 | + int g = color >> 8 & 0xFF; |
| 187 | + int b = color & 0xFF; |
| 188 | + JMWaypointModern jmWaypointJsonModern = new JMWaypointModern(waypointName, x, y, z, r, g, b, true, new String[]{dimension}); |
| 189 | + waypoints.add(jmWaypointJsonModern); |
| 190 | + } |
| 191 | + return waypoints; |
| 192 | + } |
143 | 193 | } |
0 commit comments