Merge remote-tracking branch 'origin/main' into 1.18
This commit is contained in:
commit
bc493d624f
|
|
@ -33,7 +33,7 @@ public abstract class ServerChunkCacheMixin {
|
||||||
|
|
||||||
@Inject(method = "getChunk", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getChunk", at = @At("HEAD"), cancellable = true)
|
||||||
private void bailIfServerDead(int chunkX, int chunkZ, ChunkStatus requiredStatus, boolean load, CallbackInfoReturnable<ChunkAccess> cir) {
|
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)");
|
ModernFix.LOGGER.fatal("A mod is accessing chunks from a stopped server (this will also cause memory leaks)");
|
||||||
if(debugDeadServerAccess) {
|
if(debugDeadServerAccess) {
|
||||||
new Exception().printStackTrace();
|
new Exception().printStackTrace();
|
||||||
|
|
|
||||||
|
|
@ -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