Shorten structure hashes to fix issues on Windows
This commit is contained in:
parent
03abdfdc49
commit
bcb33a1018
|
|
@ -49,6 +49,12 @@ public class CachingStructureManager {
|
||||||
|
|
||||||
private static final Set<String> laggyStructureMods = new ObjectOpenHashSet<>();
|
private static final Set<String> laggyStructureMods = new ObjectOpenHashSet<>();
|
||||||
|
|
||||||
|
private static final int MAX_HASH_LENGTH = 9;
|
||||||
|
|
||||||
|
private static String truncateHash(String hash) {
|
||||||
|
return hash.substring(0, MAX_HASH_LENGTH + 1);
|
||||||
|
}
|
||||||
|
|
||||||
public static CompoundTag readStructureTag(ResourceLocation location, DataFixer datafixer, InputStream stream) throws IOException {
|
public static CompoundTag readStructureTag(ResourceLocation location, DataFixer datafixer, InputStream stream) throws IOException {
|
||||||
byte[] structureBytes = toBytes(stream);
|
byte[] structureBytes = toBytes(stream);
|
||||||
CompoundTag currentTag = NbtIo.readCompressed(new ByteArrayInputStream(structureBytes));
|
CompoundTag currentTag = NbtIo.readCompressed(new ByteArrayInputStream(structureBytes));
|
||||||
|
|
@ -57,20 +63,22 @@ public class CachingStructureManager {
|
||||||
}
|
}
|
||||||
int currentDataVersion = currentTag.getInt("DataVersion");
|
int currentDataVersion = currentTag.getInt("DataVersion");
|
||||||
if(currentDataVersion < SharedConstants.getCurrentVersion().getWorldVersion()) {
|
if(currentDataVersion < SharedConstants.getCurrentVersion().getWorldVersion()) {
|
||||||
synchronized (laggyStructureMods) {
|
|
||||||
if(laggyStructureMods.add(location.getNamespace())) {
|
|
||||||
ModernFix.LOGGER.warn("Mod {} is shipping outdated structure files, which can cause worldgen lag; please report this to them.", location.getNamespace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Needs upgrade, try looking up from cache */
|
/* Needs upgrade, try looking up from cache */
|
||||||
MessageDigest hasher = digestThreadLocal.get();
|
MessageDigest hasher = digestThreadLocal.get();
|
||||||
hasher.reset();
|
hasher.reset();
|
||||||
String hash = encodeHex(hasher.digest(structureBytes));
|
String hash = encodeHex(hasher.digest(structureBytes));
|
||||||
CompoundTag cachedUpgraded = getCachedUpgraded(location, hash);
|
CompoundTag cachedUpgraded = getCachedUpgraded(location, truncateHash(hash));
|
||||||
|
if(cachedUpgraded == null)
|
||||||
|
cachedUpgraded = getCachedUpgraded(location, hash); /* pick up old cache */
|
||||||
if(cachedUpgraded != null && cachedUpgraded.getInt("DataVersion") == SharedConstants.getCurrentVersion().getWorldVersion()) {
|
if(cachedUpgraded != null && cachedUpgraded.getInt("DataVersion") == SharedConstants.getCurrentVersion().getWorldVersion()) {
|
||||||
ModernFix.LOGGER.debug("Using cached upgraded version of {}", location);
|
ModernFix.LOGGER.debug("Using cached upgraded version of {}", location);
|
||||||
currentTag = cachedUpgraded;
|
currentTag = cachedUpgraded;
|
||||||
} else {
|
} else {
|
||||||
|
synchronized (laggyStructureMods) {
|
||||||
|
if(laggyStructureMods.add(location.getNamespace())) {
|
||||||
|
ModernFix.LOGGER.warn("Mod {} is shipping outdated structure files, which can cause worldgen lag; please report this to them.", location.getNamespace());
|
||||||
|
}
|
||||||
|
}
|
||||||
ModernFix.LOGGER.debug("Structure {} is being run through DFU (hash {}), this will cause launch time delays", location, hash);
|
ModernFix.LOGGER.debug("Structure {} is being run through DFU (hash {}), this will cause launch time delays", location, hash);
|
||||||
currentTag = NbtUtils.update(datafixer, DataFixTypes.STRUCTURE, currentTag, currentDataVersion,
|
currentTag = NbtUtils.update(datafixer, DataFixTypes.STRUCTURE, currentTag, currentDataVersion,
|
||||||
SharedConstants.getCurrentVersion().getWorldVersion());
|
SharedConstants.getCurrentVersion().getWorldVersion());
|
||||||
|
|
@ -99,7 +107,7 @@ public class CachingStructureManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized void saveCachedUpgraded(ResourceLocation location, String hash, CompoundTag tagToSave) {
|
private static synchronized void saveCachedUpgraded(ResourceLocation location, String hash, CompoundTag tagToSave) {
|
||||||
File theFile = getCachePath(location, hash);
|
File theFile = getCachePath(location, truncateHash(hash));
|
||||||
try {
|
try {
|
||||||
NbtIo.writeCompressed(tagToSave, theFile);
|
NbtIo.writeCompressed(tagToSave, theFile);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user