Jump to content

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


Recommended Posts

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.

Posted

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

Posted

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;
	}

}

}

 

 

 

Posted

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);

Posted

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...

Posted

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.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yep I did upgrade just because it showed me a new version available.  I'll redownload the mod list and make sure anything works.  Thanks!
    • The latest log was taken down by pastebin for some reason. Did you try removing the mods you added? The mods you updated, was there a specific reason you updated, or just because? It's possible the updates introduced incompatibilitie, or even need a newer build of forge. If you didn't need the updates for a specific reason, you could also try downgrading those mods.
    • Please read the FAQ, and post logs as described there. https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/
    • I am using forge 1.20.1 (version 47.3.0). My pc has an RTX 4080 super and an i9 14900 KF, I am on the latest Nvidia graphics driver, latest windows 10 software, I have java 23, forge 1.12.2 works and so does all vanilla versions but for some reason no version of forge 1.20.1 works and instead the game just crashes with the error code "-1." I have no mods in my mods fodler, I have deleted my options.txt and forge.cfg files in case my settings were causing a crash and have tried removing my forge version from the installations folder and reinstalling but no matter what I still crash with the same code and my log doesn't tell me anything: 18:34:53.924 game 2025-02-06 18:34:53,914 main WARN Advanced terminal features are not available in this environment 18:34:54.023 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, mrmirchi, --version, 1.20.1-forge-47.3.0, --gameDir, C:\Users\aryam\AppData\Roaming\.minecraft, --assetsDir, C:\Users\aryam\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 2db00ea8d678420a8956109a85d90e9d, --accessToken, ????????, --clientId, ZWI3NThkNzMtNmNlZS00MGI5LTgyZTgtYmZkNzcwMTM5MGMx, --xuid, 2535436222989555, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\aryam\AppData\Roaming\.minecraft\quickPlay\java\1738838092785.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.3.0, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] 18:34:54.027 game [18:34:54] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 18:34:54.132 game [18:34:54] [main/INFO] [ne.mi.fm.lo.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow 18:34:54.191 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6 18:34:54.303 game [18:34:54] [main/INFO] [EARLYDISPLAY/]: Requested GL version 4.6 got version 4.6 18:34:54.367 monitor Process Monitor Process crashed with exit code -1     screenshot of log: https://drive.google.com/file/d/1WdkH88H865XErvmIqAKjlg7yrmj8EYy7/view?usp=sharing
    • I am currently working on a big mod, but I'm having trouble with my tabs, I want to find a way to add tabs inside tabs, like how in mrcrayfishes furniture mod, his furniture tab has multiple other sub tabs to them, so i know it is possible but i just don't know how it is possible, any help would be appreciated, thanks
  • Topics

×
×
  • Create New...

Important Information

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