Skip to content

Commit

Permalink
re-add structure markers. update for latest surveyor.
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Mar 6, 2024
1 parent 7b2494d commit 431f31a
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 173 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.gradle.configureondemand=true
# Enable advanced multi-module optimizations (share tiny-remaper instance between projects)
fabric.loom.multiProjectOptimisation=true
# Mod Properties
baseVersion = 2.0.0-alpha.3
baseVersion = 2.0.0-alpha.4
defaultBranch = 1.20
branch = 1.20
2 changes: 1 addition & 1 deletion libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fl = "0.15.0"
yarn = "1.20.1+build.10"
fapi = "0.83.0+1.20.1"
kaleidoConfig = "0.1.1+1.1.0-beta.3"
surveyor = "0.1.0-alpha.9+1.20"
surveyor = "0.1.0-alpha.14+1.20"

[plugins]
loom = { id = "fabric-loom", version.ref = "loom" }
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/folk/sisby/antique_atlas/AntiqueAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,19 @@ public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(MarkerTypes.getInstance());
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(StructureTiles.getInstance());

SurveyorEvents.Register.clientWorldLoad(id("world_tiles"), (world, ws) -> ((AntiqueAtlasWorld) world).antiqueAtlas$getWorldTiles());
SurveyorEvents.Register.clientWorldLoad(id("world_markers"), (world, ws) -> ((AntiqueAtlasWorld) world).antiqueAtlas$getWorldMarkers());
SurveyorEvents.Register.terrainUpdated(id("world_tiles"), (world, terrain, chunks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getWorldTiles().onTerrainUpdated(MinecraftClient.getInstance().world, terrain, chunks);
SurveyorEvents.Register.clientWorldLoad(id("world_data"), (world, ws) -> ((AntiqueAtlasWorld) world).antiqueAtlas$getData());
SurveyorEvents.Register.terrainUpdated(id("world_data"), (world, terrain, chunks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getData().onTerrainUpdated(MinecraftClient.getInstance().world, terrain, chunks);
});
SurveyorEvents.Register.structuresAdded(id("world_tiles"), (world, structures, summaries) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getWorldTiles().onStructuresAdded(MinecraftClient.getInstance().world, structures, summaries);
SurveyorEvents.Register.structuresAdded(id("world_data"), (world, structures, summaries) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getData().onStructuresAdded(MinecraftClient.getInstance().world, structures, summaries);
});
SurveyorEvents.Register.landmarksAdded(id("world_markers"), (world, worldLandmarks, landmarks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getWorldMarkers().onLandmarksAdded(MinecraftClient.getInstance().world, worldLandmarks, landmarks);
SurveyorEvents.Register.landmarksAdded(id("world_data"), (world, worldLandmarks, landmarks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getData().onLandmarksAdded(MinecraftClient.getInstance().world, worldLandmarks, landmarks);
});
SurveyorEvents.Register.landmarksRemoved(id("world_markers"), (world, worldLandmarks, landmarks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getWorldMarkers().onLandmarksRemoved(MinecraftClient.getInstance().world, worldLandmarks, landmarks);
SurveyorEvents.Register.landmarksRemoved(id("world_data"), (world, worldLandmarks, landmarks) -> {
if (MinecraftClient.getInstance().world != null) ((AntiqueAtlasWorld) MinecraftClient.getInstance().world).antiqueAtlas$getData().onLandmarksRemoved(MinecraftClient.getInstance().world, worldLandmarks, landmarks);
});
ClientTickEvents.END_WORLD_TICK.register((world -> ((AntiqueAtlasWorld) world).antiqueAtlas$getWorldTiles().tick(world)));
ClientTickEvents.END_WORLD_TICK.register((world -> ((AntiqueAtlasWorld) world).antiqueAtlas$getData().tick(world)));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package folk.sisby.antique_atlas;

public interface AntiqueAtlasWorld {
WorldTiles antiqueAtlas$getWorldTiles();

WorldMarkers antiqueAtlas$getWorldMarkers();
WorldAtlasData antiqueAtlas$getData();
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,104 @@
package folk.sisby.antique_atlas;

import com.google.common.collect.Multimap;
import folk.sisby.antique_atlas.reloader.StructureTiles;
import folk.sisby.antique_atlas.terrain.SurveyorChunkUtil;
import folk.sisby.antique_atlas.tile.TileType;
import folk.sisby.antique_atlas.util.Rect;
import folk.sisby.surveyor.SurveyorWorld;
import folk.sisby.surveyor.landmark.Landmark;
import folk.sisby.surveyor.landmark.LandmarkType;
import folk.sisby.surveyor.landmark.NetherPortalLandmark;
import folk.sisby.surveyor.landmark.PlayerDeathLandmark;
import folk.sisby.surveyor.landmark.SimplePointLandmark;
import folk.sisby.surveyor.landmark.WorldLandmarks;
import folk.sisby.surveyor.structure.WorldStructureSummary;
import folk.sisby.surveyor.terrain.WorldTerrainSummary;
import folk.sisby.surveyor.util.MapUtil;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.Structure;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;

public class WorldMarkers {
private final Map<LandmarkType<?>, Map<BlockPos, Marker>> markers = new ConcurrentHashMap<>();
public class WorldAtlasData {
private static final int CHUNK_TICK_LIMIT = AntiqueAtlas.CONFIG.performance.chunkTickLimit;
private final Map<ChunkPos, TileType> biomeTiles = new HashMap<>();
private final Map<ChunkPos, TileType> structureTiles = new HashMap<>();
private final Rect tileScope = new Rect(0, 0, 0, 0);
private final Deque<ChunkPos> terrainDeque = new ConcurrentLinkedDeque<>();
private final Map<LandmarkType<?>, Map<BlockPos, Marker>> landmarkMarkers = new ConcurrentHashMap<>();
private final Map<RegistryKey<Structure>, Map<ChunkPos, Marker>> structureMarkers = new ConcurrentHashMap<>();
boolean isFinished = false;

public WorldMarkers(World world) {
refresh(world);
public WorldAtlasData(World world) {
((SurveyorWorld) world).surveyor$getWorldSummary().terrain().keySet().forEach(terrainDeque::addLast);
((SurveyorWorld) world).surveyor$getWorldSummary().structures().asMap().forEach((key, map) -> onStructuresAdded(world, ((SurveyorWorld) world).surveyor$getWorldSummary().structures(), MapUtil.hashMultiMapOf(Map.of(key, map.keySet()))));
refreshLandmarkMarkers(world);
AntiqueAtlas.LOGGER.info("[Antique Atlas] Beginning to load terrain for {} - {} chunks available.", world.getRegistryKey().getValue(), terrainDeque.size());
}

public void refresh(World world) {
markers.clear();
public void onTerrainUpdated(World world, WorldTerrainSummary ws, Collection<ChunkPos> chunks) {
for (ChunkPos pos : chunks) {
if (!terrainDeque.contains(pos)) terrainDeque.add(pos);
}
}

public void onStructuresAdded(World world, WorldStructureSummary ws, Multimap<RegistryKey<Structure>, ChunkPos> summaries) {
summaries.forEach((key, pos) -> StructureTiles.getInstance().resolve(structureTiles, structureMarkers, world, key, pos, ws.get(key, pos), ws.getType(key), ws.getTags(key)));
}

public void tick(World world) {
for (int i = 0; i < CHUNK_TICK_LIMIT; i++) {
ChunkPos pos = terrainDeque.pollFirst();
if (pos == null) break;
TileType tile = world.getRegistryKey() == World.NETHER ? SurveyorChunkUtil.terrainToTileNether(world, pos) : SurveyorChunkUtil.terrainToTile(world, pos);
if (tile != null) {
tileScope.extendTo(pos.x, pos.z);
biomeTiles.put(pos, tile);
}
}
if (!isFinished && terrainDeque.isEmpty()) {
isFinished = true;
AntiqueAtlas.LOGGER.info("[Antique Atlas] Finished loading terrain for {} - {} tiles.", world.getRegistryKey().getValue(), biomeTiles.size());
}
}

public Rect getScope() {
return tileScope;
}

public Identifier getTile(int x, int z) {
return getTile(new ChunkPos(x, z));
}

public Identifier getTile(ChunkPos pos) {
return structureTiles.containsKey(pos) ? structureTiles.get(pos).id() : biomeTiles.containsKey(pos) ? biomeTiles.get(pos).id() : null;
}

public void refreshLandmarkMarkers(World world) {
landmarkMarkers.clear();
((SurveyorWorld) world).surveyor$getWorldSummary().landmarks().keySet().forEach(((landmarkType, pos) -> {
if (landmarkType == NetherPortalLandmark.TYPE) {
NetherPortalLandmark landmark = (NetherPortalLandmark) ((SurveyorWorld) world).surveyor$getWorldSummary().landmarks().get(landmarkType, pos);
markers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkMarkers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkType, AntiqueAtlas.id("nether_portal"), landmark.name(), landmark.pos(), true, landmark.owner()
));
}
Expand All @@ -58,25 +118,25 @@ public void refresh(World world) {
case ITEMS -> AntiqueAtlas.id("bundle");
};

markers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkMarkers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkType, icon, text, landmark.pos(), true, landmark.owner()
));
}
if (landmarkType == SimplePointLandmark.TYPE) {
SimplePointLandmark landmark = (SimplePointLandmark) ((SurveyorWorld) world).surveyor$getWorldSummary().landmarks().get(landmarkType, pos);
markers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkMarkers.computeIfAbsent(landmarkType, t -> new HashMap<>()).put(landmark.pos(), new Marker(
landmarkType, landmark.texture(), landmark.name(), landmark.pos(), true, landmark.owner()
));
}
}));
}

public void onLandmarksAdded(World world, WorldLandmarks ws, Collection<Landmark<?>> landmark) {
refresh(world);
public void onLandmarksAdded(World world, WorldLandmarks ws, Map<LandmarkType<?>, Map<BlockPos, Landmark<?>>> landmark) {
refreshLandmarkMarkers(world);
}

public void onLandmarksRemoved(ClientWorld world, WorldLandmarks landmarks, Multimap<LandmarkType<?>, BlockPos> landmark) {
refresh(world);
refreshLandmarkMarkers(world);
}

public void addMarker(PlayerEntity player, World world, Marker marker) {
Expand All @@ -97,7 +157,8 @@ public boolean deleteMarker(World world, Marker marker) {

public Collection<Marker> getAllMarkers() {
List<Marker> outList = new ArrayList<>();
markers.values().forEach(m -> outList.addAll(m.values()));
landmarkMarkers.values().forEach(m -> outList.addAll(m.values()));
structureMarkers.values().forEach(m -> outList.addAll(m.values()));
return outList;
}
}
74 changes: 0 additions & 74 deletions src/main/java/folk/sisby/antique_atlas/WorldTiles.java

This file was deleted.

Loading

0 comments on commit 431f31a

Please sign in to comment.