Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.2][SOLVED]Need help setting up my SimpleMessageHandler properly

Featured Replies

Posted

Hey I've been working on this for a week now, searching and reading up on all the posts about this and the tutorials. However I get crashes when I register my custom packets/messages

"net.registerMessage(customPacketHandler.class, customPacket.class, packetId++, Side.SERVER);"

 

From what I read in posts they use the proxies, however I have no idea how to use it, or use it correctly. I can't find any tutorials or read any posts that make sense to me, all I want is to be able to start using custom GUIs to control tileEntities and other information. And so I would like to ask for some kind of example of doing this whole setup, I really would like to get started on this my mod is so backlogged from this.

 

Would anyone be nice enough to show me, how to code "The registering of messages/packets", "Sending the packets/messages", and "receiving these messages/packets in a tileEntity".

 

Also just for references these are the threads I've found and read:

https://gist.github.com/CatDany/4a3df7fcb3c8270cf70b

http://www.minecraftforge.net/forum/index.php/topic,22201.0.html

http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

http://www.minecraftforge.net/forum/index.php/topic,20138.0.html

 

I've tried to understand these and I fail time and time again, and this is my last resort to ask for some kind of visual code example of how to do this. Thanks for any that respond.

What crash does it give you? Your code seems alright.

I don't think you need to use proxies, they work fine to me without them.

 

The way I currently use those packets is by sending messages from server to update client's information when it is changed on server.

Since I know it will always be sync I use the info in my client while rendering Gui without worrying about whether it is sync or not. Although I'm sure you can send request-reply message for the info and render on reply handling

  • Author

Error Message:

 

[03:11:15] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue
[03:11:15] [Client thread/ERROR] [FML]: 
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
FML{7.2.156.1060} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.1.1060.jar) Unloaded->Constructed->Pre-initialized->Initialized
Forge{10.12.1.1060} [Minecraft Forge] (forgeSrc-1.7.2-10.12.1.1060.jar) Unloaded->Constructed->Pre-initialized->Initialized
RoT{1.0} [Rise of Tristram] (bin) Unloaded->Constructed->Pre-initialized->Errored
[03:11:15] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[03:11:15] [Client thread/ERROR] [FML]: Caught exception from RoT
java.lang.IllegalStateException: cannot determine the type of the type parameter 'REQ': class cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper
at io.netty.util.internal.TypeParameterMatcher.fail(TypeParameterMatcher.java:171) ~[TypeParameterMatcher.class:?]
at io.netty.util.internal.TypeParameterMatcher.find0(TypeParameterMatcher.java:165) ~[TypeParameterMatcher.class:?]
at io.netty.util.internal.TypeParameterMatcher.find(TypeParameterMatcher.java:93) ~[TypeParameterMatcher.class:?]
at io.netty.channel.SimpleChannelInboundHandler.<init>(SimpleChannelInboundHandler.java:60) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.SimpleChannelInboundHandler.<init>(SimpleChannelInboundHandler.java:50) ~[simpleChannelInboundHandler.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:85) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:73) ~[simpleNetworkWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:63) ~[simpleNetworkWrapper.class:?]
at ee.rot.Rot.init(Rot.java:76) ~[Rot.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
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:209) ~[LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:188) ~[LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
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:119) [LoadController.class:?]
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:677) [Loader.class:?]
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:268) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:583) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:890) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
---- Minecraft Crash Report ----
// On the bright side, I bought you a teddy bear!

Time: 13/08/14 3:11 AM
Description: Initializing game

java.lang.IllegalStateException: cannot determine the type of the type parameter 'REQ': class cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper
at io.netty.util.internal.TypeParameterMatcher.fail(TypeParameterMatcher.java:171)
at io.netty.util.internal.TypeParameterMatcher.find0(TypeParameterMatcher.java:165)
at io.netty.util.internal.TypeParameterMatcher.find(TypeParameterMatcher.java:93)
at io.netty.channel.SimpleChannelInboundHandler.<init>(SimpleChannelInboundHandler.java:60)
at io.netty.channel.SimpleChannelInboundHandler.<init>(SimpleChannelInboundHandler.java:50)
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.<init>(SimpleChannelHandlerWrapper.java:17)
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.getHandlerWrapper(SimpleNetworkWrapper.java:85)
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.addServerHandlerAfter(SimpleNetworkWrapper.java:73)
at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.registerMessage(SimpleNetworkWrapper.java:63)
at ee.rot.Rot.init(Rot.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:209)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)
at com.google.common.eventbus.EventBus.post(EventBus.java:267)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:677)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:268)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:583)
at net.minecraft.client.Minecraft.run(Minecraft.java:890)
at net.minecraft.client.main.Main.main(Main.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

 

Thinking about it I probably should post my code in case it's just me making one slight error somewhere

 

Main Mod Class:

 

package ee.rot;

import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import ee.rot.blocks.RotBlocks;
import ee.rot.blocks.TileEntityItemGenerator;
import ee.rot.comms.CommonProxy;
import ee.rot.comms.customPacket;
import ee.rot.comms.customPacket.customPacketHandler;
import ee.rot.events.RotEventHandler;
import ee.rot.events.RotStandardEventHandler;
import ee.rot.gui.RotManaGui;
import ee.rot.gui.RotStamGui;
import ee.rot.items.RotItems;

@Mod(modid = Rot.MODID, version = Rot.VERSION, name= Rot.MODNAME)

public class Rot {

@Instance(value = "RoT")
public static Rot instance;

// Says where the client and server 'proxy' code is loaded.
    @SidedProxy(clientSide="ee.rot.comms.ClientProxy", serverSide="ee.rot.comms.CommonProxy")
    public static CommonProxy proxy;
    
    //@NetworkMod(clientSideRequired=true, serverSideRequired=false, channels = {"rot"}, packetHandler = OpenGuiPacket.class)

public static final String MODID = "RoT";
public static final String MODNAME = "Rise of Tristram";
    public static final String VERSION = "1.0";   
    
    public static SimpleNetworkWrapper net;
    private int packetId = 0;   
    
    // Sending packets:
    /*
    MyMod.network.sendToServer(new MyMessage("foobar"));
    MyMod.network.sendTo(new SomeMessage(), somePlayer);
    */
    
    public static CreativeTabs tabRoT = new CreativeTabsRoT("RoT");
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {  	
	GameRegistry.registerTileEntity(TileEntityItemGenerator.class, "itemGenRot");
    	
    	RotBlocks.init();
    	RotBlocks.registerBlocks();
    	
    	RotItems.init();
    	RotItems.registerItems();
    	
    	RotRecipes.init();    
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	//PacketHandler.initPackets();
    	net = NetworkRegistry.INSTANCE.newSimpleChannel("rpcee");
    	net.registerMessage(customPacketHandler.class, customPacket.class, packetId++, Side.SERVER);
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event)
    {
    	MinecraftForge.EVENT_BUS.register(new RotStandardEventHandler());
    	MinecraftForge.EVENT_BUS.register(new RotEventHandler());
    	if (FMLCommonHandler.instance().getEffectiveSide().isClient())MinecraftForge.EVENT_BUS.register(new RotManaGui(Minecraft.getMinecraft()));
    	if (FMLCommonHandler.instance().getEffectiveSide().isClient())MinecraftForge.EVENT_BUS.register(new RotStamGui(Minecraft.getMinecraft()));
    }
}

 

 

Message Class:

 

package ee.rot.comms;

import io.netty.buffer.ByteBuf;
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 customPacket implements IMessage 
{

public String text;

public customPacket()
{

}

public customPacket(String text)
{
	this.text = text;
}

@Override
public void fromBytes(ByteBuf buf) 
{
	text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects
}

@Override
public void toBytes(ByteBuf buf) 
{
	 ByteBufUtils.writeUTF8String(buf, text);
}

public static class customPacketHandler implements IMessageHandler<customPacket, IMessage> 
{

	@Override
	public IMessage onMessage(customPacket message, MessageContext ctx) 
	{
		System.out.println(String.format("Received %s from %s", 
				message.text, 
				ctx.getServerHandler().playerEntity.getDisplayName()));
		return null;
	}

}

}

 

 

 

If your packet handler is in same class as the packet, try register packet and handler like this:

net.registerMessage(customPacket.customPacketHandler.class, customPacket.class, packetId++, Side.SERVER);

This is weird...I tried your customPacket.class and registered it same way as you do in my mod and it doesn't crash at all...

  • Author

Umm I know this is rude, but may I see how you setup your channel and register your messages?

 

Can PM it if you don't wish to make it public. I have no idea why this isn't working for me and I see everyone saying theirs works really makes me wonder what I'm doing lol

I can't figure out why your code doesn't crash my mod but it does yours. Oh, you should check that you are using the latest recommended version of Forge for 1.7.2.

my guess would be hes using a forge version below the network fixs (1122~)

Update forge to latest/rec and try again.

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.