Skip to content

Commit d8ad274

Browse files
committed
Fix Datapack Structures
1 parent e8bd7f5 commit d8ad274

9 files changed

Lines changed: 1132 additions & 30 deletions

common/src/main/java/com/mamiyaotaru/voxelmap/gui/GuiSeedMapperDatapackOptions.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.Random;
1515

1616
public class GuiSeedMapperDatapackOptions extends GuiScreenMinimap {
17-
private static final List<String> COLOR_SCHEMES = List.of("Random", "HSV", "Bright HSV");
17+
private static final List<String> COLOR_SCHEMES = List.of("Palette Random", "Highly Saturated", "Vibrant");
1818
private static final List<String> ICON_STYLES = List.of("Default", "Large", "Potion");
1919
private static final int[] COLOR_COUNTS = {32, 64, 128, 256};
2020

@@ -62,12 +62,20 @@ public void init() {
6262
y += 24;
6363
randomColorsButton = addRenderableWidget(new Button.Builder(Component.empty(), button -> {
6464
cycleRandomColorCount();
65+
settings.datapackRandomColorCycle = 0;
66+
settings.datapackColorScheme = 1;
6567
refreshLabels();
6668
MapSettingsManager.instance.saveAll();
6769
}).bounds(left, y, 150, 20).build());
6870

6971
regenerateColorsButton = addRenderableWidget(new Button.Builder(Component.literal("Regenerate Colors"), button -> {
70-
regenerateColors(settings.getDatapackRandomColors().size());
72+
if (settings.getDatapackRandomColors().isEmpty()) {
73+
regenerateColors(COLOR_COUNTS[0]);
74+
settings.datapackRandomColorCycle = 0;
75+
} else {
76+
settings.cycleDatapackRandomColors();
77+
}
78+
settings.datapackColorScheme = 1;
7179
refreshLabels();
7280
MapSettingsManager.instance.saveAll();
7381
}).bounds(right, y, 150, 20).build());
@@ -97,14 +105,20 @@ private void refreshLabels() {
97105
colorSchemeButton.setMessage(Component.literal("Color Scheme: " + COLOR_SCHEMES.get(Math.max(0, Math.min(COLOR_SCHEMES.size() - 1, settings.datapackColorScheme - 1)))));
98106
iconStyleButton.setMessage(Component.literal("Icon Style: " + ICON_STYLES.get(Math.max(0, Math.min(ICON_STYLES.size() - 1, settings.datapackIconStyle - 1)))));
99107
randomColorsButton.setMessage(Component.literal("Random Colors: " + settings.getDatapackRandomColors().size()));
100-
structureDisabledButton.setMessage(Component.literal("Structure Disabled: " + countDisabledStructures()));
108+
structureDisabledButton.setMessage(Component.literal("Datapack Structures: " + countEnabledStructures() + " shown"));
101109
savedUrlsButton.setMessage(Component.literal("Saved URLs"));
102110
savedCachePathsButton.setMessage(Component.literal("Saved Cache Paths"));
103111
}
104112

105-
private int countDisabledStructures() {
113+
private int countEnabledStructures() {
106114
String worldKey = currentWorldKey();
107-
return settings.getDisabledDatapackStructures(worldKey).size();
115+
long seed = Long.MIN_VALUE;
116+
try {
117+
seed = settings.resolveSeed(VoxelConstants.getVoxelMapInstance().getWorldSeed());
118+
} catch (IllegalArgumentException ignored) {
119+
}
120+
int total = SeedMapperDatapackManager.readImportedStructureIds(settings.datapackCachePath, seed).size();
121+
return Math.max(0, total - settings.getDisabledDatapackStructures(worldKey).size());
108122
}
109123

110124
private void cycleRandomColorCount() {

common/src/main/java/com/mamiyaotaru/voxelmap/gui/GuiSeedMapperDatapackStructures.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ public void init() {
4545

4646
private void reloadEntries() {
4747
structureIds.clear();
48-
structureIds.addAll(SeedMapperDatapackManager.readImportedStructureIds(settings.datapackCachePath));
48+
long seed = Long.MIN_VALUE;
49+
try {
50+
seed = settings.resolveSeed(VoxelConstants.getVoxelMapInstance().getWorldSeed());
51+
} catch (IllegalArgumentException ignored) {
52+
}
53+
structureIds.addAll(SeedMapperDatapackManager.readImportedStructureIds(settings.datapackCachePath, seed));
4954
structureIds.sort(Comparator.comparing(s -> s, String.CASE_INSENSITIVE_ORDER));
5055
clampScroll();
5156
refreshButtons();

common/src/main/java/com/mamiyaotaru/voxelmap/persistent/GuiPersistentMap.java

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,13 +1856,21 @@ private void drawSeedMapperFeatureStrip(GuiGraphicsExtractor graphics, int mouse
18561856
int x = startX + titleWidth + stripPad + 8;
18571857
int contentEnd = this.width - this.sideMargin - 6;
18581858
int perPage = Math.max(1, (contentEnd - x) / (iconSize + gap));
1859-
List<SeedMapperFeature> visibleFeatures = new ArrayList<>();
1859+
List<LegendEntry> visibleEntries = new ArrayList<>();
18601860
for (SeedMapperFeature feature : SeedMapperFeature.values()) {
1861+
if (feature == SeedMapperFeature.DATAPACK_STRUCTURE) {
1862+
continue;
1863+
}
18611864
if (featureMatchesDimension(feature, currentDimension) && isSeedMapperFeatureVisible(feature)) {
1862-
visibleFeatures.add(feature);
1865+
visibleEntries.add(LegendEntry.feature(feature));
1866+
}
1867+
}
1868+
if (seedMapperOptions.datapackEnabled && seedMapperOptions.isFeatureEnabled(SeedMapperFeature.DATAPACK_STRUCTURE)) {
1869+
for (String structureId : visibleDatapackLegendStructureIds()) {
1870+
visibleEntries.add(LegendEntry.datapack(structureId));
18631871
}
18641872
}
1865-
SeedMapperFeature[] all = visibleFeatures.toArray(SeedMapperFeature[]::new);
1873+
LegendEntry[] all = visibleEntries.toArray(LegendEntry[]::new);
18661874
seedMapperLegendMaxPage = Math.max(0, (all.length - 1) / perPage);
18671875
if (seedMapperLegendPage > seedMapperLegendMaxPage) {
18681876
seedMapperLegendPage = seedMapperLegendMaxPage;
@@ -1871,8 +1879,8 @@ private void drawSeedMapperFeatureStrip(GuiGraphicsExtractor graphics, int mouse
18711879
int startIndex = seedMapperLegendPage * perPage;
18721880
int endIndex = Math.min(all.length, startIndex + perPage);
18731881
for (int i = startIndex; i < endIndex; i++) {
1874-
SeedMapperFeature feature = all[i];
1875-
seedMapperIconHitboxes.add(new FeatureIconHitbox(feature, x, y + (barHeight - iconSize) / 2, iconSize));
1882+
LegendEntry entry = all[i];
1883+
seedMapperIconHitboxes.add(new FeatureIconHitbox(entry.feature(), entry.datapackStructureId(), x, y + (barHeight - iconSize) / 2, iconSize));
18761884
x += iconSize + gap;
18771885
}
18781886

@@ -1918,13 +1926,19 @@ private void drawSeedMapperFeatureStrip(GuiGraphicsExtractor graphics, int mouse
19181926
if (!seedMapperIconHitboxes.isEmpty()) {
19191927
for (FeatureIconHitbox hitbox : seedMapperIconHitboxes) {
19201928
SeedMapperFeature feature = hitbox.feature();
1921-
boolean enabled = isFeatureEnabledInPanel(feature);
1929+
boolean datapackStructure = hitbox.datapackStructureId() != null;
1930+
boolean enabled = datapackStructure || isFeatureEnabledInPanel(feature);
19221931
int color = enabled ? 0xFFFFFFFF : 0x55FFFFFF;
1923-
VoxelMapGuiGraphics.blitFloat(graphics, RenderPipelines.GUI_TEXTURED, feature.icon(), hitbox.x(), hitbox.y(), iconSize, iconSize, 0, 1, 0, 1, color);
1932+
if (datapackStructure) {
1933+
drawDatapackLegendIcon(graphics, hitbox.datapackStructureId(), hitbox.x(), hitbox.y(), iconSize);
1934+
} else {
1935+
VoxelMapGuiGraphics.blitFloat(graphics, RenderPipelines.GUI_TEXTURED, feature.icon(), hitbox.x(), hitbox.y(), iconSize, iconSize, 0, 1, 0, 1, color);
1936+
}
19241937
if (mouseX >= hitbox.x() && mouseX <= hitbox.x() + iconSize && mouseY >= hitbox.y() && mouseY <= hitbox.y() + iconSize) {
19251938
graphics.requestCursor(CursorTypes.CROSSHAIR);
1926-
Component tooltip = Component.translatable(feature.translationKey())
1927-
.append(Component.literal(enabled ? " (ON)" : " (OFF)"));
1939+
Component tooltip = datapackStructure
1940+
? Component.literal(hitbox.datapackStructureId() + " (ON)")
1941+
: Component.translatable(feature.translationKey()).append(Component.literal(enabled ? " (ON)" : " (OFF)"));
19281942
renderTooltip(graphics, tooltip, mouseX, mouseY);
19291943
}
19301944
}
@@ -1961,6 +1975,13 @@ private boolean handleSeedMapperIconClick(int mouseX, int mouseY) {
19611975
}
19621976
for (FeatureIconHitbox hitbox : seedMapperIconHitboxes) {
19631977
if (hitbox.contains(mouseX, mouseY)) {
1978+
if (hitbox.datapackStructureId() != null) {
1979+
seedMapperOptions.setDatapackStructureEnabled(currentSeedMapperWorldKey(), hitbox.datapackStructureId(), false);
1980+
seedMapperSavedToggles = null;
1981+
seedMapperIsolatedFeature = null;
1982+
MapSettingsManager.instance.saveAll();
1983+
return true;
1984+
}
19641985
boolean ctrlDown = isCtrlDown();
19651986
SeedMapperFeature clicked = hitbox.feature();
19661987
if (isPortalFeature(clicked)) {
@@ -2027,6 +2048,37 @@ private boolean isSeedMapperFeatureVisible(SeedMapperFeature feature) {
20272048
return true;
20282049
}
20292050

2051+
private List<String> visibleDatapackLegendStructureIds() {
2052+
long seed;
2053+
try {
2054+
seed = seedMapperOptions.resolveSeed(VoxelConstants.getVoxelMapInstance().getWorldSeed());
2055+
} catch (IllegalArgumentException ignored) {
2056+
return List.of();
2057+
}
2058+
String worldKey = currentSeedMapperWorldKey();
2059+
Set<String> disabled = seedMapperOptions.getDisabledDatapackStructures(worldKey);
2060+
ArrayList<String> ids = new ArrayList<>();
2061+
for (String id : SeedMapperImportedDatapackManager.importedStructureIds(seedMapperOptions.datapackCachePath, seed)) {
2062+
if (!disabled.contains(id)) {
2063+
ids.add(id);
2064+
}
2065+
}
2066+
return ids;
2067+
}
2068+
2069+
private void drawDatapackLegendIcon(GuiGraphicsExtractor graphics, String structureId, int x, int y, int iconSize) {
2070+
int color = SeedMapperImportedDatapackManager.colorForStructureId(structureId);
2071+
if (SeedMapperImportedDatapackManager.usesPotionIcon()) {
2072+
Identifier potion = SeedMapperImportedDatapackManager.iconForStructureId(structureId);
2073+
Identifier overlay = SeedMapperImportedDatapackManager.iconOverlayForStructureId(structureId);
2074+
VoxelMapGuiGraphics.blitFloat(graphics, RenderPipelines.GUI_TEXTURED, potion, x, y, iconSize, iconSize, 0, 1, 0, 1, 0xFFFFFFFF);
2075+
VoxelMapGuiGraphics.blitFloat(graphics, RenderPipelines.GUI_TEXTURED, overlay, x, y, iconSize, iconSize, 0, 1, 0, 1, color);
2076+
return;
2077+
}
2078+
graphics.fill(x - 1, y - 1, x + iconSize + 1, y + iconSize + 1, 0xFF000000);
2079+
graphics.fill(x, y, x + iconSize, y + iconSize, color);
2080+
}
2081+
20302082
private boolean isPortalFeature(SeedMapperFeature feature) {
20312083
return feature == SeedMapperFeature.NETHER_PORTAL
20322084
|| feature == SeedMapperFeature.END_PORTAL
@@ -2685,7 +2737,17 @@ private void centerOnWorldSpawn() {
26852737
}
26862738
}
26872739

2688-
private record FeatureIconHitbox(SeedMapperFeature feature, int x, int y, int size) {
2740+
private record LegendEntry(SeedMapperFeature feature, String datapackStructureId) {
2741+
private static LegendEntry feature(SeedMapperFeature feature) {
2742+
return new LegendEntry(feature, null);
2743+
}
2744+
2745+
private static LegendEntry datapack(String structureId) {
2746+
return new LegendEntry(SeedMapperFeature.DATAPACK_STRUCTURE, structureId);
2747+
}
2748+
}
2749+
2750+
private record FeatureIconHitbox(SeedMapperFeature feature, String datapackStructureId, int x, int y, int size) {
26892751
private boolean contains(int mouseX, int mouseY) {
26902752
return mouseX >= x && mouseX <= x + size && mouseY >= y && mouseY <= y + size;
26912753
}

common/src/main/java/com/mamiyaotaru/voxelmap/seedmapper/SeedMapperDatapackManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,19 @@ public static ImportResult importFromUrl(String urlString) throws IOException {
5555
}
5656

5757
public static List<String> readImportedStructureIds(String datapackRootPath) {
58+
return readImportedStructureIds(datapackRootPath, Long.MIN_VALUE);
59+
}
60+
61+
public static List<String> readImportedStructureIds(String datapackRootPath, long seed) {
5862
if (datapackRootPath == null || datapackRootPath.isBlank()) {
5963
return List.of();
6064
}
65+
if (seed != Long.MIN_VALUE) {
66+
List<String> worldgenIds = SeedMapperImportedDatapackManager.importedStructureIds(datapackRootPath, seed);
67+
if (!worldgenIds.isEmpty()) {
68+
return worldgenIds;
69+
}
70+
}
6171
Path root = Path.of(datapackRootPath);
6272
if (!Files.isDirectory(root)) {
6373
return List.of();

0 commit comments

Comments
 (0)