Drop the legacy structure index cleanup

structures/structure-index.json is no longer removed or skipped by validation.
Nothing is released, so an old pack that still has the file sees it reported as
a structure without a start pool.
This commit is contained in:
piexel committed 2026-11-06 10:07:32 +01:00
1 parent ab32568550
commit 4e7a46fb2d
3 files changed
+3 -74

No files matched your search

@@ -37,8 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
public final class StructureIndexService {
private static final String INDEX_PATH = ".iris/structure-index.json";
private static final String LEGACY_INDEX_PATH = "structures/structure-index.json";
private static final String LEGACY_INDEX_KEY = "structure-index";
private static final Set<String> GENERATED = ConcurrentHashMap.newKeySet();
private StructureIndexService() {
@@ -65,7 +63,6 @@ public final class StructureIndexService {
}
public static File write(IrisData data) {
removeLegacyIndex(data);
List<String> structures = IrisPlatforms.get().structureHooks().structureKeys();
List<String> sets = IrisPlatforms.get().structureHooks().structureSetKeys();
@@ -90,7 +87,6 @@ public final class StructureIndexService {
}
List<String> iris = new ArrayList<>(ModuleServices.structureKeys(data));
iris.removeIf(LEGACY_INDEX_KEY::equals);
Collections.sort(vanilla);
Collections.sort(datapack);
@@ -133,20 +129,4 @@ public final class StructureIndexService {
static File indexFile(File dataFolder) {
return new File(dataFolder, INDEX_PATH);
}
static File legacyIndexFile(File dataFolder) {
return new File(dataFolder, LEGACY_INDEX_PATH);
}
static void removeLegacyIndex(IrisData data) {
File legacyFile = legacyIndexFile(data.getDataFolder());
try {
if (Files.deleteIfExists(legacyFile.toPath())) {
data.invalidateStructureResources();
}
} catch (Throwable e) {
IrisLogging.reportError("Failed to remove legacy structure index '"
+ legacyFile.getAbsolutePath() + "'", e);
}
}
}
@@ -58,7 +58,6 @@ public final class StructureGraphValidation {
private static final List<Long> GEOMETRY_SAMPLE_SEEDS = List.of(
0L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L, 55L, 89L, 144L, 233L, 377L, 610L, 987L);
private static final int GEOMETRY_SAMPLE_ORIGIN_Y = 64;
private static final String LEGACY_INDEX_KEY = "structure-index";
private static final String OBJECTS_FOLDER = "objects";
private static final String OBJECT_EXTENSION = ".iob";
private static final String JSON_EXTENSION = ".json";
@@ -79,7 +78,7 @@ public final class StructureGraphValidation {
PackStructureResolver resolver = new PackStructureResolver(data);
for (ResourceId id : data.getPackResources().ids(StructureResources.STRUCTURES)) {
String structureKey = id.path();
if (structureKey.equals(LEGACY_INDEX_KEY) || (activeStructureKeys != null && !activeStructureKeys.contains(structureKey))) {
if (activeStructureKeys != null && !activeStructureKeys.contains(structureKey)) {
continue;
}
IrisStructure structure = StructureResources.structure(data.getPackResources(), structureKey);
@@ -14,12 +14,10 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.InOrder;
import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -27,9 +25,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -64,73 +60,27 @@ public class StructureIndexServiceTest {
}
@Test
public void legacyIndexPathRemainsExplicitForCleanup() throws Exception {
public void writeOnceWaitsForBoundHooksThenWritesOnce() throws Exception {
File pack = temporaryFolder.newFolder("pack");
assertEquals(new File(pack, "structures/structure-index.json"),
StructureIndexService.legacyIndexFile(pack));
}
@Test
public void legacyIndexIsDeletedAndStructureKeysAreRefreshed() throws Exception {
File pack = temporaryFolder.newFolder("pack");
File legacyIndex = StructureIndexService.legacyIndexFile(pack);
Files.createDirectories(legacyIndex.toPath().getParent());
Files.writeString(legacyIndex.toPath(), "{}", StandardCharsets.UTF_8);
IrisData data = mock(IrisData.class);
when(data.getDataFolder()).thenReturn(pack);
StructureIndexService.removeLegacyIndex(data);
assertFalse(legacyIndex.exists());
verify(data).invalidateStructureResources();
}
@Test
public void structureResourcesStayUntouchedWithoutALegacyIndex() throws Exception {
File pack = temporaryFolder.newFolder("pack");
IrisData data = mock(IrisData.class);
when(data.getDataFolder()).thenReturn(pack);
StructureIndexService.removeLegacyIndex(data);
verify(data, never()).invalidateStructureResources();
}
@Test
public void writeOnceWaitsForBoundHooksThenCleansBeforeEnumerating() throws Exception {
File pack = temporaryFolder.newFolder("pack");
File legacyIndex = StructureIndexService.legacyIndexFile(pack);
Files.createDirectories(legacyIndex.toPath().getParent());
Files.writeString(legacyIndex.toPath(), "{}", StandardCharsets.UTF_8);
IrisData data = mock(IrisData.class);
IrisPlatform platform = mock(IrisPlatform.class);
PlatformStructureHooks structureHooks = mock(PlatformStructureHooks.class);
ModuleResourceFixture.serveModules(data, new StructureModelModule(), new StructureModule());
when(data.getDataFolder()).thenReturn(pack);
ModuleResourceFixture.serve(data)
.resource(StructureResources.STRUCTURES, "castle", new IrisStructure())
.resource(StructureResources.STRUCTURES, "structure-index", new IrisStructure());
ModuleResourceFixture.serve(data).resource(StructureResources.STRUCTURES, "castle", new IrisStructure());
when(structureHooks.structureKeys()).thenReturn(List.of("minecraft:village", "example:castle"));
when(structureHooks.structureSetKeys()).thenReturn(List.of("minecraft:villages"));
assertNull(StructureIndexService.writeOnce(data));
assertTrue(legacyIndex.exists());
IrisPlatforms.bind(platform);
assertNull(StructureIndexService.writeOnce(data));
assertTrue(legacyIndex.exists());
when(platform.structureHooks()).thenReturn(structureHooks);
File index = StructureIndexService.writeOnce(data);
assertEquals(StructureIndexService.indexFile(pack), index);
assertTrue(index.isFile());
assertFalse(legacyIndex.exists());
InOrder order = inOrder(data, structureHooks);
order.verify(data).invalidateStructureResources();
order.verify(structureHooks).structureKeys();
order.verify(structureHooks).structureSetKeys();
assertNull(StructureIndexService.writeOnce(data));
verify(structureHooks, times(1)).structureKeys();
verify(structureHooks, times(1)).structureSetKeys();