This commit is contained in:
CCr4ft3r
2023-05-11 18:38:45 +02:00
parent e373e4d8ed
commit bd31d4bf6b
8 changed files with 8 additions and 11 deletions
@@ -19,5 +19,7 @@ public class Main {
if (CompatUtil.existsClass("net.minecraftforge.resource.ResourceCacheManager")
&& ResourceCacheManager.shouldUseCache())
GlobalCache.shouldCacheEmptyNamespaces = false;
if (ModList.get().isLoaded(ModConstants.MULTIBLOCKED_ID))
GlobalCache.shouldCacheMaterials = false;
}
}
@@ -5,4 +5,5 @@ public class ModConstants {
public static final String MOD_ID = "lightspeed";
public static final String JSON_THINGS_ID = "jsonthings";
public static final String SOPHISTICATED_STORAGE_ID = "sophisticatedstorage";
public static final String MULTIBLOCKED_ID = "multiblocked";
}
@@ -20,6 +20,7 @@ public class GlobalCache {
public static Boolean isEnabled = true;
public static Boolean shouldCacheWalkedPaths = true;
public static Boolean shouldCacheEmptyNamespaces = true;
public static Boolean shouldCacheMaterials = true;
public static final Map<CharSequence, List<String>> SPLITTED_STRINGS_BY_SEQUENCE = Maps.newConcurrentMap();
public static final Map<String, String> CANONICAL_PATH_PER_FILE = Maps.newConcurrentMap();
private static final Set<ICache> CACHES = Sets.newConcurrentHashSet();
@@ -22,7 +22,7 @@ public abstract class BlockModelMixin {
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
public void getMaterialsHeadInjected(Function<ResourceLocation, UnbakedModel> p_111855_, Set<Pair<String, String>> p_111856_, CallbackInfoReturnable<Collection<Material>> cir) {
if (GlobalCache.isEnabled && materials != null)
if (GlobalCache.isEnabled && materials != null && GlobalCache.shouldCacheMaterials)
cir.setReturnValue(materials);
}
@@ -35,7 +35,7 @@ public abstract class MultiPartMixin implements UnbakedModel {
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
public void getMaterialsHeadInjected(Function<ResourceLocation, UnbakedModel> p_111855_, Set<Pair<String, String>> p_111856_, CallbackInfoReturnable<Collection<Material>> cir) {
if (GlobalCache.isEnabled && materials != null)
if (GlobalCache.isEnabled && materials != null && GlobalCache.shouldCacheMaterials)
cir.setReturnValue(materials);
}
@@ -30,7 +30,7 @@ public abstract class MultivariantMixin implements UnbakedModel {
@Inject(method = "getMaterials", at = @At("HEAD"), cancellable = true)
public void getMaterialsHeadInjected(Function<ResourceLocation, UnbakedModel> p_111855_, Set<Pair<String, String>> p_111856_, CallbackInfoReturnable<Collection<Material>> cir) {
if (GlobalCache.isEnabled && materials != null)
if (GlobalCache.isEnabled && materials != null && GlobalCache.shouldCacheMaterials)
cir.setReturnValue(materials);
}
@@ -9,11 +9,9 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List;
import java.util.stream.Stream;
@Mixin(DelegatingResourcePack.class)
public abstract class DelegatingResourcePackMixin {
@@ -27,9 +25,4 @@ public abstract class DelegatingResourcePackMixin {
return;
cir.setReturnValue(getCandidatePacks(type, location).parallelStream().anyMatch(p -> p.hasResource(type, location)));
}
@Redirect(method = "getResources", at = @At(value = "INVOKE", target = "Ljava/util/List;stream()Ljava/util/stream/Stream;"))
public <R> Stream<R> getResourcesStreamRedirected(List<R> instance) {
return !GlobalCache.isEnabled ? instance.stream() : instance.parallelStream();
}
}