diff --git a/mapsync-mod/build.gradle.kts b/mapsync-mod/build.gradle.kts index 8926c34..61905a4 100644 --- a/mapsync-mod/build.gradle.kts +++ b/mapsync-mod/build.gradle.kts @@ -41,11 +41,11 @@ dependencies { libs.voxelmap.also { modCompileOnly(it) - modLocalDep(it) // Uncomment to test VoxelMap + // modLocalDep(it) // Uncomment to test VoxelMap } libs.journeymap.also { modCompileOnly(it) - //modLocalDep(it) // Uncomment to test JourneyMap + modLocalDep(it) // Uncomment to test JourneyMap } libs.xaerosmap.also { modCompileOnly(it) diff --git a/mapsync-mod/gradle/libs.versions.toml b/mapsync-mod/gradle/libs.versions.toml index 0d976dd..9cc383d 100644 --- a/mapsync-mod/gradle/libs.versions.toml +++ b/mapsync-mod/gradle/libs.versions.toml @@ -2,7 +2,7 @@ minecraft = "1.21.11" # https://fabricmc.net/versions.html fabricLoom = "1.15-SNAPSHOT" -fabricLoader = "0.18.4" +fabricLoader = "0.18.6" fabricApi = "0.141.3+1.21.11" [libraries] @@ -19,7 +19,7 @@ modmenu = { group = "maven.modrinth", name = "modmenu", version = "JWQVh32x" } # https://modrinth.com/mod/voxelmap-updated/versions?l=fabric voxelmap = { group = "maven.modrinth", name = "voxelmap-updated", version = "oL15yOzL" } # https://modrinth.com/mod/journeymap/versions?l=fabric -journeymap = { group = "maven.modrinth", name = "journeymap", version = "6vu2HyQi" } +journeymap = { group = "maven.modrinth", name = "journeymap", version = "ajOMv0sc" } # https://modrinth.com/mod/xaeros-world-map/versions?l=fabric xaerosmap = { group = "maven.modrinth", name = "xaeros-world-map", version = "CkZVhVE0" } # https://mvnrepository.com/artifact/org.java-websocket/Java-WebSocket diff --git a/mapsync-mod/src/main/java/gjum/minecraft/mapsync/mod/integrations/journeymap/JourneyMapHelperReal.java b/mapsync-mod/src/main/java/gjum/minecraft/mapsync/mod/integrations/journeymap/JourneyMapHelperReal.java index a8f1b83..513d7b3 100644 --- a/mapsync-mod/src/main/java/gjum/minecraft/mapsync/mod/integrations/journeymap/JourneyMapHelperReal.java +++ b/mapsync-mod/src/main/java/gjum/minecraft/mapsync/mod/integrations/journeymap/JourneyMapHelperReal.java @@ -1,24 +1,27 @@ package gjum.minecraft.mapsync.mod.integrations.journeymap; -import static gjum.minecraft.mapsync.mod.MapSyncMod.logger; -import static gjum.minecraft.mapsync.mod.Utils.mc; - import gjum.minecraft.mapsync.mod.data.BlockColumn; import gjum.minecraft.mapsync.mod.data.BlockInfo; import gjum.minecraft.mapsync.mod.data.ChunkTile; import journeymap.client.JourneymapClient; import journeymap.client.io.FileHandler; -import journeymap.client.model.chunk.NBTChunkMD; +import journeymap.client.model.chunk.ChunkMD; import journeymap.client.model.map.MapType; import journeymap.client.model.region.RegionCoord; -import journeymap.common.nbt.RegionData; -import journeymap.common.nbt.RegionDataStorageHandler; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.LevelChunk; +import static gjum.minecraft.mapsync.mod.MapSyncMod.logger; +import static gjum.minecraft.mapsync.mod.Utils.getBiomeRegistry; +import static gjum.minecraft.mapsync.mod.Utils.mc; + public class JourneyMapHelperReal { static boolean isMapping() { return JourneymapClient.getInstance().isMapping(); @@ -33,41 +36,53 @@ static boolean updateWithChunkTile(ChunkTile chunkTile) { var chunkMd = new TileChunkMD(chunkTile); var rCoord = RegionCoord.fromChunkPos( - FileHandler.getJMWorldDir(mc), - MapType.day(chunkTile.dimension()), // type doesn't matter, only dimension is used - chunkMd.getCoord().x, - chunkMd.getCoord().z); - - var key = new RegionDataStorageHandler.Key(rCoord, MapType.day(chunkTile.dimension())); - RegionData regionData = RegionDataStorageHandler.getInstance().getRegionData(key); - - final boolean renderedDay = renderController.renderChunk(rCoord, - MapType.day(chunkTile.dimension()), chunkMd, regionData); - if (!renderedDay) logger.warn("Failed rendering day at {}", chunkTile.chunkPos()); - - final boolean renderedBiome = renderController.renderChunk(rCoord, - MapType.biome(chunkTile.dimension()), chunkMd, regionData); - if (!renderedBiome) logger.warn("Failed rendering biome at {}", chunkTile.chunkPos()); - - final boolean renderedTopo = renderController.renderChunk(rCoord, - MapType.topo(chunkTile.dimension()), chunkMd, regionData); - if (!renderedTopo) logger.warn("Failed rendering topo at {}", chunkTile.chunkPos()); + FileHandler.getJMWorldDir(mc), + MapType.day(chunkTile.dimension()), // type doesn't matter, only dimension is used + chunkMd.getCoord().x, + chunkMd.getCoord().z); + + final boolean renderedDay = renderWithDiagnostics(rCoord, + MapType.day(chunkTile.dimension()), chunkMd, "day"); + final boolean renderedBiome = renderWithDiagnostics(rCoord, + MapType.biome(chunkTile.dimension()), chunkMd, "biome"); + final boolean renderedTopo = renderWithDiagnostics(rCoord, + MapType.topo(chunkTile.dimension()), chunkMd, "topo"); + + if (!renderedDay || !renderedBiome || !renderedTopo) { + logger.warn("JourneyMap chunk render debug {} -> day={}, biome={}, topo={}", + chunkTile.chunkPos(), renderedDay, renderedBiome, renderedTopo); + } return renderedDay && renderedBiome && renderedTopo; } + private static boolean renderWithDiagnostics( + RegionCoord rCoord, + MapType mapType, + TileChunkMD chunkMd, + String mapName + ) { + try { + // keep this call in one place so failures are logged with context + final boolean rendered = JourneymapClient.getInstance().getChunkRenderController().renderChunk(rCoord, mapType, chunkMd); + return rendered; + } catch (ChunkMD.ChunkMissingException e) { + logger.error("Chunk missing for rendering {} at {}", mapName, chunkMd.chunkTile.chunkPos()); + return false; + } catch (Throwable t) { + logger.error("Exception rendering {} at {}", mapName, chunkMd.chunkTile.chunkPos(), t); + return false; + } + } + /** * References JourneyMap classes. Check {@link JourneyMapHelper#isJourneyMapNotAvailable} before referencing this. */ - private static class TileChunkMD extends NBTChunkMD { + private static class TileChunkMD extends ChunkMD { private final ChunkTile chunkTile; public TileChunkMD(ChunkTile chunkTile) { - super(new LevelChunk(mc.level, chunkTile.chunkPos()), - chunkTile.chunkPos(), - null, // all accessing methods are overridden - MapType.day(chunkTile.dimension()) // just has to not be `underground` - ); + super(new LevelChunk(mc.level, chunkTile.chunkPos())); this.chunkTile = chunkTile; } @@ -88,7 +103,9 @@ private BlockColumn getCol(BlockPos pos) { @Override public BlockState getBlockState(BlockPos pos) { - var layers = getCol(pos.getX(), pos.getZ()).layers(); + var column = getCol(pos.getX(), pos.getZ()); + if (column == null) return Blocks.AIR.defaultBlockState(); + var layers = column.layers(); BlockInfo prevLayer = null; // note that layers are ordered top-down for (BlockInfo layer : layers) { @@ -107,23 +124,65 @@ public BlockState getBlockState(BlockPos pos) { } @Override - public Integer getGetLightValue(BlockPos pos) { - return getCol(pos.getX(), pos.getZ()).light(); + public BlockState getChunkBlockState(BlockPos pos) { + return getBlockState(pos); } @Override - public Integer getTopY(BlockPos pos) { - return getCol(pos.getX(), pos.getZ()).layers().get(0).y(); + public boolean canBlockSeeTheSky(int localX, int y, int localZ) { + return getSavedLightValue(localX, y, localZ) > 0; + } + + + @Override + public int getSavedLightValue(int localX, int y, int localZ) { + var column = getCol(localX, localZ); + if (column == null) return 0; + int light = column.light(); + if (light < 0 || light > 15) return 0; + return light; + } + + @Override + public int getPrecipitationHeight(BlockPos pos) { + return this.getPrecipitationHeight(pos.getX(), pos.getZ()); + } + + @Override + public ResourceKey getDimension() { + return chunkTile.dimension(); + } + + @Override + public int getPrecipitationHeight(int localX, int localZ) { + var column = getCol(localX, localZ); + if (column == null || column.layers().isEmpty()) { + return mc.level != null ? this.getMinY() : 0; + } + return column.layers().get(0).y(); } @Override public int getHeight(BlockPos pos) { - return this.getTopY(pos); + return this.getPrecipitationHeight(pos); + } + + @Override + public Holder getBiomeHolder(BlockPos pos) { + var biome = getBiome(pos); + if (biome == null || mc.level == null) return null; + var biomeKey = getBiomeRegistry().getResourceKey(biome).orElse(null); + if (biomeKey == null) return null; + return mc.level.registryAccess() + .lookupOrThrow(Registries.BIOME) + .getOrThrow(biomeKey); } @Override public Biome getBiome(BlockPos pos) { - return getCol(pos).biome(); + var column = getCol(pos); + if (column != null) return column.biome(); + return null; } } }