diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/chunk_deadlock/ServerChunkCacheMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/chunk_deadlock/ServerChunkCacheMixin.java index 71dba962..528b26b4 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/chunk_deadlock/ServerChunkCacheMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/chunk_deadlock/ServerChunkCacheMixin.java @@ -33,7 +33,7 @@ public abstract class ServerChunkCacheMixin { @Inject(method = "getChunk", at = @At("HEAD"), cancellable = true) private void bailIfServerDead(int chunkX, int chunkZ, ChunkStatus requiredStatus, boolean load, CallbackInfoReturnable cir) { - if(!this.mainThread.isAlive()) { + if(!this.level.getServer().isRunning() && !this.mainThread.isAlive()) { ModernFix.LOGGER.fatal("A mod is accessing chunks from a stopped server (this will also cause memory leaks)"); if(debugDeadServerAccess) { new Exception().printStackTrace(); diff --git a/common/src/main/java/org/embeddedt/modernfix/structure/CachingStructureManager.java b/common/src/main/java/org/embeddedt/modernfix/structure/CachingStructureManager.java index b5ed3b88..365fb4d7 100644 --- a/common/src/main/java/org/embeddedt/modernfix/structure/CachingStructureManager.java +++ b/common/src/main/java/org/embeddedt/modernfix/structure/CachingStructureManager.java @@ -49,6 +49,12 @@ public class CachingStructureManager { private static final Set 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 { byte[] structureBytes = toBytes(stream); CompoundTag currentTag = NbtIo.readCompressed(new ByteArrayInputStream(structureBytes)); @@ -57,20 +63,22 @@ public class CachingStructureManager { } int currentDataVersion = currentTag.getInt("DataVersion"); 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 */ MessageDigest hasher = digestThreadLocal.get(); hasher.reset(); 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()) { ModernFix.LOGGER.debug("Using cached upgraded version of {}", location); currentTag = cachedUpgraded; } 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); currentTag = NbtUtils.update(datafixer, DataFixTypes.STRUCTURE, currentTag, currentDataVersion, SharedConstants.getCurrentVersion().getWorldVersion()); @@ -99,7 +107,7 @@ public class CachingStructureManager { } private static synchronized void saveCachedUpgraded(ResourceLocation location, String hash, CompoundTag tagToSave) { - File theFile = getCachePath(location, hash); + File theFile = getCachePath(location, truncateHash(hash)); try { NbtIo.writeCompressed(tagToSave, theFile); } catch(IOException e) {