【问题标题】:change the displayed name of the minecraft version更改 minecraft 版本的显示名称
【发布时间】:2021-08-07 20:59:04
【问题描述】:

我正在尝试更改 minecraft 版本的显示名称,因为某些服务器具有通过检查其版本来检测客户端是否正在运行 forge 的插件,我尝试反编译几个 .class 文件以搜索该设置但我没找到,here the screen of what "displayed version" i'm talking about

我发现的唯一东西就是这个“id”,但如果我改变它,我只会让我的世界崩溃。

{
    "_comment_": [
        "Please do not automate the download and installation of Forge.",
        "Our efforts are supported by ads from the download page.",
        "If you MUST automate this, please consider supporting the project through https://www.patreon.com/LexManos/"
    ],
    "id": "1.16.5-forge-36.2.0",
    "time": "2021-07-22T01:48:10+00:00",
    "releaseTime": "2021-07-22T01:48:10+00:00",
    "type": "release",
    "mainClass": "cpw.mods.modlauncher.Launcher",
    "inheritsFrom": "1.16.5",
    "logging": {
        
    },

请帮忙,这让我很生气。

【问题讨论】:

    标签: json minecraft


    【解决方案1】:

    这称为客户品牌。 Vanilla Minecraft 使用vanilla,Forge 使用fml,forge,Lunar 客户端使用Lunarclient:LunarVersionNumber,等等。我不知道1.16.5,但在1.8.9 中用于获取客户端品牌的类是@987654324 @(类似于 1.8.9)。您需要在运行时使用 mixins 或其他操作代码的方式来修改它。

    【讨论】:

    • 我试图检查该文件,但已经设置为“vanilla”,我将代码放在这里:package net.minecraft.client; public class ClientBrandRetriever { public static String getClientModName() { return "vanilla"; } } 这是位于 .minecraft\versions\1.16.5- 中的 ClientBrandRetriever.class forge-36.2.0\1.16.5-forge-36.2.0\net\minecraft\client,这个是解压后的jar文件所在的文件夹
    • @nicolas200221 我很确定 forge 就像 Minecraft 的一个库。它运行在 Minecraft 代码之上。您需要创建一个编辑客户品牌的锻造模组。当我在 MDK 中查看它时,我可以看到它将品牌编辑为“fml,forge”。
    • 好吧,我从来没有做过 minecraft mod,我非常了解 java,你能帮我告诉我要做什么吗?我认为我必须以某种方式覆盖 ClientBrandRetriever 类的 getClientModName 方法,对吗?或者如果可以的话,只修改和重新编译 forge 所在的库
    • @nicolas200221 我不太确定,imo 最简单的方法是创建一个模组
    【解决方案2】:

    好吧,实际上我在尝试制作 mod 时发现了一些东西,我找到了这个 2 .class 文件。 Forge 的 ClientBrandRetriever.class

    package net.minecraft.client;
    
    import net.minecraftforge.api.distmarker.Dist;
    import net.minecraftforge.api.distmarker.OnlyIn;
    
    @OnlyIn(Dist.CLIENT)
    public class ClientBrandRetriever {
       public static String getClientModName() {
          return net.minecraftforge.fml.BrandingControl.getClientBranding();
       }
    }
    

    这叫做 BrandingControl.class

    /*
     * Minecraft Forge
     * Copyright (c) 2016-2021.
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation version 2.1
     * of the License.
     *
     * This library is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with this library; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     */
    
    package net.minecraftforge.fml;
    
    import com.google.common.collect.ImmutableList;
    import com.google.common.collect.Lists;
    import java.util.List;
    import java.util.function.BiConsumer;
    import java.util.stream.IntStream;
    
    import net.minecraft.resources.IResourceManager;
    import net.minecraft.resources.IResourceManagerReloadListener;
    import net.minecraftforge.client.ForgeHooksClient;
    import net.minecraftforge.versions.forge.ForgeVersion;
    import net.minecraftforge.versions.mcp.MCPVersion;
    
    
    public class BrandingControl
    {
        private static List<String> brandings;
        private static List<String> brandingsNoMC;
        private static List<String> overCopyrightBrandings;
    
        private static void computeBranding()
        {
            if (brandings == null)
            {
                ImmutableList.Builder<String> brd = ImmutableList.builder();
                brd.add("Forge " + ForgeVersion.getVersion());
                brd.add("Minecraft " + MCPVersion.getMCVersion());
                brd.add("MCP " + MCPVersion.getMCPVersion());
                int tModCount = ModList.get().size();
                brd.add(ForgeI18n.parseMessage("fml.menu.loadingmods", tModCount));
                brandings = brd.build();
                brandingsNoMC = brandings.subList(1, brandings.size());
            }
        }
    
        private static List<String> getBrandings(boolean includeMC, boolean reverse)
        {
            computeBranding();
            if (includeMC) {
                return reverse ? Lists.reverse(brandings) : brandings;
            } else {
                return reverse ? Lists.reverse(brandingsNoMC) : brandingsNoMC;
            }
        }
    
        private static void computeOverCopyrightBrandings() {
            if (overCopyrightBrandings == null) {
                ImmutableList.Builder<String> brd = ImmutableList.builder();
                if (ForgeHooksClient.forgeStatusLine != null) brd.add(ForgeHooksClient.forgeStatusLine);
                overCopyrightBrandings = brd.build();
            }
        }
    
        public static void forEachLine(boolean includeMC, boolean reverse, BiConsumer<Integer, String> lineConsumer) {
            final List<String> brandings = getBrandings(includeMC, reverse);
            IntStream.range(0, brandings.size()).boxed().forEachOrdered(idx -> lineConsumer.accept(idx, brandings.get(idx)));
        }
    
        public static void forEachAboveCopyrightLine(BiConsumer<Integer, String> lineConsumer) {
            computeOverCopyrightBrandings();
            IntStream.range(0, overCopyrightBrandings.size()).boxed().forEachOrdered(idx->lineConsumer.accept(idx, overCopyrightBrandings.get(idx)));
        }
    
        public static String getClientBranding() {
            return "forge";
        }
    
        public static String getServerBranding() {
            return "forge";
        }
    
        public static IResourceManagerReloadListener resourceManagerReloadListener() {
            return BrandingControl::onResourceManagerReload;
        }
    
        private static void onResourceManagerReload(IResourceManager resourceManager) {
            brandings = null;
            brandingsNoMC = null;
        }
    }
    

    此时我设法重建了最后一个 .class 文件,更改客户端和服务器品牌返回“elberto”,现在当我运行 sdk 环境时,它在版本上显示“elberto”,但是当我尝试对实际加载的 minecraft forge 文件执行相同操作,并在加载结束时崩溃。

    我很确定这不是做我想做的事的好方法,如果你知道更好的方法来做一个我正在听的正确的工作模式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多