Merge 1.20 into 1.20.2

This commit is contained in:
embeddedt 2023-10-25 15:00:20 -04:00
commit f6f7badde8
5 changed files with 14 additions and 69 deletions

View File

@ -1,4 +1,4 @@
package org.embeddedt.modernfix.fabric.mixin.perf.dynamic_resources;
package org.embeddedt.modernfix.common.mixin.perf.dynamic_resources;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.BlockModel;

View File

@ -20,6 +20,7 @@ import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.Mixin;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BooleanSupplier;
@ -156,7 +157,6 @@ public class ModernFixEarlyConfig {
private static final ImmutableMap<String, Boolean> DEFAULT_SETTING_OVERRIDES = new DefaultSettingMapBuilder()
.put("mixin.perf.dynamic_resources", false)
.putConditionally(() -> !isFabric, "mixin.perf.async_jei", false)
.put("mixin.perf.dynamic_sounds", false)
.put("mixin.perf.dynamic_block_codecs", false)
.put("mixin.feature.direct_stack_trace", false)
@ -237,7 +237,10 @@ public class ModernFixEarlyConfig {
if(!ModernFixPlatformHooks.INSTANCE.isDevEnv())
return;
try {
if(ModernFixEarlyConfig.class.getClassLoader().getResource("/net/minecraft/world/level/Level.class") == null) {
URL deobfClass = isFabric ?
ModernFixEarlyConfig.class.getResource("/net/minecraft/world/level/Level.class") :
ModernFixEarlyConfig.class.getClassLoader().getResource("/net/minecraft/world/level/Level.class");
if(deobfClass == null) {
LOGGER.warn("We are in a non-Mojmap dev environment. Disabling blockstate cache patch");
this.options.get("mixin.perf.reduce_blockstate_cache_rebuilds").addModOverride(false, "[not mojmap]");
}

View File

@ -13,6 +13,8 @@ public class ModernFixConfigScreen extends Screen {
public boolean madeChanges = false;
private Button doneButton, wikiButton;
private double lastScrollAmount = 0;
public ModernFixConfigScreen(Screen lastScreen) {
super(Component.translatable("modernfix.config"));
this.lastScreen = lastScreen;
@ -21,6 +23,7 @@ public class ModernFixConfigScreen extends Screen {
@Override
protected void init() {
this.optionList = new OptionList(this, this.minecraft);
this.optionList.setScrollAmount(lastScrollAmount);
this.addWidget(this.optionList);
this.wikiButton = new Button.Builder(Component.translatable("modernfix.config.wiki"), (arg) -> {
Util.getPlatform().openUri("https://github.com/embeddedt/ModernFix/wiki/Summary-of-Patches");
@ -45,4 +48,8 @@ public class ModernFixConfigScreen extends Screen {
this.doneButton.setMessage(madeChanges ? Component.translatable("modernfix.config.done_restart") : CommonComponents.GUI_DONE);
super.render(guiGraphics, mouseX, mouseY, partialTicks);
}
public void setLastScrollAmount(double d) {
this.lastScrollAmount = d;
}
}

View File

@ -166,6 +166,7 @@ public class OptionList extends ContainerObjectSelectionList<OptionList.Entry> {
}).tooltip(toggleTooltip).pos(0, 0).size(55, 20).build();
updateStatus();
this.helpButton = new Button.Builder(Component.literal("?"), (arg) -> {
mainScreen.setLastScrollAmount(getScrollAmount());
Minecraft.getInstance().setScreen(new ModernFixOptionInfoScreen(mainScreen, optionName));
}).pos(75, 0).size(20, 20).build();
if(!I18n.exists("modernfix.option." + optionName)) {

View File

@ -1,66 +0,0 @@
package org.embeddedt.modernfix.forge.mixin.perf.dynamic_resources;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import org.embeddedt.modernfix.ModernFix;
import org.embeddedt.modernfix.util.LambdaMap;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
@Mixin(ModelManager.class)
public class ModelManagerMixin {
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelManager;loadBlockModels(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private CompletableFuture<Map<ResourceLocation, BlockModel>> deferBlockModelLoad(ResourceManager manager, Executor executor) {
return CompletableFuture.completedFuture(new LambdaMap<>(location -> loadSingleBlockModel(manager, location)));
}
@Redirect(method = "reload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ModelManager;loadBlockStates(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private CompletableFuture<Map<ResourceLocation, List<ModelBakery.LoadedJson>>> deferBlockStateLoad(ResourceManager manager, Executor executor) {
return CompletableFuture.completedFuture(new LambdaMap<>(location -> loadSingleBlockState(manager, location)));
}
@Redirect(method = "loadModels", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/StateDefinition;getPossibleStates()Lcom/google/common/collect/ImmutableList;"))
private ImmutableList<BlockState> skipCollection(StateDefinition<Block, BlockState> definition) {
return ImmutableList.of();
}
private BlockModel loadSingleBlockModel(ResourceManager manager, ResourceLocation location) {
return manager.getResource(location).map(resource -> {
try (BufferedReader reader = resource.openAsReader()) {
return BlockModel.fromStream(reader);
} catch(IOException e) {
ModernFix.LOGGER.error("Couldn't load model", e);
return null;
}
}).orElse(null);
}
private List<ModelBakery.LoadedJson> loadSingleBlockState(ResourceManager manager, ResourceLocation location) {
return manager.getResourceStack(location).stream().map(resource -> {
try (BufferedReader reader = resource.openAsReader()) {
return new ModelBakery.LoadedJson(resource.sourcePackId(), GsonHelper.parse(reader));
} catch(IOException e) {
ModernFix.LOGGER.error("Couldn't load blockstate", e);
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList());
}
}