Jump to content

[SOLVED][1.7.x] Bug in FML, or am I just not understanding?


coolAlias

Recommended Posts

Hey again,

 

So I thought I had this server-client stuff all worked out, but I've run across a perplexing situation: trying to access Minecraft.getMinecraft(), even inside a conditional to check if we're on the client, causes the server to crash on startup, before the method that this is in can even be called!

 

The offending class:

 

public abstract class AbstractMessageHandler<T extends IMessage> implements IMessageHandler <T, IMessage>
{
/**
 * Handle a message received on the client side
 * @return a message to send back to the Server, or null if no reply is necessary
 */
public abstract IMessage handleClientMessage(EntityPlayer player, T message, MessageContext ctx);

/**
 * Handle a message received on the server side
 * @return a message to send back to the Client, or null if no reply is necessary
 */
public abstract IMessage handleServerMessage(EntityPlayer player, T message, MessageContext ctx);

@Override
public IMessage onMessage(T message, MessageContext ctx) {
// this should only run on the client side, right? but it crashes the game referencing EntityClientPlayerMP:
	if (ctx.side == Side.CLIENT && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
		System.out.println("THIS NEVER PRINTS");
		// but commenting out the following line prevents the crash:
		return handleClientMessage(Minecraft.getMinecraft().thePlayer, message, ctx);
	} else {
		return handleServerMessage(ctx.getServerHandler().playerEntity, message, ctx);
	}
}
}

public abstract class AbstractServerMessageHandler<T extends IMessage> extends AbstractMessageHandler<T> {
public final IMessage handleClientMessage(EntityPlayer player, T message, MessageContext ctx) {
	return null;
}
}

public abstract class AbstractClientMessageHandler<T extends IMessage> extends AbstractMessageHandler<T> {
public final IMessage handleServerMessage(EntityPlayer player, T message, MessageContext ctx) {
	return null;
}
}

 

 

A class implementing the above:

 

public class OpenGuiMessage implements IMessage {
private int id;

public OpenGuiMessage() {}

public OpenGuiMessage(int id) {
	this.id = id;
}

@Override
public void fromBytes(ByteBuf buffer) {
	id = buffer.readInt();
}

@Override
public void toBytes(ByteBuf buffer) {
	buffer.writeInt(id);
}

// using this version results in the server crash:
public static class OpenGuiMessageHandler extends AbstractServerMessageHandler<OpenGuiMessage> {
	@Override
	public IMessage handleServerMessage(EntityPlayer player, OpenGuiMessage message, MessageContext ctx) {
		player.openGui(Main.instance, message.id, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
		return null;
	}
}
/*
// using the standard IMessageHandler interface works fine:
public static class OpenGuiMessageHandler implements IMessageHandler<OpenGuiMessage, IMessage> {
	@Override
	public IMessage onMessage(OpenGuiMessage message, MessageContext ctx) {
		EntityPlayer player = ctx.getServerHandler().playerEntity;
		player.openGui(Main.instance, message.id, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
		return null;
	}
}
*/
}

 

 

Registering the messages is nothing out of the ordinary:

// registered during pre-initialization
dispatcher.registerMessage(OpenGuiMessage.OpenGuiMessageHandler.class, OpenGuiMessage.class, packetId++, Side.SERVER);

dispatcher.registerMessage(SyncPlayerPropsMessage.SyncPlayerPropsMessageHandler.class, SyncPlayerPropsMessage.class, packetId++, Side.CLIENT);

 

Crash Log:

 

[07:47:46] [server thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue
[07:47:46] [server thread/ERROR] [FML]: 
mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{7.2.211.1121} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.2.1121.jar) Unloaded->Constructed->Pre-initialized
Forge{10.12.2.1121} [Minecraft Forge] (forgeSrc-1.7.2-10.12.2.1121.jar) Unloaded->Constructed->Pre-initialized
test{1.7.2-1.0.0} [Test] (bin) Unloaded->Constructed->Errored
[07:47:46] [server thread/ERROR] [FML]: The following problems were captured during this phase
[07:47:46] [server thread/ERROR] [FML]: Caught exception from test
java.lang.NoClassDefFoundError: net/minecraft/client/entity/EntityClientPlayerMP
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.7.0_25]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:22) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:129) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:117) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:107) ~[simpleNetworkWrapper.class:?]
at test.network.PacketDispatcher.registerPackets(PacketDispatcher.java:57) ~[PacketDispatcher.class:?]
at test.Main.preInit(Main.java:118) ~[Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:512) [Loader.class:?]
at cpw.mods.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:88) [FMLServerHandler.class:?]
at cpw.mods.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:313) [FMLCommonHandler.class:?]
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:117) [DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:442) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) [MinecraftServer$2.class:?]
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.entity.EntityClientPlayerMP
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
... 42 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/entity/EntityClientPlayerMP for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) ~[forgeSrc-1.7.2-10.12.2.1121.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:276) ~[launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:174) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
... 42 more
[07:47:46] [server thread/ERROR]: Encountered an unexpected exception
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraft/client/entity/EntityClientPlayerMP
at cpw.mods.fml.common.LoadController.transition(LoadController.java:162) ~[LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:514) ~[Loader.class:?]
at cpw.mods.fml.server.FMLServerHandler.beginServerLoading(FMLServerHandler.java:88) ~[FMLServerHandler.class:?]
at cpw.mods.fml.common.FMLCommonHandler.onServerStart(FMLCommonHandler.java:313) ~[FMLCommonHandler.class:?]
at net.minecraft.server.dedicated.DedicatedServer.startServer(DedicatedServer.java:117) ~[DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:442) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) [MinecraftServer$2.class:?]
Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/entity/EntityClientPlayerMP
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.7.0_25]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:22) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:129) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:117) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:107) ~[simpleNetworkWrapper.class:?]
at test.network.PacketDispatcher.registerPackets(PacketDispatcher.java:57) ~[PacketDispatcher.class:?]
at test.Main.preInit(Main.java:118) ~[Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:512) ~[Loader.class:?]
... 5 more
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.entity.EntityClientPlayerMP
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:188) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.7.0_25]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:22) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:129) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:117) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:107) ~[simpleNetworkWrapper.class:?]
at test.network.PacketDispatcher.registerPackets(PacketDispatcher.java:57) ~[PacketDispatcher.class:?]
at test.Main.preInit(Main.java:118) ~[Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:512) ~[Loader.class:?]
... 5 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/entity/EntityClientPlayerMP for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) ~[forgeSrc-1.7.2-10.12.2.1121.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:276) ~[launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:174) ~[launchwrapper-1.9.jar:?]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.7.0_25]
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.getConstructor0(Unknown Source) ~[?:1.7.0_25]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:22) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:129) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:117) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:107) ~[simpleNetworkWrapper.class:?]
at test.network.PacketDispatcher.registerPackets(PacketDispatcher.java:57) ~[PacketDispatcher.class:?]
at test.Main.preInit(Main.java:118) ~[Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_25]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_25]
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74) ~[guava-15.0.jar:?]
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296) ~[guava-15.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:267) ~[guava-15.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:512) ~[Loader.class:?]
... 5 more

 

 

I have used similar code in many other classes without ever causing a problem, but for some reason this one seems to be an exception.

 

So my question: Why is the above code attempting to load EntityClientPlayerMP during server startup, when the onMessage method should not even be called yet? At the very least, if I didn't check side and tried to access Minecraft.getMinecraft(), I would expect it to only crash when the line was actually reached in the code, but as can be seen from my println (which never prints), it never even tries to access Minecraft.getMinecraft().

 

Is this possibly a bug in FML, or am I just completely off base here?

 

Thanks for reading,

coolAlias

Link to comment
Share on other sites

@Elyon: My PacketDispatcher class is just a wrapper for the SimpleNetworkWrapper:

 

public class PacketDispatcher {
private static byte packetId = 0;

private static final SimpleNetworkWrapper dispatcher = NetworkRegistry.INSTANCE.newSimpleChannel(Main.MOD_ID);

// currently called from preinit:
public static final void registerPackets() {
	PacketDispatcher.dispatcher.registerMessage(OpenGuiMessage.OpenGuiMessageHandler.class, OpenGuiMessage.class, packetId++, Side.SERVER);
	PacketDispatcher.dispatcher.registerMessage(SyncPlayerPropsMessage.SyncPlayerPropsMessageHandler.class, SyncPlayerPropsMessage.class, packetId++, Side.CLIENT);
}

/**
 * Send this message to the specified player.
 * See {@link SimpleNetworkWrapper#sendTo(IMessage, EntityPlayerMP)}
 */
public static final void sendTo(IMessage message, EntityPlayerMP player) {
	PacketDispatcher.dispatcher.sendTo(message, player);
}

/**
 * Send this message to everyone within a certain range of a point.
 * See {@link SimpleNetworkWrapper#sendToDimension(IMessage, NetworkRegistry.TargetPoint)}
 */
public static final void sendToAllAround(IMessage message, NetworkRegistry.TargetPoint point) {
	PacketDispatcher.dispatcher.sendToAllAround(message, point);
}

/**
 * Sends a message to everyone within a certain range of the coordinates in the same dimension.
 */
public static final void sendToAllAround(IMessage message, int dimension, double x, double y, double z, double range) {
	PacketDispatcher.sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, x, y, z, range));
}

/**
 * Sends a message to everyone within a certain range of the player provided.
 */
public static final void sendToAllAround(IMessage message, EntityPlayer player, double range) {
	PacketDispatcher.sendToAllAround(message, player.worldObj.provider.dimensionId, player.posX, player.posY, player.posZ, range);
}

/**
 * Send this message to everyone within the supplied dimension.
 * See {@link SimpleNetworkWrapper#sendToDimension(IMessage, int)}
 */
public static final void sendToDimension(IMessage message, int dimensionId) {
	PacketDispatcher.dispatcher.sendToDimension(message, dimensionId);
}

/**
 * Send this message to the server.
 * See {@link SimpleNetworkWrapper#sendToServer(IMessage)}
 */
public static final void sendToServer(IMessage message) {
	PacketDispatcher.dispatcher.sendToServer(message);
}
}

 

 

@GotoLink - interesting idea, I'll give it a try and let you know how it goes. EDIT: Nope, gives the same crash :\

Link to comment
Share on other sites

You can't use client classes (in your case the Minecraft class) in your Packet classes, since the server uses them, too.

Interesting; so how is one supposed to get the player in messages sent to the client in the IMessageHandler#onMessage class?

 

public static class SyncPlayerPropsMessageHandler implements IMessageHandler<SyncPlayerPropsMessage, IMessage> {
	@Override
	public IMessage onMessage(SyncPlayerPropsMessage message, MessageContext ctx) {
		// THIS DOES NOT WORK:
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
		ExtendedPlayer.get(player).loadNBTData(message.data);
		return null;
	}
}

Link to comment
Share on other sites

**This is not tested, i am just speculating. If this doesn't work, don't rage on me of giving wrong info**

 

You can check the side of the context you get, and if it's Side.CLIENT, you can use Minecraft.*, and if it's Side.SERVER, You can use the MessageContext you get passed in, use the

getServerHandler()

method which has a EntityPlayer object called entityPlayer that youc an use.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Put your client-only methods under @SideOnly(Side.CLIENT) ? The stuff should be stripped.

Or hide the call into your proxy.

 

//In client proxy
@Override
public EntityPlayer getClientPlayer(){ return Minecraft.getMinecraft().thePlayer; }

//In packet handler
if(messageContext.side.isClient()){
handleClientMessage(MyMod.proxy.getClientPlayer(), message);
}

Link to comment
Share on other sites

There is a much better way.

 

In your Server Proxy, make a method called getPlayerFromMessageContext(MessageContext ctx) and make it return ctx.getServerHandler().playerEntity

 

Then, in your Client Proxy, override it and just return Minecraft.getMinecraft().thePlayer

 

It is a much better solution than GotoLink's suggestion because you don't have to.check for sides and no @SideOnly's are needed. Basically this is what diesieben07 suggested.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Thanks everyone for the various solutions - I think it should work now, though I get a funky server error that I've only seen with 1180:

 

[20:20:58] [server thread/INFO] [FML]: Holder lookups applied
[20:20:58] [server thread/INFO]: Loading properties
[20:20:58] [server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
[20:20:58] [server thread/WARN] [FML]: Can't revert to frozen GameData state without freezing first.
[20:20:58] [server thread/INFO] [FML]: Applying holder lookups
[20:20:58] [server thread/INFO] [FML]: Holder lookups applied
[20:20:58] [server thread/INFO] [FML]: The state engine was in incorrect state POSTINITIALIZATION and forced into state SERVER_STOPPED. Errors may have been discarded.

 

 

Anyway, I shall mark this as solved for now, but I find it very bizarre that the class loading is so fragile in this particular case. As larsgerrits mentioned and I already tried in my first attempts, usually nesting such code in an 'if (client side)' statement is enough, and as my println proved, the offending code was never even called, but FML still somehow both found and decided to load that class, which is even more surprising because no packets are even being sent at that point to trigger the onMessage method.

 

Requiring such bizarre workarounds to simply get an EntityPlayer while handling a packet does not seem like the most ideal framework, but I don't know much about what needs to happen in FML so maybe it is the only way. I hope that a patch comes along soon that fixes this issue, if possible.

 

Thanks again everyone.

Link to comment
Share on other sites

If you want to be technical, this is probably compiler-level stuff.

Your original #handleClientMessage was probably given a signature with EntityClientPlayerMP by the compiler, then type-erasure and/or binary compatibility triggered, making you unable to change that signature in more recent compilations. (the bytecode would be needed to confirm this assumption)

 

@Kwibble

It would be nicer if you didn't try to compare codes that don't produce the same result.

Link to comment
Share on other sites

Thanks for the further insight, but I am still very confused; even when NOT using my abstract classes but instead implementing IMessageHandler directly (still as an inner class), the server will crash with the exact same error:

public static class SyncPlayerPropsMessageHandler implements IMessageHandler<SyncPlayerPropsMessage, IMessage> {
	@Override
	public IMessage onMessage(SyncPlayerPropsMessage message, MessageContext ctx) {
		EntityPlayer player = Minecraft.getMinecraft().thePlayer;
		ExtendedPlayer.get(player).loadNBTData(message.data);
		return null;
	}
}

// crashes with:
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/entity/EntityClientPlayerMP for invalid side SERVER

// pointing to the line that registers the above message class

 

To me, this means that it is impossible to handle many client side messages, since the server will crash every single time even though this code should not be accessed during start-up.

 

As a counter-example, the way the rest of Minecraft works:

public class SomeRandomClass {

public void someRandomMethod(World world) {
if (world.isRemote) { // on the client
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
// works perfectly fine
}
}
}

This has been my experience and understanding of the code so far - there has never been a need to use @SideOnly for stuff like this, simply checking side via the world or FMLCommonHandler is enough to segregate the code and prevent the server from trying to access it.

 

But with SimpleNetworkWrapper, this does not seem to be the case. If we can't access things like Keyboard, Minecraft class, etc. in our client messages, then the network code seems fairly broken to me still. Of course it seems to work, but only on single player; has anyone been able to use it successfully for a wide variety of different messages in a server environment?

Link to comment
Share on other sites

You need to redirect client message handling through your Client proxy, as I explained above.

Yes, that does work, but it seems like a very bizarre step to have to take. I guess I'm just frustrated with the fickle behavior of SimpleNetworkWrapper and the lack of documentation explaining such nuances. The 'memory-leaky' network code never had any such trouble and was very easy to use, whereas now I feel like I'm jumping through hoops that most certainly shouldn't exist in the first place.

 

Btw, does anyone know specifically which part of the wiki code causes a memory leak? It always worked without fail for me, and I didn't notice any memory problems, so I'm curious what's wrong with it.

 

Anyway, thanks again for the responses.

Link to comment
Share on other sites

Oh... I did not know that... so why is it that in many cases simply nesting is enough?

 

Some examples that will not crash the server:

// in an event:
@SubscribeEvent
public void onHurt(LivingHurtEvent event) {
if (event.entity.worldObj.isRemote) { // I don't do this - just an example!
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
}
}

// in an item:
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (world.isRemote) {
	// able to access objectmouseover, Keyboard and other client-side only stuff
	// without crashing server
}
}

 

I could give many more examples that I have used previously, none of which have any problems loading client classes in a class that may be accessed on both sides. I have never had to resort to using proxies to access such things, but merely as a convenient place to register client-only classes such as renderers. In fact I've always thought modders who placed tons of things in their client proxy were doing unnecessary work, but it appears I don't understand this stuff nearly as well as I had thought.

 

I promise I'm not trying to be obtuse, but I don't see what the difference is between my examples, which have worked perfectly fine for me, and the message classes above, which crash the server immediately. I've been going about modding very incorrectly this whole time if we're supposed to have always used proxies for this kind of thing. Is there perhaps a resource somewhere that explains this in more depth?

Link to comment
Share on other sites

I was going to ask same question as coolalias but am on my phone so couldn't write up examples as nicely.

 

At what point does Java hang up on missing (ie due to sided proxy) classes.  I guess the import itself might fail?  Or just when you try to access the class? I thought that just checking isRemote (or otherwise being sure that code was only being called on one side)  could protect you from running client only code on server.  Or does Java runtime try to resolve it all even for paths it might not execute?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Hi

 

I wrestled with this back in 1.6.4 for a while, where it all worked fine until I installed my jar in a dedicated server and everything broke, not the same FML classloader errors but a similar idea, i.e. the jvm found references to client-side objects in my code even when those statements were never executed, and threw some linkage errors I forget exactly what they were.

 

Anyway the basic rules I follow now are

1) Make each class side-specific if at all possible.  Server-side classes never refer to client-side at all, only server-side and common.  Client-side classes never refer to server-side at all, only client-side and common.

2) If I'm writing common classes, either because they're overriding vanilla common or because I want to share the same code on both server and client, I only refer to vanilla common classes, never client or server side vanilla, even if .isRemote is available.  If I need to access sided vanilla from a common class (rare), I either use a method in my proxy or more frequently I call one of my sided classes to do it instead (with isRemote to choose the correct side).  For forge code which attempts to be present on both sides, in particular some tick handlers and some packet handlers, my proxy init registers a different packet handler class for each side (i.e. dedicated server doesn't register a client handler).  Generally I try to keep handlers as stubs which do essentially nothing except immediately pass control to a sided class.

 

So far it's worked fine so long as I've stuck to those rules.

 

-TGG

 

 

Link to comment
Share on other sites

Thanks for that explanation - I don't know anything about how Java actually compiles code (always more to learn...), but that makes sense if using reflection causes a deeper analysis of a class. I wonder if it is at all possible to refactor IMessage and SimpleNetworkWrapper to not use reflection? I imagine many people will run into the same crash and have no idea what went wrong, especially coming from previous networking solutions that were less tricky to use :\

 

Thanks again.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.