Jump to content

Packet problem


Asweez

Recommended Posts

So I made a syncSkills packet for my extended player and I am getting this error:

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.10-10.13.2.1230.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.11.jar:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[?:1.7.0_71]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[?:1.7.0_71]
at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.7.0_71]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2585) ~[?:1.7.0_71]
at java.lang.Class.getConstructor0(Class.java:2885) ~[?:1.7.0_71]
at java.lang.Class.newInstance(Class.java:350) ~[?:1.7.0_71]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.instantiate(SimpleNetworkWrapper.java:113) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:106) ~[simpleNetworkWrapper.class:?]
at com.apmods.magicraft.network.MagiNetwork.registerMessageForServer(MagiNetwork.java:31) ~[MagiNetwork.class:?]
at com.apmods.magicraft.network.MagiNetwork.init(MagiNetwork.java:19) ~[MagiNetwork.class:?]
at com.apmods.magicraft.main.MagiCraft.init(MagiCraft.java:40) ~[MagiCraft.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_71]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_71]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.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_71]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_71]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_71]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_71]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) ~[LoadController.class:?]
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:691) ~[Loader.class:?]
... 5 more

 

Here is my code

 

MagiNetwork:

 

package com.apmods.magicraft.network;

import com.apmods.magicraft.main.MagiCraft;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

public class MagiNetwork {
    public static SimpleNetworkWrapper net;
    public static int messages = 0;

    public static void init(){
        net = NetworkRegistry.INSTANCE.newSimpleChannel(MagiCraft.MODID);
        registerMessage(CastSpellPacket.class, CastSpellPacket.SpellMessage.class);
        registerMessage(OpenWandGuiPacket.class, OpenWandGuiPacket.GuiMessage.class);
        registerMessageForClient(SyncSkillsPacket.class, SyncSkillsPacket.SkillsMessage.class);
        registerMessage(LevelUpKnowledgePacket.class, LevelUpKnowledgePacket.KnowledgeMessage.class);
    }

    private static void registerMessage(Class handler, Class message)
    {
        net.registerMessage(handler, message, messages, Side.CLIENT);
        net.registerMessage(handler, message, messages, Side.SERVER);
        messages++;
    }
    private static void registerMessageForServer(Class handler, Class message)
    {
        net.registerMessage(handler, message, messages, Side.SERVER);
        messages++;
    }
    private static void registerMessageForClient(Class handler, Class message)
    {
        net.registerMessage(handler, message, messages, Side.CLIENT);
        messages++;
    }
}

 

 

SyncSkills

 

package com.apmods.magicraft.network;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

import com.apmods.magicraft.extendedplayer.MagiSkills;
import com.apmods.magicraft.network.LevelUpKnowledgePacket.KnowledgeMessage;
import com.apmods.magicraft.network.SyncSkillsPacket.SkillsMessage;

import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class SyncSkillsPacket implements IMessageHandler<SkillsMessage,IMessage>
{

    @Override
    public IMessage onMessage(SkillsMessage message, MessageContext ctx)
    {
        if(ctx.side.isClient())
        {
        	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

            if (player != null)
            {
                int playerX = (int) player.posX;
                int playerY = (int) player.posY;
                int playerZ = (int) player.posZ;
                World world = player.worldObj;
                MagiSkills ext = MagiSkills.get(player);
                ext.loadNBTData(message.data);
            }
            
        }
        return null;
    }

    public static class SkillsMessage implements IMessage
    {
    	private NBTTagCompound data;

        public SkillsMessage()
        {
        }
        public SkillsMessage(EntityPlayer player)
        {
        	MagiSkills ext = MagiSkills.get(player);
        	this.data = new NBTTagCompound();
        	ext.saveNBTData(data);
        }

	@Override
	public void fromBytes(ByteBuf buf) {
		this.data = ByteBufUtils.readTag(buf);
	}

	@Override
	public void toBytes(ByteBuf buf) {
		ByteBufUtils.writeTag(buf, data);
	}

        
    }
}

 

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

The code you posted isn't the code that's crashing because the code that crashes is:

 

    private static void registerMessageForServer(Class handler, Class message)
    {
        net.registerMessage(handler, message, messages, Side.SERVER);
        messages++;
    }

 

Which is being called from init at the line that reads:

        registerMessageForClient(SyncSkillsPacket.class, SyncSkillsPacket.SkillsMessage.class);

 

Note that the method causing the crash says "ForServer" and call says "ForClient."  Something is out of date.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If a packet class or handler is ever instantiated on the Server side, it must not contain any references to vanilla client code at all.

 

For example this will cause your mod to crash on a dedicated server:

        if(ctx.side.isClient())
        {
        	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

Doesn't matter that you've hidden Minecraft inside a check for the Client side - the way the classloader works, it will try to look for Minecraft before executing any code at all.  It doesn't find Minecraft class on the dedicated server, so it throws this error.

 

Looks to me like something similar is happening for one of your classes with EntityClientPlayerMP, which is client-side only.

 

-TGG

 

Link to comment
Share on other sites

You are testing this mod in dedicated server, yeah?

 

That section of code is being run in init, which is before the client and server threads start.  Side.SERVER is the dedicated server, not server thread, that is different.

http://greyminecraftcoder.blogspot.com.au/2013/11/how-forge-starts-up-your-code.html

 

How are you testing this mod / where does the message appear?

 

-TGG

Link to comment
Share on other sites

Wow thanks! That was really helpful. Right now I'm registering that packet in the MagiNetwork whose init method is being called in the initialization event. Should I register that packet in my client proxy?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

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.