This commit is contained in:
embeddedt 2023-01-03 16:14:42 -05:00
parent 3534aa9fbc
commit 3d80d5a90e
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
11 changed files with 82 additions and 87 deletions

View File

@ -37,7 +37,7 @@ minecraft {
// //
// Use non-default mappings at your own risk. They may not always work. // Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace. // Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'snapshot', version: '20210309-1.16.5' mappings channel: 'official', version: '1.16.5'
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

View File

@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.Shadow;
/* Idea from Lithium for 1.19.3 */ /* Idea from Lithium for 1.19.3 */
@Mixin(Biome.class) @Mixin(Biome.class)
public abstract class BiomeMixin { public abstract class BiomeMixin {
@Shadow protected abstract float getTemperatureAtPosition(BlockPos pos); @Shadow protected abstract float getHeightAdjustedTemperature(BlockPos pos);
/** /**
* @author 2No2Name * @author 2No2Name
@ -19,6 +19,6 @@ public abstract class BiomeMixin {
*/ */
@Overwrite @Overwrite
public final float getTemperature(BlockPos pos) { public final float getTemperature(BlockPos pos) {
return this.getTemperatureAtPosition(pos); return this.getHeightAdjustedTemperature(pos);
} }
} }

View File

@ -10,14 +10,14 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(targets = { "net/minecraftforge/registries/GameData$BlockCallbacks" }) @Mixin(targets = { "net/minecraftforge/registries/GameData$BlockCallbacks" })
public class BlockCallbacksMixin { public class BlockCallbacksMixin {
@Redirect(method = "onBake", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;cacheState()V")) @Redirect(method = "onBake", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;initCache()V"))
private void skipCacheIfAllowed(BlockState state) { private void skipCacheIfAllowed(BlockState state) {
if(BakeReason.currentBakeReason == BakeReason.FREEZE if(BakeReason.currentBakeReason == BakeReason.FREEZE
|| BakeReason.currentBakeReason == BakeReason.REMOTE_SNAPSHOT_INJECT || BakeReason.currentBakeReason == BakeReason.REMOTE_SNAPSHOT_INJECT
|| (BakeReason.currentBakeReason == BakeReason.LOCAL_SNAPSHOT_INJECT && ModernFix.runningFirstInjection)) { || (BakeReason.currentBakeReason == BakeReason.LOCAL_SNAPSHOT_INJECT && ModernFix.runningFirstInjection)) {
((IBlockState)state).clearCache(); ((IBlockState)state).clearCache();
} else { } else {
state.cacheState(); state.initCache();
} }
} }
} }

View File

@ -16,11 +16,11 @@ import java.nio.file.Path;
@Mixin(SaveFormat.LevelSave.class) @Mixin(SaveFormat.LevelSave.class)
public class LevelSaveMixin implements ILevelSave { public class LevelSaveMixin implements ILevelSave {
@Shadow @Final private Path saveDir; @Shadow @Final private Path levelPath;
public void runWorldPersistenceHooks() { public void runWorldPersistenceHooks() {
SaveFormat saveFormat = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getInstance(), "field_71469_aa"); SaveFormat saveFormat = ObfuscationReflectionHelper.getPrivateValue(Minecraft.class, Minecraft.getInstance(), "levelSource");
((SaveFormatAccessor)saveFormat).invokeReadFromLevelData(this.saveDir.toFile(), (file, dataFixer) -> { ((SaveFormatAccessor)saveFormat).invokeReadLevelData(this.levelPath.toFile(), (file, dataFixer) -> {
try { try {
CompoundNBT compoundTag = CompressedStreamTools.readCompressed(file); CompoundNBT compoundTag = CompressedStreamTools.readCompressed(file);
net.minecraftforge.fml.WorldPersistenceHooks.handleWorldDataLoad((SaveFormat.LevelSave)(Object)this, new DummyServerConfiguration(), compoundTag); net.minecraftforge.fml.WorldPersistenceHooks.handleWorldDataLoad((SaveFormat.LevelSave)(Object)this, new DummyServerConfiguration(), compoundTag);

View File

@ -23,16 +23,16 @@ import java.util.function.Function;
@Mixin(Minecraft.class) @Mixin(Minecraft.class)
public abstract class MinecraftMixin { public abstract class MinecraftMixin {
@Shadow public abstract Minecraft.PackManager reloadDatapacks(DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave worldStorage) throws InterruptedException, ExecutionException; @Shadow public abstract Minecraft.PackManager makeServerStem(DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave worldStorage) throws InterruptedException, ExecutionException;
private long datapackReloadStartTime; private long datapackReloadStartTime;
private int registryHash; private int registryHash;
@Inject(method = "reloadDatapacks", at = @At(value = "HEAD")) @Inject(method = "makeServerStem", at = @At(value = "HEAD"))
private void recordReloadStart(DynamicRegistries.Impl p_238189_1_, Function<SaveFormat.LevelSave, DatapackCodec> p_238189_2_, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> p_238189_3_, boolean p_238189_4_, SaveFormat.LevelSave p_238189_5_, CallbackInfoReturnable<Minecraft.PackManager> cir) { private void recordReloadStart(DynamicRegistries.Impl p_238189_1_, Function<SaveFormat.LevelSave, DatapackCodec> p_238189_2_, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> p_238189_3_, boolean p_238189_4_, SaveFormat.LevelSave p_238189_5_, CallbackInfoReturnable<Minecraft.PackManager> cir) {
datapackReloadStartTime = System.nanoTime(); datapackReloadStartTime = System.nanoTime();
} }
@Inject(method = "reloadDatapacks", at = @At(value = "RETURN")) @Inject(method = "makeServerStem", at = @At(value = "RETURN"))
private void recordReloadEnd(DynamicRegistries.Impl p_238189_1_, Function<SaveFormat.LevelSave, DatapackCodec> p_238189_2_, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> p_238189_3_, boolean p_238189_4_, SaveFormat.LevelSave p_238189_5_, CallbackInfoReturnable<Minecraft.PackManager> cir) { private void recordReloadEnd(DynamicRegistries.Impl p_238189_1_, Function<SaveFormat.LevelSave, DatapackCodec> p_238189_2_, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> p_238189_3_, boolean p_238189_4_, SaveFormat.LevelSave p_238189_5_, CallbackInfoReturnable<Minecraft.PackManager> cir) {
float timeSpentReloading = ((float)(System.nanoTime() - datapackReloadStartTime) / 1000000000f); float timeSpentReloading = ((float)(System.nanoTime() - datapackReloadStartTime) / 1000000000f);
ModernFix.LOGGER.warn("Datapack reload took " + timeSpentReloading + " seconds."); ModernFix.LOGGER.warn("Datapack reload took " + timeSpentReloading + " seconds.");
@ -43,12 +43,12 @@ public abstract class MinecraftMixin {
ModernFixClient.worldLoadStartTime = System.nanoTime(); ModernFixClient.worldLoadStartTime = System.nanoTime();
} }
@Redirect(method = "loadWorld(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistries;func_239770_b_()Lnet/minecraft/util/registry/DynamicRegistries$Impl;")) @Redirect(method = "loadLevel(Ljava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DynamicRegistries;builtin()Lnet/minecraft/util/registry/DynamicRegistries$Impl;"))
private DynamicRegistries.Impl useNullRegistry() { private DynamicRegistries.Impl useNullRegistry() {
return null; return null;
} }
@Redirect(method = "loadWorld(Ljava/lang/String;Lnet/minecraft/util/registry/DynamicRegistries$Impl;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/Minecraft$WorldSelectionType;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;reloadDatapacks(Lnet/minecraft/util/registry/DynamicRegistries$Impl;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/world/storage/SaveFormat$LevelSave;)Lnet/minecraft/client/Minecraft$PackManager;", ordinal = 0)) @Redirect(method = "loadWorld(Ljava/lang/String;Lnet/minecraft/util/registry/DynamicRegistries$Impl;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/client/Minecraft$WorldSelectionType;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;makeServerStem(Lnet/minecraft/util/registry/DynamicRegistries$Impl;Ljava/util/function/Function;Lcom/mojang/datafixers/util/Function4;ZLnet/minecraft/world/storage/SaveFormat$LevelSave;)Lnet/minecraft/client/Minecraft$PackManager;", ordinal = 0))
private Minecraft.PackManager skipFirstReload(Minecraft client, DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave levelSave, String worldName, DynamicRegistries.Impl originalRegistries, Function<SaveFormat.LevelSave, DatapackCodec> levelSaveToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction2, boolean vanillaOnly2, Minecraft.WorldSelectionType selectionType, boolean creating) throws InterruptedException, ExecutionException { private Minecraft.PackManager skipFirstReload(Minecraft client, DynamicRegistries.Impl dynamicRegistries, Function<SaveFormat.LevelSave, DatapackCodec> worldStorageToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction, boolean vanillaOnly, SaveFormat.LevelSave levelSave, String worldName, DynamicRegistries.Impl originalRegistries, Function<SaveFormat.LevelSave, DatapackCodec> levelSaveToDatapackFunction, Function4<SaveFormat.LevelSave, DynamicRegistries.Impl, IResourceManager, DatapackCodec, IServerConfiguration> quadFunction2, boolean vanillaOnly2, Minecraft.WorldSelectionType selectionType, boolean creating) throws InterruptedException, ExecutionException {
if(!creating) { if(!creating) {
ModernFix.LOGGER.warn("Skipping first reload, this is still experimental"); ModernFix.LOGGER.warn("Skipping first reload, this is still experimental");
@ -58,7 +58,7 @@ public abstract class MinecraftMixin {
return null; return null;
} else { } else {
/* allow reload */ /* allow reload */
return reloadDatapacks(dynamicRegistries, worldStorageToDatapackFunction, quadFunction, vanillaOnly, levelSave); return makeServerStem(dynamicRegistries, worldStorageToDatapackFunction, quadFunction, vanillaOnly, levelSave);
} }
} }
} }

View File

@ -27,7 +27,7 @@ import java.util.stream.Stream;
@Mixin(ModFileResourcePack.class) @Mixin(ModFileResourcePack.class)
public abstract class ModFileResourcePackMixin { public abstract class ModFileResourcePackMixin {
@Shadow public abstract Set<String> getResourceNamespaces(ResourcePackType type); @Shadow public abstract Set<String> getNamespaces(ResourcePackType type);
@Shadow(remap = false) @Final private ModFile modFile; @Shadow(remap = false) @Final private ModFile modFile;
private EnumMap<ResourcePackType, Set<String>> namespacesByType; private EnumMap<ResourcePackType, Set<String>> namespacesByType;
@ -39,7 +39,7 @@ public abstract class ModFileResourcePackMixin {
this.useNamespaceCaches = false; this.useNamespaceCaches = false;
this.namespacesByType = new EnumMap<>(ResourcePackType.class); this.namespacesByType = new EnumMap<>(ResourcePackType.class);
for(ResourcePackType type : ResourcePackType.values()) { for(ResourcePackType type : ResourcePackType.values()) {
this.namespacesByType.put(type, this.getResourceNamespaces(type)); this.namespacesByType.put(type, this.getNamespaces(type));
} }
this.useNamespaceCaches = true; this.useNamespaceCaches = true;
this.rootListingByNamespaceAndType = new EnumMap<>(ResourcePackType.class); this.rootListingByNamespaceAndType = new EnumMap<>(ResourcePackType.class);
@ -48,7 +48,7 @@ public abstract class ModFileResourcePackMixin {
HashMap<String, List<Path>> rootListingForNamespaces = new HashMap<>(); HashMap<String, List<Path>> rootListingForNamespaces = new HashMap<>();
for(String namespace : namespaces) { for(String namespace : namespaces) {
try { try {
Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName(), namespace).toAbsolutePath(); Path root = modFile.getLocator().findPath(modFile, type.getDirectory(), namespace).toAbsolutePath();
try (Stream<Path> stream = Files.walk(root)) { try (Stream<Path> stream = Files.walk(root)) {
rootListingForNamespaces.put(namespace, stream rootListingForNamespaces.put(namespace, stream
.map(path -> root.relativize(path.toAbsolutePath())) .map(path -> root.relativize(path.toAbsolutePath()))
@ -63,7 +63,7 @@ public abstract class ModFileResourcePackMixin {
} }
} }
@Inject(method = "getResourceNamespaces", at = @At("HEAD"), cancellable = true) @Inject(method = "getNamespaces", at = @At("HEAD"), cancellable = true)
private void useCacheForNamespaces(ResourcePackType type, CallbackInfoReturnable<Set<String>> cir) { private void useCacheForNamespaces(ResourcePackType type, CallbackInfoReturnable<Set<String>> cir) {
if(useNamespaceCaches) { if(useNamespaceCaches) {
cir.setReturnValue(this.namespacesByType.get(type)); cir.setReturnValue(this.namespacesByType.get(type));
@ -75,9 +75,9 @@ public abstract class ModFileResourcePackMixin {
* @reason Use cached listing of mod resources * @reason Use cached listing of mod resources
*/ */
@Overwrite @Overwrite
public Collection<ResourceLocation> getAllResourceLocations(ResourcePackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<String> filter) public Collection<ResourceLocation> getResources(ResourcePackType type, String resourceNamespace, String pathIn, int maxDepth, Predicate<String> filter)
{ {
Path root = modFile.getLocator().findPath(modFile, type.getDirectoryName(), resourceNamespace).toAbsolutePath(); Path root = modFile.getLocator().findPath(modFile, type.getDirectory(), resourceNamespace).toAbsolutePath();
Path inputPath = root.getFileSystem().getPath(pathIn); Path inputPath = root.getFileSystem().getPath(pathIn);
return this.rootListingByNamespaceAndType.get(type).getOrDefault(resourceNamespace, Collections.emptyList()).stream(). return this.rootListingByNamespaceAndType.get(type).getOrDefault(resourceNamespace, Collections.emptyList()).stream().
filter(path -> path.getNameCount() <= maxDepth). // Make sure the depth is within bounds filter(path -> path.getNameCount() <= maxDepth). // Make sure the depth is within bounds

View File

@ -1,10 +1,8 @@
package org.embeddedt.modernfix.mixin; package org.embeddedt.modernfix.mixin;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.model.*; import net.minecraft.client.renderer.model.*;
import net.minecraft.client.renderer.texture.SpriteMap; import net.minecraft.client.renderer.texture.SpriteMap;
import net.minecraft.profiler.IProfiler; import net.minecraft.profiler.IProfiler;
@ -38,23 +36,23 @@ import java.util.stream.Stream;
@Mixin(ModelBakery.class) @Mixin(ModelBakery.class)
public abstract class ModelBakeryMixin { public abstract class ModelBakeryMixin {
@Shadow protected abstract BlockModel loadModel(ResourceLocation location) throws IOException; @Shadow protected abstract BlockModel loadBlockModel(ResourceLocation location) throws IOException;
@Shadow @Final private Map<ResourceLocation, IUnbakedModel> unbakedModels; @Shadow @Final private Map<ResourceLocation, IUnbakedModel> unbakedCache;
@Shadow @Final public static ModelResourceLocation MODEL_MISSING; @Shadow @Final public static ModelResourceLocation MISSING_MODEL_LOCATION;
@Shadow public abstract IUnbakedModel getUnbakedModel(ResourceLocation modelLocation); @Shadow public abstract IUnbakedModel getModel(ResourceLocation modelLocation);
@Shadow @Final public static BlockModel MODEL_GENERATED; @Shadow @Final public static BlockModel GENERATION_MARKER;
@Shadow @Final private static ItemModelGenerator ITEM_MODEL_GENERATOR; @Shadow @Final private static ItemModelGenerator ITEM_MODEL_GENERATOR;
@Shadow @Nullable private SpriteMap spriteMap; @Shadow @Nullable private SpriteMap atlasSet;
@Shadow @Final private Map<Triple<ResourceLocation, TransformationMatrix, Boolean>, IBakedModel> bakedModels; @Shadow @Final private Map<Triple<ResourceLocation, TransformationMatrix, Boolean>, IBakedModel> bakedCache;
@Shadow @Final private Map<ResourceLocation, IBakedModel> topBakedModels; @Shadow @Final private Map<ResourceLocation, IBakedModel> bakedTopLevelModels;
@Shadow @Final private Map<ResourceLocation, IUnbakedModel> topUnbakedModels; @Shadow @Final private Map<ResourceLocation, IUnbakedModel> topLevelModels;
private Map<ResourceLocation, BlockModel> deserializedModelCache = null; private Map<ResourceLocation, BlockModel> deserializedModelCache = null;
private boolean useModelCache = false; private boolean useModelCache = false;
@Inject(method = "loadModel", at = @At("HEAD"), cancellable = true) @Inject(method = "loadBlockModel", at = @At("HEAD"), cancellable = true)
private void useCachedModel(ResourceLocation location, CallbackInfoReturnable<BlockModel> cir) { private void useCachedModel(ResourceLocation location, CallbackInfoReturnable<BlockModel> cir) {
if(useModelCache && deserializedModelCache != null) { if(useModelCache && deserializedModelCache != null) {
BlockModel model = deserializedModelCache.get(location); BlockModel model = deserializedModelCache.get(location);
@ -65,24 +63,24 @@ public abstract class ModelBakeryMixin {
private BlockModel loadModelSafely(ResourceLocation location) { private BlockModel loadModelSafely(ResourceLocation location) {
try { try {
return this.loadModel(location); return this.loadBlockModel(location);
} catch(Throwable e) { } catch(Throwable e) {
ModernFix.LOGGER.warn("Model " + location + " will not be preloaded", e); ModernFix.LOGGER.warn("Model " + location + " will not be preloaded", e);
return null; return null;
} }
} }
@Inject(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;endStartSection(Ljava/lang/String;)V", ordinal = 1)) @Inject(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/IProfiler;popPush(Ljava/lang/String;)V", ordinal = 1))
private void preloadJsonModels(IProfiler profilerIn, int maxMipmapLevel, CallbackInfo ci) { private void preloadJsonModels(IProfiler profilerIn, int maxMipmapLevel, CallbackInfo ci) {
profilerIn.endStartSection("loadjsons"); profilerIn.popPush("loadjsons");
ModernFix.LOGGER.warn("Preloading JSONs in parallel..."); ModernFix.LOGGER.warn("Preloading JSONs in parallel...");
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
useModelCache = false; useModelCache = false;
deserializedModelCache = Minecraft.getInstance().getResourceManager().getAllResourceLocations("models", p -> { deserializedModelCache = Minecraft.getInstance().getResourceManager().listResources("models", p -> {
if(!p.endsWith(".json")) if(!p.endsWith(".json"))
return false; return false;
for(int i = 0; i < p.length(); i++) { for(int i = 0; i < p.length(); i++) {
if(!ResourceLocation.validatePathChar(p.charAt(i))) if(!ResourceLocation.validPathChar(p.charAt(i)))
return false; return false;
} }
return true; return true;
@ -106,30 +104,30 @@ public abstract class ModelBakeryMixin {
@Redirect(method = "uploadTextures", at = @At(value = "INVOKE", target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V", ordinal = 0)) @Redirect(method = "uploadTextures", at = @At(value = "INVOKE", target = "Ljava/util/Set;forEach(Ljava/util/function/Consumer;)V", ordinal = 0))
private void parallelBake(Set<ResourceLocation> locationSet, Consumer consumer) { private void parallelBake(Set<ResourceLocation> locationSet, Consumer consumer) {
final IModelTransform transform = ModelRotation.X0_Y0; final IModelTransform transform = ModelRotation.X0_Y0;
if(this.spriteMap == null) if(this.atlasSet == null)
throw new IllegalStateException("no sprite map"); throw new IllegalStateException("no sprite map");
ModernFix.LOGGER.warn("Baking models in parallel..."); ModernFix.LOGGER.warn("Baking models in parallel...");
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
locationSet.forEach(this::getUnbakedModel); /* make sure every unbaked model is loaded, should be fast */ locationSet.forEach(this::getModel); /* make sure every unbaked model is loaded, should be fast */
List<Pair<ResourceLocation, IBakedModel>> models = CompletableFuture.supplyAsync(() -> { List<Pair<ResourceLocation, IBakedModel>> models = CompletableFuture.supplyAsync(() -> {
return locationSet.parallelStream().map(location -> { return locationSet.parallelStream().map(location -> {
IUnbakedModel iunbakedmodel = this.unbakedModels.get(location); IUnbakedModel iunbakedmodel = this.unbakedCache.get(location);
if (iunbakedmodel instanceof BlockModel) { if (iunbakedmodel instanceof BlockModel) {
BlockModel blockmodel = (BlockModel)iunbakedmodel; BlockModel blockmodel = (BlockModel)iunbakedmodel;
if (blockmodel.getRootModel() == MODEL_GENERATED) { if (blockmodel.getRootModel() == GENERATION_MARKER) {
return Pair.of(location, ITEM_MODEL_GENERATOR.makeItemModel(this.spriteMap::getSprite, blockmodel).bakeModel((ModelBakery)(Object)this, blockmodel, this.spriteMap::getSprite, transform, location, false)); return Pair.of(location, ITEM_MODEL_GENERATOR.generateBlockModel(this.atlasSet::getSprite, blockmodel).bake((ModelBakery)(Object)this, blockmodel, this.atlasSet::getSprite, transform, location, false));
} }
} }
IBakedModel ibakedmodel = iunbakedmodel.bakeModel((ModelBakery)(Object)this, this.spriteMap::getSprite, transform, location); IBakedModel ibakedmodel = iunbakedmodel.bake((ModelBakery)(Object)this, this.atlasSet::getSprite, transform, location);
return Pair.of(location, ibakedmodel); return Pair.of(location, ibakedmodel);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
}, Util.getServerExecutor()).join(); }, Util.backgroundExecutor()).join();
models.forEach(pair -> { models.forEach(pair -> {
Triple<ResourceLocation, TransformationMatrix, Boolean> triple = Triple.of(pair.getKey(), transform.getRotation(), transform.isUvLock()); Triple<ResourceLocation, TransformationMatrix, Boolean> triple = Triple.of(pair.getKey(), transform.getRotation(), transform.isUvLocked());
this.bakedModels.put(triple, pair.getValue()); this.bakedCache.put(triple, pair.getValue());
if(pair.getValue() != null) if(pair.getValue() != null)
this.topBakedModels.put(pair.getKey(), pair.getValue()); this.bakedTopLevelModels.put(pair.getKey(), pair.getValue());
}); });
ModernFix.LOGGER.warn("Baking in parallel took " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds"); ModernFix.LOGGER.warn("Baking in parallel took " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");
stopwatch.stop(); stopwatch.stop();
@ -139,21 +137,21 @@ public abstract class ModelBakeryMixin {
private Object collectTexturesParallel(Stream instance, Collector arCollector) { private Object collectTexturesParallel(Stream instance, Collector arCollector) {
ModernFix.LOGGER.warn("Collecting textures in parallel..."); ModernFix.LOGGER.warn("Collecting textures in parallel...");
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
ConcurrentHashMap<ResourceLocation, IUnbakedModel> threadedUnbakedModels = new ConcurrentHashMap<>(this.unbakedModels); ConcurrentHashMap<ResourceLocation, IUnbakedModel> threadedunbakedCache = new ConcurrentHashMap<>(this.unbakedCache);
Function<ResourceLocation, IUnbakedModel> safeUnbakedGetter = (location) -> { Function<ResourceLocation, IUnbakedModel> safeUnbakedGetter = (location) -> {
IUnbakedModel candidate = threadedUnbakedModels.get(location); IUnbakedModel candidate = threadedunbakedCache.get(location);
if(candidate == null) { if(candidate == null) {
synchronized (this.unbakedModels) { synchronized (this.unbakedCache) {
candidate = this.getUnbakedModel(location); candidate = this.getModel(location);
threadedUnbakedModels.put(location, candidate); threadedunbakedCache.put(location, candidate);
} }
} }
return candidate; return candidate;
}; };
Set<com.mojang.datafixers.util.Pair<String, String>> set = Collections.synchronizedSet(Sets.newLinkedHashSet()); Set<com.mojang.datafixers.util.Pair<String, String>> set = Collections.synchronizedSet(Sets.newLinkedHashSet());
String modelMissingString = MODEL_MISSING.toString(); String modelMissingString = MISSING_MODEL_LOCATION.toString();
Set<RenderMaterial> materials = this.topUnbakedModels.values().parallelStream().flatMap((unbaked) -> { Set<RenderMaterial> materials = this.topLevelModels.values().parallelStream().flatMap((unbaked) -> {
return unbaked.getTextures(safeUnbakedGetter, set).stream(); return unbaked.getMaterials(safeUnbakedGetter, set).stream();
}).collect(Collectors.toSet()); }).collect(Collectors.toSet());
set.stream().filter((stringPair) -> { set.stream().filter((stringPair) -> {
return !stringPair.getSecond().equals(modelMissingString); return !stringPair.getSecond().equals(modelMissingString);

View File

@ -1,6 +1,5 @@
package org.embeddedt.modernfix.mixin; package org.embeddedt.modernfix.mixin;
import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet; import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormat;
@ -9,20 +8,18 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import java.util.Collections;
@Mixin(targets = {"net/minecraft/client/renderer/RenderType$Type"}) @Mixin(targets = {"net/minecraft/client/renderer/RenderType$Type"})
public class RenderTypeMixin { public class RenderTypeMixin {
@Shadow @Final private static ObjectOpenCustomHashSet<RenderType.Type> TYPES; @Shadow @Final private static ObjectOpenCustomHashSet<RenderType.Type> INSTANCES;
/** /**
* @author embeddedt * @author embeddedt
* @reason synchronize, can be accessed by multiple mods during modloading * @reason synchronize, can be accessed by multiple mods during modloading
*/ */
@Overwrite @Overwrite
private static RenderType.Type getOrCreate(String name, VertexFormat format, int drawMode, int bufferSize, boolean useDelegate, boolean needsSorting, RenderType.State renderState) { private static RenderType.Type memoize(String name, VertexFormat format, int drawMode, int bufferSize, boolean useDelegate, boolean needsSorting, RenderType.State renderState) {
synchronized (TYPES){ synchronized (INSTANCES){
return TYPES.addOrGet(new RenderType.Type(name, format, drawMode, bufferSize, useDelegate, needsSorting, renderState)); return INSTANCES.addOrGet(new RenderType.Type(name, format, drawMode, bufferSize, useDelegate, needsSorting, renderState));
} }
} }
} }

View File

@ -11,5 +11,5 @@ import java.util.function.BiFunction;
@Mixin(SaveFormat.class) @Mixin(SaveFormat.class)
public interface SaveFormatAccessor { public interface SaveFormatAccessor {
@Invoker @Invoker
<T> T invokeReadFromLevelData(File saveDir, BiFunction<File, DataFixer, T> levelDatReader); <T> T invokeReadLevelData(File saveDir, BiFunction<File, DataFixer, T> levelDatReader);
} }

View File

@ -29,11 +29,11 @@ import java.util.stream.Stream;
@Mixin(VanillaPack.class) @Mixin(VanillaPack.class)
public class VanillaPackMixin { public class VanillaPackMixin {
@Shadow @Final private static Map<ResourcePackType, FileSystem> FILE_SYSTEMS_BY_PACK_TYPE; @Shadow @Final private static Map<ResourcePackType, FileSystem> JAR_FILESYSTEM_BY_TYPE;
private static LoadingCache<Pair<Path, Integer>, List<Path>> pathStreamLoadingCache = CacheBuilder.newBuilder() private static LoadingCache<Pair<Path, Integer>, List<Path>> pathStreamLoadingCache = CacheBuilder.newBuilder()
.build(FileWalker.INSTANCE); .build(FileWalker.INSTANCE);
@Redirect(method = "collectResources", at = @At(value = "INVOKE", target = "Ljava/nio/file/Files;walk(Ljava/nio/file/Path;I[Ljava/nio/file/FileVisitOption;)Ljava/util/stream/Stream;")) @Redirect(method = "getResources(Ljava/util/Collection;ILjava/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;I[Ljava/nio/file/FileVisitOption;)Ljava/util/stream/Stream;"))
private static Stream<Path> useCacheForLoading(Path path, int maxDepth, FileVisitOption[] fileVisitOptions) throws IOException { private static Stream<Path> useCacheForLoading(Path path, int maxDepth, FileVisitOption[] fileVisitOptions) throws IOException {
try { try {
return pathStreamLoadingCache.get(Pair.of(path, maxDepth)).stream(); return pathStreamLoadingCache.get(Pair.of(path, maxDepth)).stream();
@ -45,9 +45,9 @@ public class VanillaPackMixin {
} }
} }
@Inject(method = "resourceExists", at = @At(value = "INVOKE", target = "Ljava/lang/Class;getResource(Ljava/lang/String;)Ljava/net/URL;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) @Inject(method = "hasResource", at = @At(value = "INVOKE", target = "Ljava/lang/Class;getResource(Ljava/lang/String;)Ljava/net/URL;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void useCacheForExistence(ResourcePackType type, ResourceLocation location, CallbackInfoReturnable<Boolean> cir, String path) { private void useCacheForExistence(ResourcePackType type, ResourceLocation location, CallbackInfoReturnable<Boolean> cir, String path) {
FileSystem fs = FILE_SYSTEMS_BY_PACK_TYPE.get(type); FileSystem fs = JAR_FILESYSTEM_BY_TYPE.get(type);
cir.setReturnValue(Files.exists(fs.getPath(path))); cir.setReturnValue(Files.exists(fs.getPath(path)));
} }
} }

View File

@ -18,53 +18,53 @@ import java.util.Set;
public class DummyServerConfiguration implements IServerConfiguration { public class DummyServerConfiguration implements IServerConfiguration {
@Override @Override
public DatapackCodec getDatapackCodec() { public DatapackCodec getDataPackConfig() {
return DatapackCodec.VANILLA_CODEC; return DatapackCodec.DEFAULT;
} }
@Override @Override
public void setDatapackCodec(DatapackCodec codec) { public void setDataPackConfig(DatapackCodec codec) {
} }
@Override @Override
public boolean isModded() { public boolean wasModded() {
return true; return true;
} }
@Override @Override
public Set<String> getServerBranding() { public Set<String> getKnownServerBrands() {
return ImmutableSet.of("forge"); return ImmutableSet.of("forge");
} }
@Override @Override
public void addServerBranding(String name, boolean isModded) { public void setModdedInfo(String name, boolean isModded) {
} }
@Nullable @Nullable
@Override @Override
public CompoundNBT getCustomBossEventData() { public CompoundNBT getCustomBossEvents() {
return null; return null;
} }
@Override @Override
public void setCustomBossEventData(@Nullable CompoundNBT nbt) { public void setCustomBossEvents(@Nullable CompoundNBT nbt) {
} }
@Override @Override
public IServerWorldInfo getServerWorldInfo() { public IServerWorldInfo overworldData() {
return null; return null;
} }
@Override @Override
public WorldSettings getWorldSettings() { public WorldSettings getLevelSettings() {
return null; return null;
} }
@Override @Override
public CompoundNBT serialize(DynamicRegistries registries, @Nullable CompoundNBT hostPlayerNBT) { public CompoundNBT createTag(DynamicRegistries registries, @Nullable CompoundNBT hostPlayerNBT) {
return null; return null;
} }
@ -74,12 +74,12 @@ public class DummyServerConfiguration implements IServerConfiguration {
} }
@Override @Override
public int getStorageVersionId() { public int getVersion() {
return 0; return 0;
} }
@Override @Override
public String getWorldName() { public String getLevelName() {
return null; return null;
} }
@ -94,7 +94,7 @@ public class DummyServerConfiguration implements IServerConfiguration {
} }
@Override @Override
public boolean areCommandsAllowed() { public boolean getAllowCommands() {
return false; return false;
} }
@ -119,32 +119,32 @@ public class DummyServerConfiguration implements IServerConfiguration {
} }
@Override @Override
public GameRules getGameRulesInstance() { public GameRules getGameRules() {
return null; return null;
} }
@Override @Override
public CompoundNBT getHostPlayerNBT() { public CompoundNBT getLoadedPlayerTag() {
return null; return null;
} }
@Override @Override
public CompoundNBT getDragonFightData() { public CompoundNBT endDragonFightData() {
return null; return null;
} }
@Override @Override
public void setDragonFightData(CompoundNBT nbt) { public void setEndDragonFightData(CompoundNBT nbt) {
} }
@Override @Override
public DimensionGeneratorSettings getDimensionGeneratorSettings() { public DimensionGeneratorSettings worldGenSettings() {
return null; return null;
} }
@Override @Override
public Lifecycle getLifecycle() { public Lifecycle worldGenSettingsLifecycle() {
return Lifecycle.stable(); return Lifecycle.stable();
} }
} }