From 8873a055bc059288083275d0ff3b6dc51f21b136 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:08:39 -0400 Subject: [PATCH 1/5] Fix https://github.com/thebrightspark/AsyncLocator/issues/12 for 1.16 --- .../forge/mixin/perf/async_locator/SetNameFunctionMixin.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/async_locator/SetNameFunctionMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/async_locator/SetNameFunctionMixin.java index 9f215c86..40829573 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/async_locator/SetNameFunctionMixin.java +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/perf/async_locator/SetNameFunctionMixin.java @@ -21,6 +21,8 @@ public class SetNameFunctionMixin { public ItemStack deferSetName(ItemStack stack, Component name) { if (CommonLogic.isEmptyPendingMap(stack)) ExplorationMapFunctionLogic.cacheName(stack, name); + else + stack.setHoverName(name); return stack; } } From ec189b55a2f33f0db235bcba31c08d9dc5e83335 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:34:46 -0400 Subject: [PATCH 2/5] Fix concurrency bugs in Mantle models Backports https://github.com/SlimeKnights/Mantle/commit/eb111d2083ae0b2021acaf15ae903d7950bf0f49 Related: https://github.com/embeddedt/embeddium/issues/251 --- .../mantle_model_cme/ConnectedModelMixin.java | 24 +++++++++++++++ .../FluidTextureModelLoaderMixin.java | 24 +++++++++++++++ .../RetexturedModelBakedMixin.java | 29 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/ConnectedModelMixin.java create mode 100644 forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/FluidTextureModelLoaderMixin.java create mode 100644 forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/RetexturedModelBakedMixin.java diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/ConnectedModelMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/ConnectedModelMixin.java new file mode 100644 index 00000000..913205c3 --- /dev/null +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/ConnectedModelMixin.java @@ -0,0 +1,24 @@ +package org.embeddedt.modernfix.forge.mixin.bugfix.mantle_model_cme; + +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.annotation.RequiresMod; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Pseudo +@Mixin(targets = { "slimeknights/mantle/client/model/connected/ConnectedModel$Baked" }, remap = false) +@RequiresMod("mantle") +@ClientOnlyMixin +public class ConnectedModelMixin { + @SuppressWarnings("unused") + @Shadow + @Final + @Mutable + private final Map nameMappingCache = new ConcurrentHashMap<>(); +} diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/FluidTextureModelLoaderMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/FluidTextureModelLoaderMixin.java new file mode 100644 index 00000000..018369dd --- /dev/null +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/FluidTextureModelLoaderMixin.java @@ -0,0 +1,24 @@ +package org.embeddedt.modernfix.forge.mixin.bugfix.mantle_model_cme; + +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.annotation.RequiresMod; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@Pseudo +@Mixin(targets = { "slimeknights/mantle/client/model/fluid/FluidTextureModel$Loader" }, remap = false) +@RequiresMod("mantle") +@ClientOnlyMixin +public class FluidTextureModelLoaderMixin { + @SuppressWarnings("unused") + @Shadow + @Final + @Mutable + private final Map modelCache = new ConcurrentHashMap<>(); +} diff --git a/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/RetexturedModelBakedMixin.java b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/RetexturedModelBakedMixin.java new file mode 100644 index 00000000..69a1b90e --- /dev/null +++ b/forge/src/main/java/org/embeddedt/modernfix/forge/mixin/bugfix/mantle_model_cme/RetexturedModelBakedMixin.java @@ -0,0 +1,29 @@ +package org.embeddedt.modernfix.forge.mixin.bugfix.mantle_model_cme; + +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.resources.ResourceLocation; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.annotation.RequiresMod; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Fix ConcurrentModificationException from Mantle models by making the cache thread-safe. + */ +@Pseudo +@Mixin(targets = { "slimeknights/mantle/client/model/RetexturedModel$BakedModel" }, remap = false) +@RequiresMod("mantle") +@ClientOnlyMixin +public class RetexturedModelBakedMixin { + @SuppressWarnings("unused") + @Shadow + @Final + @Mutable + private final Map cache = new ConcurrentHashMap<>(); +} From ab1da68da2783a30be5f5428fac6b136e1c7efbf Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:43:12 -0400 Subject: [PATCH 3/5] Document all new mixin options --- .../main/resources/assets/modernfix/lang/en_us.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/src/main/resources/assets/modernfix/lang/en_us.json b/common/src/main/resources/assets/modernfix/lang/en_us.json index 98bc5ba1..a2f242d8 100644 --- a/common/src/main/resources/assets/modernfix/lang/en_us.json +++ b/common/src/main/resources/assets/modernfix/lang/en_us.json @@ -120,5 +120,16 @@ "modernfix.option.mixin.perf.compact_mojang_registries": "(Fabric) Experimental option that reduces the memory usage of registries by roughly 50%. Not useful in most modpacks unless they contain millions of blocks and items.", "modernfix.option.mixin.perf.dynamic_block_codecs": "Avoids storing a codec for every block(state) and instead generates and caches it on the fly when needed. Generally not worth enabling unless you have a million blocks/items.", "modernfix.option.mixin.perf.faster_command_suggestions": "Mitigate lag when there are hundreds of thousands of suggestions while typing a command", - "modernfix.option.mixin.perf.mojang_registry_size": "Fixes an issue causing registration of blocks/items to slow down proportional to the number already registered. This improves startup time." + "modernfix.option.mixin.perf.mojang_registry_size": "Fixes an issue causing registration of blocks/items to slow down proportional to the number already registered. This improves startup time.", + "modernfix.option.mixin.bugfix.entity_pose_stack": "Fixes Forge issue #9118, where mods can cause undebuggable render crashes by pushing the matrix stack without popping it.", + "modernfix.option.mixin.bugfix.file_dialog_title": "Fixes a security issue with the worldgen settings file dialog", + "modernfix.option.mixin.bugfix.forge_vehicle_packets": "Fixes a bug introduced by a Forge patch that causes excessive amounts of chunk data packets to be sent to the player if they are riding a vehicle on a chunk border.", + "modernfix.option.mixin.bugfix.mantle_model_cme": "Fixes a bug in Mantle that can cause random ConcurrentModificationException crashes when rendering Tinkers Construct content.", + "modernfix.option.mixin.bugfix.model_data_manager_cme": "Works around design flaws in the Forge ModelDataManager system that can cause unexpected concurrency issues.", + "modernfix.option.mixin.bugfix.recipe_book_type_desync": "Fixes Forge clients being disconnected when connecting to a vanilla server if mods add custom recipe book entry types.", + "modernfix.option.mixin.bugfix.unsafe_modded_shape_caches": "Fixes various ConcurrentModificationExceptions that can occur in content mods when computing block shapes", + "modernfix.option.mixin.feature.stalled_chunk_load_detection": "This option may help to detect the cause of chunkloading freezes. However, leaving it enabled may cause slightly worse performance.", + "modernfix.option.mixin.perf.fix_loop_spin_waiting": "Fixes Minecraft's built-in wait function consuming excessive amounts of CPU resources.", + "modernfix.option.mixin.perf.forge_cap_retrieval": "Small micro-optimization that makes retrieving custom entity data slightly more efficient on Forge.", + "modernfix.option.mixin.perf.forge_registry_lambda": "Fixes oversights in Forge that lead to excessive allocation in hot registry methods." } From 9f521ed30804686dabc4cea266e136fd4b37d419 Mon Sep 17 00:00:00 2001 From: ZZZank <47418975+ZZZank@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:41:16 +0800 Subject: [PATCH 4/5] Update zh_cn localizations for mixin options (#387) --- .../main/resources/assets/modernfix/lang/zh_cn.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/common/src/main/resources/assets/modernfix/lang/zh_cn.json b/common/src/main/resources/assets/modernfix/lang/zh_cn.json index 457d4a01..3fc1b0f6 100644 --- a/common/src/main/resources/assets/modernfix/lang/zh_cn.json +++ b/common/src/main/resources/assets/modernfix/lang/zh_cn.json @@ -120,5 +120,16 @@ "modernfix.option.mixin.perf.compact_mojang_registries": "(Fabric)实验性选项,可将注册表的内存占用减少约 50%。在大多数整合包中没什么用,除非它们包含数百万个方块和物品。", "modernfix.option.mixin.perf.dynamic_block_codecs": "不再给每个方块(状态)都存储一个编解码器,只在需要时动态生成、缓存它。通常不值得启用,除非你有一百万个方块/物品。", "modernfix.option.mixin.perf.faster_command_suggestions": "在输入命令时,若有数十万个建议,可以缓解卡顿。", - "modernfix.option.mixin.perf.mojang_registry_size": "修复了一个问题,它会导致方块/物品的注册速度减慢,减慢的程度与已注册的数量成正比。这缩短了启动时间。" + "modernfix.option.mixin.perf.mojang_registry_size": "修复了一个问题,它会导致方块/物品的注册速度减慢,减慢的程度与已注册的数量成正比。这缩短了启动时间。", + "modernfix.option.mixin.bugfix.entity_pose_stack": "修复了Forge的#9118号问题,这个问题会导致模组在不弹出已经推入的MatrixStack时有概率触发无法诊断的渲染崩溃。", + "modernfix.option.mixin.bugfix.file_dialog_title": "修复了在世界生成设置的文件选择对话框中的一个安全问题。", + "modernfix.option.mixin.bugfix.forge_vehicle_packets": "修复了一个由Forge补丁引入的问题,此问题会导致玩家在区块边界上乘坐交通工具时,服务器向该玩家发送非常大量的区块数据包。", + "modernfix.option.mixin.bugfix.mantle_model_cme": "修复了地幔(Mantle)的一个问题,此问题会导致渲染匠魂相关内容时毫无规律地触发并发修改异常(ConcurrentModificationException)而崩溃。", + "modernfix.option.mixin.bugfix.model_data_manager_cme": "规避Forge的ModelDataManager的一些设计缺陷,这些缺陷可能导致突发性的并发问题。", + "modernfix.option.mixin.bugfix.recipe_book_type_desync": "修复具有模组额外添加的配方书条目类型的Forge客户端在连接到原版服务器时强制断连的问题。", + "modernfix.option.mixin.bugfix.unsafe_modded_shape_caches": "修复内容型模组在计算方块形状时可能发生的并发修改异常(ConcurrentModificationException)", + "modernfix.option.mixin.feature.stalled_chunk_load_detection": "此选项对检测区块加载冻结可能有所帮助。不过,开启此选项也可能导致轻微性能下降。", + "modernfix.option.mixin.perf.fix_loop_spin_waiting": "修复Minecraft内置的wait函数(方法)消耗过量CPU资源的问题。", + "modernfix.option.mixin.perf.forge_cap_retrieval": "微优化,让Forge在获取自定义实体数据上更有效率一点。", + "modernfix.option.mixin.perf.forge_registry_lambda": "修复Forge注册系统的一些疏漏,其会使得其中的热点方法产生过量的内存分配需求。" } From 32b0216b1943ef5635cff94cbad7daa51d50a5aa Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:13:12 -0400 Subject: [PATCH 5/5] Work around Carpet crash when remove_spawn_chunks is enabled Related: #390 --- .../SortedArraySetMixin.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java new file mode 100644 index 00000000..814b2ca9 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java @@ -0,0 +1,25 @@ +package org.embeddedt.modernfix.common.mixin.perf.remove_spawn_chunks; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.util.SortedArraySet; +import org.embeddedt.modernfix.ModernFix; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(SortedArraySet.class) +public class SortedArraySetMixin { + /** + * @author embeddedt + * @reason Make add() not crash with a null key, since some mods (Carpet) assume there will always be a spawn ticket, + * and then assume the reference they have is non-null (it can be null with this option enabled). + */ + @WrapOperation(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/SortedArraySet;findIndex(Ljava/lang/Object;)I"), require = 0) + private int checkStatus(SortedArraySet instance, T object, Operation original) { + if(object == null) { + ModernFix.LOGGER.error("Attempted to insert a null key into SortedArraySet, ignoring"); + return 0; + } + return original.call(instance, object); + } +}