Merge remote-tracking branch 'origin/1.18' into 1.19.2

This commit is contained in:
embeddedt 2023-05-10 09:56:43 -04:00
commit 8c278d6555
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 16 additions and 8 deletions

View File

@ -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<ChunkAccess> 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();

View File

@ -49,6 +49,12 @@ public class CachingStructureManager {
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 {
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) {