gpt4 book ai didi

java - Minecraft 实体注册表在服务器加载时失败

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:25 53 4
gpt4 key购买 nike

对于我来说,我无法弄清楚为什么这段代码在基于客户端的启动器中运行良好,但是一旦您尝试注册实体,服务器就会崩溃。

这是代码,我现在迷路了,我也尝试了其他注册方式,但那也没有任何作用。

    package com.muddykat.grimoire.entity;

import com.muddykat.grimoire.entity.mob.EntityImp;
import com.muddykat.grimoire.entity.mob.EntityProwler;
import com.muddykat.grimoire.lib.GrimoireLib;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod.EventBusSubscriber
public class EntityReg {
private EntityReg() {
}

public static void preInit() {
//registerEntity(EntityImp.class, "demon_imp", 0x660000, 0xB8AB8D);
//registerEntity(EntityProwler.class, "demon_prowler", 0x660000, 0xB8AB8D);
}

private static int id = 0;


@SubscribeEvent
public static void registerEntities(RegistryEvent.Register<EntityEntry> event) {
EntityEntry imp = EntityEntryBuilder.create()
.entity(EntityImp.class)
.id(new ResourceLocation(GrimoireLib.MODID + ":demon_imp"), id++)
.name("grimoire.demon_imp")
.egg(0x660000, 0xB8AB8D)
.tracker(64, 3, true)
.build();
event.getRegistry().register(imp);

EntityEntry prowler = EntityEntryBuilder.create()
.entity(EntityProwler.class)
.id(new ResourceLocation(GrimoireLib.MODID + ":demon_prowler"), id++)
.name("grimoire.demon_prowler")
.egg(0x660000, 0xB8AB8D)
.tracker(64, 3, true)
.build();
event.getRegistry().register(prowler);
}
}

这是崩溃日志

    ---- Minecraft Crash Report ----
// This doesn't make any sense!

Time: 12/17/18 6:49 PM
Description: Exception in server tick loop

java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at net.minecraftforge.fml.relauncher.ReflectionHelper.findConstructor(ReflectionHelper.java:255)
at net.minecraftforge.fml.common.registry.EntityEntryBuilder$ConstructorFactory.<init>(EntityEntryBuilder.java:298)
at net.minecraftforge.fml.common.registry.EntityEntryBuilder$1.<init>(EntityEntryBuilder.java:266)
at net.minecraftforge.fml.common.registry.EntityEntryBuilder.build(EntityEntryBuilder.java:266)
at com.muddykat.grimoire.entity.EntityReg.registerEntities(EntityReg.java:37)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_5_EntityReg_registerEntities_Register.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:789)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:628)
at net.minecraftforge.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:99)
at net.minecraftforge.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:333)
at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:128)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:552)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.multiplayer.WorldClient
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 20 more
Caused by: net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerException: Exception in class transformer net.minecraftforge.fml.common.asm.transformers.SideTransformer@14f3c6fc from coremod FMLCorePlugin
at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:260)
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279)
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176)
... 22 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/multiplayer/WorldClient for invalid side SERVER
at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:62)
at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:256)
... 24 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.12.2
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_181, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 879695752 bytes (838 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.42 Powered by Forge 14.23.5.2768 6 mods loaded, 6 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

| State | ID | Version | Source | Signature |
|:----- |:--------- |:------------ |:-------------------------------- |:--------- |
| UCH | minecraft | 1.12.2 | minecraft.jar | None |
| UCH | mcp | 9.42 | minecraft.jar | None |
| UCH | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2768.jar | None |
| UCH | forge | 14.23.5.2768 | forgeSrc-1.12.2-14.23.5.2768.jar | None |
| UCH | grimoire | 1.0 | bin | None |
| UCH | jei | 4.13.1.225 | jei_1.12.2-4.13.1.225.jar | None |

Loaded coremods (and transformers):
Profiler Position: N/A (disabled)
Is Modded: Definitely; Server brand changed to 'fml,forge'
Type: Dedicated Server (map_server.txt)

最佳答案

因为服务器不知道渲染器(以及其他一些东西)是什么

某些类仅出现在客户端(专用服务器 jar 与客户端 jar 不同),因为服务器不渲染任何内容,不知道键盘是什么,也不播放音频。

让我们看看错误:

java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient
at com.muddykat.grimoire.entity.EntityReg.registerEntities(EntityReg.java:37)

找不到的类位于 net.minecraft.client 中(这是客户端专用的东西!),名为 WorldClient,客户端使用它在本地存储世界数据(对其所做的更改很大程度上会被忽略,并在服务器发送更新时被覆盖)。错误堆栈跟踪包含很多内容,但它确实包含实体注册中代码内的调用。它少了几行,但这并不意味着你没有错(你确实有错)。

我无法判断哪一行是第 37 行,但是您的两个实体类之一可能包含对 WorldClient 的引用,当您将该类传递给 EntityBuilder 时,JVM 会查看该类并询问:“我可以找到该类所做的所有引用吗?”为 WorldClient 找到一个,然后说:“不!我不知道那是什么”,然后崩溃了……即使这种崇敬永远不会被唤起(JVM 无法知道这一点)。

进一步诊断需要查看您的实体的代码。

关于java - Minecraft 实体注册表在服务器加载时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53810918/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com