Merge remote-tracking branch 'origin/1.18' into 1.19.2
This commit is contained in:
commit
a1eb62a176
|
|
@ -2,7 +2,10 @@ package org.embeddedt.modernfix.core.config;
|
||||||
|
|
||||||
import net.minecraftforge.fml.loading.FMLLoader;
|
import net.minecraftforge.fml.loading.FMLLoader;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator;
|
import net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator;
|
||||||
|
import net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
|
||||||
|
import net.minecraftforge.forgespi.locating.IModLocator;
|
||||||
|
import net.minecraftforge.forgespi.locating.IModProvider;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -68,6 +71,7 @@ public class ModernFixEarlyConfig {
|
||||||
this.addMixinRule("perf.fast_forge_dummies", true);
|
this.addMixinRule("perf.fast_forge_dummies", true);
|
||||||
this.addMixinRule("perf.dynamic_structure_manager", true);
|
this.addMixinRule("perf.dynamic_structure_manager", true);
|
||||||
this.addMixinRule("bugfix.chunk_deadlock", true);
|
this.addMixinRule("bugfix.chunk_deadlock", true);
|
||||||
|
this.addMixinRule("bugfix.remove_block_chunkloading", true);
|
||||||
this.addMixinRule("bugfix.paper_chunk_patches", true);
|
this.addMixinRule("bugfix.paper_chunk_patches", true);
|
||||||
this.addMixinRule("perf.thread_priorities", true);
|
this.addMixinRule("perf.thread_priorities", true);
|
||||||
this.addMixinRule("perf.scan_cache", true);
|
this.addMixinRule("perf.scan_cache", true);
|
||||||
|
|
@ -89,8 +93,10 @@ public class ModernFixEarlyConfig {
|
||||||
this.addMixinRule("perf.blast_search_trees", FMLLoader.getLoadingModList().getModFileById("jei") != null || FMLLoader.getLoadingModList().getModFileById("roughlyenoughitems") != null);
|
this.addMixinRule("perf.blast_search_trees", FMLLoader.getLoadingModList().getModFileById("jei") != null || FMLLoader.getLoadingModList().getModFileById("roughlyenoughitems") != null);
|
||||||
this.addMixinRule("safety", true);
|
this.addMixinRule("safety", true);
|
||||||
this.addMixinRule("launch.class_search_cache", true);
|
this.addMixinRule("launch.class_search_cache", true);
|
||||||
boolean isDevEnv = !FMLLoader.isProduction() && FMLLoader.getLoadingModList().getModFileById("modernfix").getFile().getProvider() instanceof ExplodedDirectoryLocator;
|
IModProvider mfLocator = FMLLoader.getLoadingModList().getModFileById("modernfix").getFile().getProvider();
|
||||||
|
boolean isDevEnv = !FMLLoader.isProduction() && (mfLocator instanceof ExplodedDirectoryLocator || mfLocator instanceof MinecraftLocator);
|
||||||
this.addMixinRule("devenv", isDevEnv);
|
this.addMixinRule("devenv", isDevEnv);
|
||||||
|
this.addMixinRule("perf.remove_spawn_chunks", isDevEnv);
|
||||||
|
|
||||||
/* Mod compat */
|
/* Mod compat */
|
||||||
disableIfModPresent("mixin.perf.thread_priorities", "smoothboot");
|
disableIfModPresent("mixin.perf.thread_priorities", "smoothboot");
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
package org.embeddedt.modernfix.mixin.devenv;
|
|
||||||
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.server.level.ServerChunkCache;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
|
|
||||||
/* Disable waiting for spawn chunk load */
|
|
||||||
@Mixin(MinecraftServer.class)
|
|
||||||
public class MinecraftServerMixin {
|
|
||||||
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;getTickingGenerated()I"))
|
|
||||||
private int noSpawnChunkWait(ServerChunkCache cache) {
|
|
||||||
return 441;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;waitUntilNextTick()V"))
|
|
||||||
private void noWaitTick(MinecraftServer server) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -9,6 +9,7 @@ import net.minecraft.world.item.Item;
|
||||||
import net.minecraftforge.client.model.ForgeItemModelShaper;
|
import net.minecraftforge.client.model.ForgeItemModelShaper;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
import org.embeddedt.modernfix.dynamicresources.ModelLocationCache;
|
||||||
|
import org.embeddedt.modernfix.util.ItemMesherMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.*;
|
import org.spongepowered.asm.mixin.*;
|
||||||
|
|
@ -37,71 +38,7 @@ public abstract class ItemModelShaperMixin extends ItemModelShaper {
|
||||||
private void replaceLocationMap(CallbackInfo ci) {
|
private void replaceLocationMap(CallbackInfo ci) {
|
||||||
overrideLocations = new HashMap<>();
|
overrideLocations = new HashMap<>();
|
||||||
// need to replace this map because mods query locations through it
|
// need to replace this map because mods query locations through it
|
||||||
locations = new Map<Holder.Reference<Item>, ModelResourceLocation>() {
|
locations = new ItemMesherMap(this::getLocation);
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return ForgeRegistries.ITEMS.getValues().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsKey(Object key) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsValue(Object value) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ModelResourceLocation get(Object key) {
|
|
||||||
return getLocation(((Holder.Reference<Item>)key).get());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public ModelResourceLocation put(Holder.Reference<Item> key, ModelResourceLocation value) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ModelResourceLocation remove(Object key) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putAll(@NotNull Map<? extends Holder.Reference<Item>, ? extends ModelResourceLocation> m) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<Holder.Reference<Item>> keySet() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<ModelResourceLocation> values() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Set<Entry<Holder.Reference<Item>, ModelResourceLocation>> entrySet() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModelResourceLocation getLocation(Item item) {
|
private ModelResourceLocation getLocation(Item item) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,11 @@
|
||||||
package org.embeddedt.modernfix.mixin.perf.modern_resourcepacks;
|
package org.embeddedt.modernfix.mixin.perf.modern_resourcepacks;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraftforge.resource.PathPackResources;
|
import net.minecraftforge.resource.PathPackResources;
|
||||||
import org.embeddedt.modernfix.util.CachedResourcePath;
|
import org.embeddedt.modernfix.resources.PackResourcesCacheEngine;
|
||||||
import org.embeddedt.modernfix.util.FileUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.embeddedt.modernfix.util.PackTypeHelper;
|
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
|
@ -17,14 +13,9 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The built-in resource caching provided by Forge is overengineered and doesn't work correctly
|
* The built-in resource caching provided by Forge is overengineered and doesn't work correctly
|
||||||
|
|
@ -36,107 +27,39 @@ public abstract class PathPackResourcesMixin {
|
||||||
|
|
||||||
@Shadow protected abstract Path resolve(String... paths);
|
@Shadow protected abstract Path resolve(String... paths);
|
||||||
|
|
||||||
@Shadow @Final private String packName;
|
@Shadow @NotNull
|
||||||
@Shadow @Final private Path source;
|
protected abstract Set<String> getNamespacesFromDisk(PackType type);
|
||||||
|
|
||||||
@Shadow @NotNull protected abstract Set<String> getNamespacesFromDisk(PackType type);
|
private PackResourcesCacheEngine cacheEngine;
|
||||||
|
|
||||||
private EnumMap<PackType, Set<String>> namespacesByType;
|
|
||||||
private EnumMap<PackType, HashMap<String, List<CachedResourcePath>>> rootListingByNamespaceAndType;
|
|
||||||
private boolean hasGeneratedListings;
|
|
||||||
private Set<CachedResourcePath> containedPaths;
|
|
||||||
|
|
||||||
private FileSystem resourcePackFS;
|
|
||||||
|
|
||||||
private static Joiner slashJoiner = Joiner.on('/');
|
|
||||||
|
|
||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void cacheResources(String packName, Path source, CallbackInfo ci) {
|
private void cacheResources(String packName, Path source, CallbackInfo ci) {
|
||||||
this.resourcePackFS = source.getFileSystem();
|
this.cacheEngine = null;
|
||||||
this.namespacesByType = new EnumMap<>(PackType.class);
|
|
||||||
this.hasGeneratedListings = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateResourceCache() {
|
private void generateResourceCache() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if(hasGeneratedListings)
|
if(this.cacheEngine != null)
|
||||||
return;
|
return;
|
||||||
EnumMap<PackType, HashMap<String, List<CachedResourcePath>>> rootListingByNamespaceAndType = new EnumMap<>(PackType.class);
|
this.cacheEngine = new PackResourcesCacheEngine(this::getNamespacesFromDisk, (type, namespace) -> this.resolve(type.getDirectory(), namespace));
|
||||||
HashSet<CachedResourcePath> containedPaths = new HashSet<>();
|
|
||||||
for(PackType type : PackType.values()) {
|
|
||||||
Set<String> namespaces = this.getNamespacesFromDisk(type);
|
|
||||||
HashMap<String, List<CachedResourcePath>> rootListingForNamespaces = new HashMap<>();
|
|
||||||
for(String namespace : namespaces) {
|
|
||||||
try {
|
|
||||||
Path root = this.resolve(type.getDirectory(), namespace).toAbsolutePath();
|
|
||||||
try (Stream<Path> stream = Files.walk(root)) {
|
|
||||||
ArrayList<CachedResourcePath> rootListingPaths = new ArrayList<>();
|
|
||||||
stream
|
|
||||||
.map(path -> root.relativize(path.toAbsolutePath()))
|
|
||||||
.filter(this::isValidCachedResourcePath)
|
|
||||||
.forEach(path -> {
|
|
||||||
CachedResourcePath listing = new CachedResourcePath(path);
|
|
||||||
if(!listing.getFileName().endsWith(".mcmeta")) {
|
|
||||||
rootListingPaths.add(listing);
|
|
||||||
}
|
|
||||||
containedPaths.add(new CachedResourcePath(new String[] { type.getDirectory(), namespace }, listing));
|
|
||||||
});
|
|
||||||
rootListingPaths.trimToSize();
|
|
||||||
rootListingForNamespaces.put(namespace, rootListingPaths);
|
|
||||||
}
|
|
||||||
} catch(IOException e) {
|
|
||||||
rootListingForNamespaces.put(namespace, Collections.emptyList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(PackTypeHelper.isVanillaPackType(type))
|
|
||||||
rootListingByNamespaceAndType.put(type, rootListingForNamespaces);
|
|
||||||
}
|
|
||||||
this.rootListingByNamespaceAndType = rootListingByNamespaceAndType;
|
|
||||||
this.containedPaths = containedPaths;
|
|
||||||
this.hasGeneratedListings = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidCachedResourcePath(Path path) {
|
|
||||||
if(path.getFileName() == null || path.getNameCount() == 0)
|
|
||||||
return false;
|
|
||||||
String str = path.toString();
|
|
||||||
if(str.length() == 0)
|
|
||||||
return false;
|
|
||||||
for(int i = 0; i < str.length(); i++) {
|
|
||||||
if(!ResourceLocation.validPathChar(str.charAt(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
|
||||||
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
private void useCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
||||||
if(!PackTypeHelper.isVanillaPackType(type))
|
if(!PackTypeHelper.isVanillaPackType(type))
|
||||||
return;
|
return;
|
||||||
Set<String> cachedNamespaces;
|
if(this.cacheEngine != null) {
|
||||||
synchronized (this.namespacesByType) {
|
Set<String> namespaces = this.cacheEngine.getNamespaces(type);
|
||||||
cachedNamespaces = this.namespacesByType.get(type);
|
if(namespaces != null)
|
||||||
}
|
cir.setReturnValue(namespaces);
|
||||||
if(cachedNamespaces != null) {
|
|
||||||
cir.setReturnValue(cachedNamespaces);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "getNamespaces", at = @At("TAIL"))
|
|
||||||
private void storeCacheForNamespaces(PackType type, CallbackInfoReturnable<Set<String>> cir) {
|
|
||||||
if(!PackTypeHelper.isVanillaPackType(type))
|
|
||||||
return;
|
|
||||||
synchronized (this.namespacesByType) {
|
|
||||||
this.namespacesByType.put(type, cir.getReturnValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "hasResource(Ljava/lang/String;)Z", at = @At(value = "HEAD"), cancellable = true)
|
@Inject(method = "hasResource(Ljava/lang/String;)Z", at = @At(value = "HEAD"), cancellable = true)
|
||||||
private void useCacheForExistence(String path, CallbackInfoReturnable<Boolean> cir) {
|
private void useCacheForExistence(String path, CallbackInfoReturnable<Boolean> cir) {
|
||||||
this.generateResourceCache();
|
this.generateResourceCache();
|
||||||
cir.setReturnValue(this.containedPaths.contains(new CachedResourcePath(path)));
|
cir.setReturnValue(this.cacheEngine.hasResource(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,17 +72,6 @@ public abstract class PathPackResourcesMixin {
|
||||||
if(!PackTypeHelper.isVanillaPackType(type))
|
if(!PackTypeHelper.isVanillaPackType(type))
|
||||||
return;
|
return;
|
||||||
this.generateResourceCache();
|
this.generateResourceCache();
|
||||||
if(!pathIn.endsWith("/"))
|
cir.setReturnValue(this.cacheEngine.getResources(type, resourceNamespace, pathIn, Integer.MAX_VALUE, filter));
|
||||||
pathIn = pathIn + "/";
|
|
||||||
final String testPath = pathIn;
|
|
||||||
Collection<ResourceLocation> cachedListing = this.rootListingByNamespaceAndType.get(type).getOrDefault(resourceNamespace, Collections.emptyList()).stream().
|
|
||||||
filter(path -> path.getFullPath().startsWith(testPath)). // Make sure the target path is inside this one
|
|
||||||
// Finally we need to form the RL, so use the first name as the domain, and the rest as the path
|
|
||||||
// It is VERY IMPORTANT that we do not rely on Path.toString as this is inconsistent between operating systems
|
|
||||||
// Join the path names ourselves to force forward slashes
|
|
||||||
map(path -> new ResourceLocation(resourceNamespace, path.getFullPath())).
|
|
||||||
filter(filter::test). // Test the file name against the predicate
|
|
||||||
collect(Collectors.toList());
|
|
||||||
cir.setReturnValue(cachedListing);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package org.embeddedt.modernfix.mixin.perf.modern_resourcepacks;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
import net.minecraft.server.packs.PackType;
|
import net.minecraft.server.packs.PackType;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.packs.VanillaPackResources;
|
import net.minecraft.server.packs.VanillaPackResources;
|
||||||
|
|
@ -41,7 +42,7 @@ public class VanillaPackResourcesMixin {
|
||||||
private void cacheContainedPaths(PackMetadataSection arg, String[] p_i47912_1_, CallbackInfo ci) {
|
private void cacheContainedPaths(PackMetadataSection arg, String[] p_i47912_1_, CallbackInfo ci) {
|
||||||
if(containedPaths != null)
|
if(containedPaths != null)
|
||||||
return;
|
return;
|
||||||
containedPaths = new HashSet<>();
|
containedPaths = new ObjectOpenHashSet<>();
|
||||||
Joiner slashJoiner = Joiner.on('/');
|
Joiner slashJoiner = Joiner.on('/');
|
||||||
for(PackType type : PackType.values()) {
|
for(PackType type : PackType.values()) {
|
||||||
if(!PackTypeHelper.isVanillaPackType(type))
|
if(!PackTypeHelper.isVanillaPackType(type))
|
||||||
|
|
@ -59,6 +60,7 @@ public class VanillaPackResourcesMixin {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
((ObjectOpenHashSet<String>)containedPaths).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "getResources(Ljava/util/Collection;Ljava/lang/String;Ljava/nio/file/Path;Ljava/lang/String;Ljava/util/function/Predicate;)V", at = @At(value = "INVOKE", target = "Ljava/nio/file/Files;walk(Ljava/nio/file/Path;[Ljava/nio/file/FileVisitOption;)Ljava/util/stream/Stream;"))
|
@Redirect(method = "getResources(Ljava/util/Collection;Ljava/lang/String;Ljava/nio/file/Path;Ljava/lang/String;Ljava/util/function/Predicate;)V", at = @At(value = "INVOKE", target = "Ljava/nio/file/Files;walk(Ljava/nio/file/Path;[Ljava/nio/file/FileVisitOption;)Ljava/util/stream/Stream;"))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.embeddedt.modernfix.mixin.perf.remove_spawn_chunks;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.DistanceManager;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
|
import net.minecraft.server.level.TicketType;
|
||||||
|
import net.minecraft.util.Unit;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(value = MinecraftServer.class, priority = 1100)
|
||||||
|
public class MinecraftServerMixin {
|
||||||
|
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
|
||||||
|
private void addSpawnChunkTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
|
||||||
|
// load first chunk
|
||||||
|
cache.getChunk(pos.x, pos.z, ChunkStatus.FULL, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "prepareLevels", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;getTickingGenerated()I"), require = 0)
|
||||||
|
private int getGenerated(ServerChunkCache cache) {
|
||||||
|
return 441;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.embeddedt.modernfix.mixin.perf.remove_spawn_chunks;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.DistanceManager;
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(ServerChunkCache.class)
|
||||||
|
public interface ServerChunkCacheAccessor {
|
||||||
|
@Accessor("distanceManager")
|
||||||
|
DistanceManager getDistanceManager();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.embeddedt.modernfix.mixin.perf.remove_spawn_chunks;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerChunkCache;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.TicketType;
|
||||||
|
import net.minecraft.world.level.ChunkPos;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
@Mixin(ServerLevel.class)
|
||||||
|
public class ServerLevelMixin {
|
||||||
|
@Redirect(method = "setDefaultSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
|
||||||
|
private void removeTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Redirect(method = "setDefaultSpawnPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
|
||||||
|
private void addTicket(ServerChunkCache cache, TicketType<?> type, ChunkPos pos, int distance, Object o) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,31 +1,23 @@
|
||||||
package org.embeddedt.modernfix.util;
|
package org.embeddedt.modernfix.resources;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Interner;
|
import com.google.common.collect.Interner;
|
||||||
import com.google.common.collect.Interners;
|
import com.google.common.collect.Interners;
|
||||||
import com.google.common.collect.Streams;
|
import org.embeddedt.modernfix.util.FileUtil;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CachedResourcePath {
|
public class CachedResourcePath {
|
||||||
private final String[] pathComponents;
|
private final String[] pathComponents;
|
||||||
private int hashCode = 0;
|
|
||||||
|
|
||||||
private static final Interner<String> PATH_COMPONENT_INTERNER = Interners.newStrongInterner();
|
public static final Interner<String> PATH_COMPONENT_INTERNER = Interners.newStrongInterner();
|
||||||
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
|
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
|
||||||
private static final Joiner SLASH_JOINER = Joiner.on('/');
|
|
||||||
private WeakReference<String> fullPathCache = new WeakReference<>(null);
|
|
||||||
private static final String[] NO_PREFIX = new String[0];
|
private static final String[] NO_PREFIX = new String[0];
|
||||||
|
|
||||||
public CachedResourcePath(Path path) {
|
public CachedResourcePath(String[] prefix, Path path) {
|
||||||
this(NO_PREFIX, path, path.getNameCount(), true);
|
this(prefix, path, path.getNameCount(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedResourcePath(String s) {
|
public CachedResourcePath(String s) {
|
||||||
|
|
@ -67,11 +59,7 @@ public class CachedResourcePath {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = hashCode;
|
return Arrays.hashCode(pathComponents);
|
||||||
if(result != 0)
|
|
||||||
return result;
|
|
||||||
hashCode = Arrays.hashCode(pathComponents);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -90,12 +78,17 @@ public class CachedResourcePath {
|
||||||
return pathComponents.length;
|
return pathComponents.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFullPath() {
|
public String getNameAt(int i) {
|
||||||
String fPath = fullPathCache.get();
|
return pathComponents[i];
|
||||||
if(fPath == null) {
|
}
|
||||||
fPath = SLASH_JOINER.join(pathComponents);
|
|
||||||
fullPathCache = new WeakReference<>(fPath);
|
public String getFullPath(int startIndex) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(int i = startIndex; i < pathComponents.length; i++) {
|
||||||
|
sb.append(pathComponents[i]);
|
||||||
|
if(i != (pathComponents.length - 1))
|
||||||
|
sb.append('/');
|
||||||
}
|
}
|
||||||
return fPath;
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
package org.embeddedt.modernfix.resources;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.PackType;
|
||||||
|
import org.embeddedt.modernfix.util.PackTypeHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class PackResourcesCacheEngine {
|
||||||
|
private final Map<PackType, Set<String>> namespacesByType;
|
||||||
|
private final Set<CachedResourcePath> containedPaths;
|
||||||
|
|
||||||
|
public PackResourcesCacheEngine(Function<PackType, Set<String>> namespacesRetriever, BiFunction<PackType, String, Path> basePathRetriever) {
|
||||||
|
this.namespacesByType = new EnumMap<>(PackType.class);
|
||||||
|
for(PackType type : PackType.values()) {
|
||||||
|
if(!PackTypeHelper.isVanillaPackType(type))
|
||||||
|
continue;
|
||||||
|
this.namespacesByType.put(type, namespacesRetriever.apply(type));
|
||||||
|
}
|
||||||
|
this.containedPaths = new ObjectOpenHashSet<>();
|
||||||
|
for(PackType type : PackType.values()) {
|
||||||
|
Collection<String> namespaces = PackTypeHelper.isVanillaPackType(type) ? this.namespacesByType.get(type) : namespacesRetriever.apply(type);
|
||||||
|
for(String namespace : namespaces) {
|
||||||
|
try {
|
||||||
|
Path root = basePathRetriever.apply(type, namespace).toAbsolutePath();
|
||||||
|
try (Stream<Path> stream = Files.walk(root)) {
|
||||||
|
stream
|
||||||
|
.map(path -> root.relativize(path.toAbsolutePath()))
|
||||||
|
.filter(PackResourcesCacheEngine::isValidCachedResourcePath)
|
||||||
|
.forEach(path -> {
|
||||||
|
this.containedPaths.add(new CachedResourcePath(new String[] { type.getDirectory(), namespace }, path));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch(IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
((ObjectOpenHashSet<CachedResourcePath>)this.containedPaths).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isValidCachedResourcePath(Path path) {
|
||||||
|
if(path.getFileName() == null || path.getNameCount() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String str = path.toString();
|
||||||
|
if(str.length() == 0)
|
||||||
|
return false;
|
||||||
|
for(int i = 0; i < str.length(); i++) {
|
||||||
|
if(!ResourceLocation.validPathChar(str.charAt(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getNamespaces(PackType type) {
|
||||||
|
if(PackTypeHelper.isVanillaPackType(type))
|
||||||
|
return this.namespacesByType.get(type);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasResource(String path) {
|
||||||
|
return this.containedPaths.contains(new CachedResourcePath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ResourceLocation> getResources(PackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<ResourceLocation> filter) {
|
||||||
|
String testPath = pathIn.endsWith("/") ? pathIn : (pathIn + "/");
|
||||||
|
ArrayList<ResourceLocation> resources = new ArrayList<>();
|
||||||
|
String typeDirectory = CachedResourcePath.PATH_COMPONENT_INTERNER.intern(type.getDirectory());
|
||||||
|
resourceNamespace = CachedResourcePath.PATH_COMPONENT_INTERNER.intern(resourceNamespace);
|
||||||
|
for(CachedResourcePath cachePath : this.containedPaths) {
|
||||||
|
if(cachePath.getNameCount() < 2)
|
||||||
|
continue;
|
||||||
|
if((cachePath.getNameCount() - 2) > maxDepth)
|
||||||
|
continue;
|
||||||
|
// we interned, so reference equality is safe
|
||||||
|
if(cachePath.getNameAt(0) != typeDirectory || cachePath.getNameAt(1) != resourceNamespace)
|
||||||
|
continue;
|
||||||
|
if(cachePath.getFileName().endsWith(".mcmeta"))
|
||||||
|
continue;
|
||||||
|
String fullPath = cachePath.getFullPath(2);
|
||||||
|
if(!fullPath.startsWith(testPath))
|
||||||
|
continue;
|
||||||
|
ResourceLocation foundResource = new ResourceLocation(resourceNamespace, fullPath);
|
||||||
|
if(!filter.test(foundResource))
|
||||||
|
continue;
|
||||||
|
resources.add(foundResource);
|
||||||
|
}
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
package org.embeddedt.modernfix.util;
|
||||||
|
|
||||||
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ItemMesherMap implements Map<Holder.Reference<Item>, ModelResourceLocation> {
|
||||||
|
private final Function<Item, ModelResourceLocation> getLocation;
|
||||||
|
|
||||||
|
public ItemMesherMap(Function<Item, ModelResourceLocation> getLocation) {
|
||||||
|
this.getLocation = getLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return ForgeRegistries.ITEMS.getValues().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(Object key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(Object value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation get(Object key) {
|
||||||
|
return getLocation.apply(((Holder.Reference<Item>)key).get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation put(Holder.Reference<Item> key, ModelResourceLocation value) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation remove(Object key) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(@NotNull Map<? extends Holder.Reference<Item>, ? extends ModelResourceLocation> m) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<Holder.Reference<Item>> keySet() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<ModelResourceLocation> values() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Set<Map.Entry<Holder.Reference<Item>, ModelResourceLocation>> entrySet() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -50,7 +50,9 @@
|
||||||
"perf.compress_blockstate.BlockBehaviourMixin",
|
"perf.compress_blockstate.BlockBehaviourMixin",
|
||||||
"perf.dedup_blockstate_flattening_map.BlockStateDataMixin",
|
"perf.dedup_blockstate_flattening_map.BlockStateDataMixin",
|
||||||
"perf.dedup_blockstate_flattening_map.ChunkPalettedStorageFixMixin",
|
"perf.dedup_blockstate_flattening_map.ChunkPalettedStorageFixMixin",
|
||||||
"devenv.MinecraftServerMixin",
|
"perf.remove_spawn_chunks.ServerChunkCacheAccessor",
|
||||||
|
"perf.remove_spawn_chunks.MinecraftServerMixin",
|
||||||
|
"perf.remove_spawn_chunks.ServerLevelMixin",
|
||||||
"devenv.GameDataMixin"
|
"devenv.GameDataMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user