Skip to content

Commit

Permalink
- 配置文件更新。
Browse files Browse the repository at this point in the history
  • Loading branch information
KasumiNova committed Aug 27, 2024
1 parent 05cdc70 commit b4513bb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
package github.kasuminova.stellarcore.client.model;

import github.kasuminova.stellarcore.client.util.ClassBlackList;
import github.kasuminova.stellarcore.common.config.StellarCoreConfig;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;

import java.util.Arrays;
import java.util.Optional;
import java.util.Set;

public class ParallelModelLoaderAsyncBlackList {
public class ParallelModelLoaderAsyncBlackList extends ClassBlackList {

public static final ParallelModelLoaderAsyncBlackList INSTANCE = new ParallelModelLoaderAsyncBlackList();

private final Set<Class<?>> blackList = new ReferenceOpenHashSet<>();

public ParallelModelLoaderAsyncBlackList() {
reload();
}

public void reload() {
blackList.clear();

Arrays.stream(StellarCoreConfig.PERFORMANCE.vanilla.parallelModelLoaderBlackList)
.forEach(className -> findClass(className).ifPresent(this::add));
}

public void add(Class<?> clazz) {
blackList.add(clazz);
}

public boolean isInBlackList(Class<?> clazz) {
return blackList.contains(clazz);
}

private static Optional<Class<?>> findClass(String name) {
try {
return Optional.of(Class.forName(name));
} catch (ClassNotFoundException e) {
return Optional.empty();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package github.kasuminova.stellarcore.client.util;

import github.kasuminova.stellarcore.client.model.ParallelModelLoaderAsyncBlackList;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;

import java.util.Optional;
import java.util.Set;

public abstract class ClassBlackList {


protected final Set<Class<?>> blackList = new ReferenceOpenHashSet<>();

public ClassBlackList() {
reload();
}

public abstract void reload();

public void add(Class<?> clazz) {
blackList.add(clazz);
}

public boolean isInBlackList(Class<?> clazz) {
return blackList.contains(clazz);
}

public static Optional<Class<?>> findClass(String name) {
try {
return Optional.of(Class.forName(name));
} catch (ClassNotFoundException e) {
return Optional.empty();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,12 @@ public static class Vanilla {
"(Client Performance) Caches the state of existence of each resource file in the ResourcePack,",
"avoiding the use of the resourceExists method with its excessive overhead to improve game loading performance.",
"Effective in large ModPacks and optimises the impact on startup time when installing with Optifine, with good compatibility.",
"If you encounter some resources that don't load properly (which they usually don't), reload the resource packs, this will reset the cache."
"If you encounter some resources that don't load properly (which they usually don't), reload the resource packs, this will reset the cache.",
"Incompatible with GroovyScript, and I don't know why."
})
@Config.RequiresMcRestart
@Config.Name("ResourceExistStateCache")
public boolean resourceExistStateCache = true;
public boolean resourceExistStateCache = false;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import net.minecraft.client.resources.AbstractResourcePack;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -29,9 +31,9 @@ private static String locationToName(final ResourceLocation location) {
* @author Kasumi_Nova
* @reason Cache
*/
@Overwrite
public boolean resourceExists(ResourceLocation location) {
return stellar_core$resourceExistsCache.computeIfAbsent(location, (key) -> this.hasResourceName(locationToName(location)));
@Inject(method = "resourceExists", at = @At("HEAD"), cancellable = true)
public void injectResourceExists(final ResourceLocation location, final CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(stellar_core$resourceExistsCache.computeIfAbsent(location, (key) -> this.hasResourceName(locationToName(location))));
}

@Unique
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import net.minecraft.client.resources.ResourceIndex;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import javax.annotation.Nullable;
import java.io.InputStream;
Expand All @@ -29,10 +32,10 @@ public abstract class MixinDefaultResourcePack implements StellarCoreResourcePac
* @author Kasumi_Nova
* @reason Cache
*/
@Overwrite
public boolean resourceExists(ResourceLocation location) {
return stellar_core$resourceExistsCache.computeIfAbsent(location, (key) ->
this.getResourceStream(location) != null || this.resourceIndex.isFileExisting(location));
@Inject(method = "resourceExists", at = @At("HEAD"), cancellable = true)
public void resourceExists(final ResourceLocation location, final CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(stellar_core$resourceExistsCache.computeIfAbsent(location, (key) ->
this.getResourceStream(location) != null || this.resourceIndex.isFileExisting(location)));
}

@Unique
Expand Down

0 comments on commit b4513bb

Please sign in to comment.