MCreator 内存修复
修复了部分基于 Forge 1.20.1 的 MCreator 模组中存在的大内存分配错误。该模组会在首次启动时检测相关模组,随后需要重启游戏以使效果生效。对于使用 Forge 1.20.1 Generator >=1.0(2025年10月28日)制作的模组,已不再需要此修复。即使检测到这些模组,本模组通常也不会与之产生冲突,但不会对它们产生任何影响。
关于
简要说明
- 此模组可修复某些包含大量玩家绑定变量的 MCreator 模组的过高内存分配率。
- 这可能会减少垃圾回收(GC)卡顿、降低平均/峰值内存占用,甚至带来小幅度的帧数提升。
具体效果因人而异,完全取决于你安装的 MCreator 模组。
- 安装此模组不应有任何负面影响。
- 启动游戏时,本模组会检测所有适用的模组,
但直到你再次启动游戏后才会生效。
- 整合包制作者应重新分发位于
.minecraft/config 目录下的 mcreator_mem_fix.json 文件,
并可选择性通过在该 JSON 对象中添加 locked 键并将其设置为 true 来锁定它。
这样可以防止在模组列表发生变化时模组重新生成其配置文件。
下面有一些轻量级的技术内容。没什么大不了的。
问题所在
每当 MCreator 模组访问其玩家变量时,它都会创建一个新的对象作为默认值,然后访问存储的那个变量。
如果不存在存储的变量,则使用默认值。如果存在存储的变量,那么之前创建的默认值就是毫无意义的浪费。
问题出在哪里?许多 MCreator 模组经常访问玩家变量。
这导致了大量的不必要内存分配。
这些分配可能在每个刻(tick)和每帧中发生无数次,
导致每秒产生巨量的内存分配。
解决方案
此模组仅仅是阻止了在每次 MCreator 模组想要访问其玩家变量时都创建那个对象。
它为每个模组存储一个默认的变量对象,而不是每次访问时都创建一个新对象,而是回退到存储的默认值。很简单。
安装此模组后,功能上应该没有任何差异。
效果
某些 MCreator 模组在垃圾回收机制介入之前,可能会分配多达约 300MB 的垃圾数据。
内存分配是一项缓慢的操作,为了毫无收益而分配如此多的内存是不必要的。
有了这个模组,MCreator 模组中关于玩家变量的内存分配量应该会降至微乎其微。
这可能会减少卡顿、降低平均/峰值内存占用,甚至带来小幅度的帧数提升。具体效果因人而异。
我实际上并没有进行太多测试,但该模组应该不会引起很多问题。它几乎是免费的,几乎没有或没有任何负面影响。
兼容性
不清楚。只要没有其他模组触碰与本模组相同的代码部分,大概应该是没问题的(显然,这通常是兼容性的运作方式)。
这个模组稍微有些侵入性,它修改了许多原始模组的类,但应该是以一种相对干净的方式进行的。
任何没有明确触及 MCreator 模组的模组都应该始终保持 100% 兼容。除非我把什么东西搞砸了。
常见问题解答
免责声明:从来没有人问过我的这些问题。
如何让它在特定的 MCreator 模组上生效?
运行游戏时,会在配置目录 .minecraft/config 中创建一个文件。
在此文件创建之后,你应该重启游戏以确保已检测到的 MCreator 模组已被修改。
添加新的 MCreator 模组后,你应该删除此文件以便模组重新扫描你的模组。
当模组扫描 MCreator 模组时会记录一条消息。
整合包开发者可以安全地重新分发此配置文件,
从而避免最终用户不得不重启游戏。
他们还可以通过在配置文件中添加并将 locked 键设置为 true 来锁定此文件。
这并不是真的有必要,但它能阻止模组搜索新的待修改候选项,
从而节省启动时的几毫秒时间。
出了点问题。我怎么修复它?
首先,尝试删除配置文件并重新运行游戏一两次。
如果那不起作用,请在此处提交问题 here。
你看起来很酷。可以做我的朋友吗?
不行。也许吧。
我可以在整合包中使用它吗?
当然可以,它是为此设计的。
MCreator Memory Fix
Fixes a large memory allocation bug in some MCreator for Forge 1.20.1 mods. Detects mods on first startup, then a restart is required for effects to activate. Is no longer required for mods made with the Forge 1.20.1 Generator >=1.0 (28/10/2025). This mod still shouldn't have any conflicts with these mods, even if it detects them, but it won't affect them.
About
TLDR
- This mod fixes high allocation rates in some MCreator mods that use a lot of player-attached variables.
- This might result in less GC stuttering, less average/peak memory usage, and even a small FPS gain.
Your mileage may vary, and it entirely depends on your installed MCreator mods.
- There shouldn't be any downsides to having this mod installed.
- This mod will detect all applicable mods when you launch the game,
but it will not come into effect until you launch the game again.
- Modpack creators should redistribute the
mcreator_mem_fix.json file found in .minecraft/config,
and may optionally lock it by adding the locked key to the json object found within the config file, and setting it to true.
This prevents the mod from regenerating its config when the mod list changes.
Some light technical stuff ahead. Nothing too bad.
The Issue
Whenever an MCreator mod accesses its player variables at all, it creates a new object to serve as a default, then accesses the stored one.
If there is no stored one, the default one is used. If there is a stored one, the default one was created for no reason.
Where's the problem? Many MCreator mods like to access player variables a lot.
This results in a lot of unnecessary allocations.
These allocations can happen many, many times within both ticks and frames,
resulting in a large amount of allocations per second.
The Solution
This mod just stops that object from being created every time an MCreator mod wants to access its player variables.
It stores a default variables object for each mod, and instead of making a new object every time we access it, we fall back to the stored default. Easy.
There shouldn't be any functional difference with this mod installed.
Effect
Some MCreator mods can allocate up to ~300MB of garbage before the GC does its thing.
Memory allocation is a slow operation, and allocating that much memory for no gain is not necessary.
With this mod, the memory allocation from MCreator mods, regarding player variables, should drop to next to nothing.
This might result in less stuttering, less average/peak memory usage, and even a small FPS gain. Your mileage may vary.
I haven't actually tested much, but this mod shouldn't cause many issues. It's pretty much free, with little-to-no downside.
Compatibility
No idea. Should probably be fine as long as no other mod is touching the same stuff this one touches (obviously, that's usually how compatibility works).
This mod is a little intrusive, it modifies a lot of the original mod's classes, BUT it should be in a relatively clean way.
Any mod that doesn't explicitly touch MCreator mods should be 100% compatible, always. Unless I mess something up.
FAQ
DISCLAIMER: Not a single individual has ever asked me any one of these questions.
How do I make it work for a specific MCreator mod?
Upon running the game, a file in
the config directory .minecraft/config will be created.
After this file is created, you should restart the game to ensure the detected MCreator mods are modified.
After adding new MCreator mods, you should delete this file so the mod rescans your mods.
A message is logged when the mod scans for MCreator mods.
Modpack developers may safely redistribute this config file,
preventing the end user from having to restart their game.
They may also lock this file by adding and setting the locked key to true in the config.
This is not really necessary, but it stops the mod from searching for new candidates to modify,
saving a few milliseconds on startup.
Something went wrong. How do I fix it?
First things first, try deleting the config and re-running the game once or twice.
If that doesn't work, submit an issue here.
You seem really cool. Can you be my friend?
No. Maybe.
Can I use this in a modpack?
Yeah, it's designed for that.
评论 0
登录后参与评分
还没有评论,来抢沙发吧