Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.sinthoras.visualprospecting.database.veintypes.VeinType;
import com.sinthoras.visualprospecting.database.veintypes.VeinTypeCaching;

import gregtech.common.GTWorldgenerator;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;

/**
Expand Down Expand Up @@ -89,12 +90,15 @@ public void loadFromNbt(NBTTagCompound compound) {
return;
}

NBTTagCompound ores = compound.getCompoundTag("ores");
if (version == CURRENT_FORMAT_VERSION) {
loadOres(compound.getCompoundTag("ores"));
loadOres(ores);
loadFluids(compound.getCompoundTag("fluids"));
} else {
// version key absent => v2 or older
LegacyDimensionCacheLoader.loadV2Ores(this, compound.getCompoundTag("ores"));
if (ores.hasNoTags() || canRepairVeinCoordinates()) {
LegacyDimensionCacheLoader.loadV2Ores(this, ores);
}
LegacyDimensionCacheLoader.loadV2Fluids(this, compound.getCompoundTag("fluids"));
}
}
Expand Down Expand Up @@ -127,6 +131,8 @@ private void loadOres(NBTTagCompound ores) {
int size = chunkXArray.length;
oreChunks.ensureCapacity(oreChunks.size() + size);

if (!canRepairVeinCoordinates()) return;

int unknownVeinTypes = 0;
int repairedCoordinates = 0;
int discardedRescans = 0;
Expand Down Expand Up @@ -190,6 +196,19 @@ private void loadOres(NBTTagCompound ores) {
}
}

private boolean canRepairVeinCoordinates() {
boolean patternVerified = GTWorldgenerator.isOregenPatternVerified();
if (!patternVerified) {
preventSaving = true;
VP.LOG.warn(
"Dimension {}: ore vein pattern is not confirmed. This cache is read-only for the session; "
+ "changes will not be saved. After confirming the pattern with "
+ "/gt oregenpattern set <pattern> confirm, restart the world/server and reconnect clients.",
dimensionId);
}
return patternVerified;
}

private void loadFluids(NBTTagCompound fluids) {
if (!fluids.hasKey("palette")) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import com.sinthoras.visualprospecting.Tags;
import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.VP;

import gregtech.common.GTWorldgenerator;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

Expand All @@ -29,18 +31,18 @@ public boolean loadVeinCache(String worldId) {
isLoaded = true;
worldCache = new File(getStorageDirectory(), worldId);

if (loadLegacyVeinCache(worldCache)) return true;

final File[] dimensionFiles = worldCache.listFiles();
if (dimensionFiles == null || dimensionFiles.length == 0) return false;
if (dimensionFiles == null) return loadLegacyVeinCache(worldCache);

boolean loadedAny = false;
boolean hasNbtCache = false;
boolean requiresOreRescan = false;
for (File dimensionFile : dimensionFiles) {
final String fileName = dimensionFile.getName();
if (!dimensionFile.isFile() || !fileName.endsWith(".dat")) {
continue;
}
hasNbtCache = true;

final NBTTagCompound dimCompound = Utils.readNBT(dimensionFile);
if (dimCompound == null) continue;
Expand All @@ -52,7 +54,7 @@ public boolean loadVeinCache(String worldId) {
loadedAny = true;
}

return loadedAny && !requiresOreRescan;
return hasNbtCache ? loadedAny && !requiresOreRescan : loadLegacyVeinCache(worldCache);
}

private boolean loadLegacyVeinCache(File worldCacheDirectory) {
Expand All @@ -66,6 +68,13 @@ private boolean loadLegacyVeinCache(File worldCacheDirectory) {
final Map<Integer, ByteBuffer> oreVeinDimensionBuffers = Utils.getLegacyDimFiles(oreVeinCacheDirectory);
final Map<Integer, ByteBuffer> undergroundFluidDimensionBuffers = Utils
.getLegacyDimFiles(undergroundFluidCacheDirectory);
if (!oreVeinDimensionBuffers.isEmpty() && !GTWorldgenerator.isOregenPatternVerified()) {
VP.LOG.warn(
"Ore vein pattern is not confirmed, deferring legacy cache migration. After confirming the pattern "
+ "with /gt oregenpattern set <pattern> confirm, restart the world/server.");
return true;
}

final Set<Integer> dimensionsIds = new HashSet<>();
dimensionsIds.addAll(oreVeinDimensionBuffers.keySet());
dimensionsIds.addAll(undergroundFluidDimensionBuffers.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sinthoras.visualprospecting.Utils;
import com.sinthoras.visualprospecting.VP;

import gregtech.common.GTWorldgenerator;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
Expand Down Expand Up @@ -77,7 +78,12 @@ private void ensureExpanded() {
}
pendingBlob = null;
}
repairedVeinCoordinates = normalizeVeinCoordinates(discoveredVeins) | normalizeVeinCoordinates(depletedVeins);
if (GTWorldgenerator.isOregenPatternVerified()) {
repairedVeinCoordinates = normalizeVeinCoordinates(discoveredVeins)
| normalizeVeinCoordinates(depletedVeins);
} else {
VP.LOG.warn("Ore vein pattern is not confirmed, leaving team prospection coordinates untouched.");
}
expanded = true;
}

Expand Down