Jump to content

Recommended Posts

Posted

So after several days of being stumped, It's time to ask I guess: I'm not quite sure how to handle packets.

 

I have a Gui Overlay that draws from data in my custom IExtendedEntityProperties, and never updates when connected to a server.

I gathered from googling that the server and client has it's own instance of that or something, so I need to send packets to update the client's.

I followed the tutorial I found here on the forums to setup SimpleNetworkWrapper, and made a message to send the NBT data (http://pastebin.com/sMMePZ7P)

but now... I don't know where to send it from? I tried putting it in the extended player stats class and running it when values change using:

 

 

if (!player.worldObj.isRemote)

{

System.out.println("Sending packet: Player.NBT to EntityPlayerMP player");

PacketPipeline.sendTo(new SyncPlayerPropsPacket(player), (EntityPlayerMP) player);

}

 

 

Which just.. sorta crashes. It prints out the number of mana remaining, and prints that it's sending the packet... and then disconnects.  The server doesn't close, and the client doesn't close but it kicks you from the server with a fatal error.. no more information just "A fatal error has occured, connection is terminated", the server just says player disconnected.. so I don't really know where to go from here or how to fix it.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

Sure thing. The link in the first post is the custom packet itself. Here's everything else that could be relevant?

 

 

Extended Player Stats:

http://pastebin.com/uU8nwVv5

 

Abstract Packet:

http://pastebin.com/rTcrjwjm

 

Packet "Pipeline":

http://pastebin.com/imwkyabx

 

Living Fall Event Handler:

http://pastebin.com/neKFqSyQ

 

Gui Bar:

http://pastebin.com/3qg9DSpC

 

The crash (not very helpful really):

BBS245b.png

 

 

If anything else would help, I can post that too.

 

 

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

I will read your code in just a second.

But before I do that, in your forge folder there is a folder named crash reports. Open that up and post the full crash log here  (in a spoiler ofc)

 

EDIT: Dont use packet pipeline. Use simple network wrapper

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

 

EVEN MORE EDIT: In your living fall event only do the changes on server side. Then send a packet to the client to inform it about the changes. Every change should only be made on server side

 

I Heard you like Edits?: Are you calling PacketPipeline.registerPackets?

Posted

No crash report is being generated as neither the server, or the client actually crash. It's only booting me from the server back to the server selection screen.. to which I can click connect again and do it all over again.

 

Packet Pipeline is a bad name. It actually houses a simple network wrapper instance, I'm not using Netty. Perhaps PacketDispatcher or something would have been a more appropriate name.

 

By server side only, should I only be checking for isRemote / just handling singleplayer and multiplayer separately then?

 

Yes, it's being called in the PreInitializationEvent in the Main class file.

 

 

 

         public static void PreLoad(FMLPreInitializationEvent PreEvent)
{

	SPCreativeTabs.initialiseTabs();

	SPBlocks.mainRegistry();

	SPItems.mainRegistry();

	SPTools.mainRegistry();

	SPArmors.mainRegistry();

	CraftingManager.mainRegistry();

	SPWorldGen.mainRegistry();

	FMLCommonHandler.instance().bus().register(new AchievementHandler());

	SPAchievements.mainRegistry();

	FMLCommonHandler.instance().bus().register(new AchievementHandler());
	MinecraftForge.EVENT_BUS.register(new ExtendedPlayerStatsHandler());
	MinecraftForge.EVENT_BUS.register(new CoreDrillHandler());
	MinecraftForge.EVENT_BUS.register(new SpiralDrillBreakHandler());
	MinecraftForge.EVENT_BUS.register(new LivingFallEvent());

	PacketPipeline.registerPackets();

	proxyServer.registerRenderInfo();
}

 

 

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

Sorry u missunderstood me. What I meant is u dont need ur packet pipeline class, since u can just throw that snw in ur main mod file and call the methods just on him.

U dont need to handle singleplayer and multiplayer separately. Even if you are in singleplayer there will be a server running in the background.

Not quite sure what the error is right now hm

Posted

Ah, I see what you meant after checking the link you posted. Is there any real difference for doing in the main file versus in it's own class? I've been trying to keep the main file as clean as possible.

 

There is an internal server but isn't the difference between EntityPlayer and EntityPlayerMP still there? Or am I perhaps checking the fall itself incorrectly? As of right now if I don't check to see if it's an instance of EntityPlayer I get errors with bats... I may be going about checking the fall damage wrong?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

!

I completely forgot about the FML log!

It definitely has the problem in it.. but I don't quite understand it... it seems I've messed up the packet somehow, it seems to be of type PlayClient and is trying to cast to PlayServer.

 

Error in log:

 

 

[07:29:42] [Client thread/ERROR] [FML/]: SimpleChannelHandlerWrapper exception
java.lang.ClassCastException: net.minecraft.client.network.NetHandlerPlayClient cannot be cast to net.minecraft.network.NetHandlerPlayServer
at cpw.mods.fml.common.network.simpleimpl.MessageContext.getServerHandler(MessageContext.java:36) ~[MessageContext.class:?]
at com.Rohzek.spiralpowermod.ServerProxy.getPlayerEntity(ServerProxy.java:22) ~[serverProxy.class:?]
at com.Rohzek.network.AbstractPacket.onMessage(AbstractPacket.java:111) ~[AbstractPacket.class:?]
at com.Rohzek.network.AbstractPacket$AbstractClientPacket.onMessage(AbstractPacket.java:119) ~[AbstractPacket$AbstractClientPacket.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:101) [simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:77) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) [ej.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.func_78765_e(PlayerControllerMP.java:273) [bje.class:?]
at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1602) [bao.class:?]
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:973) [bao.class:?]
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:898) [bao.class:?]
at net.minecraft.client.main.Main.main(SourceFile:148) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
[07:29:42] [Client thread/ERROR] [FML/]: There was a critical exception handling a packet on channel spiralpowermod
java.lang.ClassCastException: net.minecraft.client.network.NetHandlerPlayClient cannot be cast to net.minecraft.network.NetHandlerPlayServer
at cpw.mods.fml.common.network.simpleimpl.MessageContext.getServerHandler(MessageContext.java:36) ~[MessageContext.class:?]
at com.Rohzek.spiralpowermod.ServerProxy.getPlayerEntity(ServerProxy.java:22) ~[serverProxy.class:?]
at com.Rohzek.network.AbstractPacket.onMessage(AbstractPacket.java:111) ~[AbstractPacket.class:?]
at com.Rohzek.network.AbstractPacket$AbstractClientPacket.onMessage(AbstractPacket.java:119) ~[AbstractPacket$AbstractClientPacket.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:101) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:77) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) [ej.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.func_78765_e(PlayerControllerMP.java:273) [bje.class:?]
at net.minecraft.client.Minecraft.func_71407_l(Minecraft.java:1602) [bao.class:?]
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:973) [bao.class:?]
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:898) [bao.class:?]
at net.minecraft.client.main.Main.main(SourceFile:148) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
[07:29:42] [Client thread/DEBUG] [FML/]: Reverting to frozen data state.

 

 

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

That it does.. but I don't understand why? Packets seem to be quite a bit above me. The two lines it refers to of mine in the error is 111 and 119..

 

119 is a definition of AbstractClientPacket which seems to be sending to client from server as I understand the comments on the tutorial I got it from...

111 is a call to process() which needs a side specified... which it gets from MessageContext... I'm not sure how it gets that...

The message itself is sent with sendTo which is sent from server to client right?

 

I'm not sure where things got flipped.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

 

 

/**
   * Returns a side-appropriate EntityPlayer for use during message handling
  */
public EntityPlayer getPlayerEntity(MessageContext ctx) 
{
return ctx.getServerHandler().playerEntity;
}

 

 

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

I...

Feel so stupid right now.

 

I thought about it for a minute after posting and realized "Shouldn't that be somewhere else too?"

 

I checked in the client proxy and found this:

 

 

@Override
public EntityPlayer getPlayerEntity(MessageContext ctx)
{
return (ctx.side.isClient() ? mc.thePlayer : super.getPlayerEntity(ctx));
}

 

 

 

somehow commented out. Uncommenting it makes it work... sorta...

 

 

 

VDgwysR.png

 

 

 

 

EDIT: Not working as intended exactly... NOW the packet gets sent but only one random player on the server gets their mana drawn from... It's not working individually...

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

Everytime a change happens to the mana amount it runs the sync() function, which has the packet send if it's on a server.

 

https://github.com/Rohzek/SpiralPowerMod/blob/master/main/java/com/Rohzek/player/SPExtendedPlayerStats.java

 

 

 

When I started the server and joined by myself... It worked as intended, figured out by adding a println statement into the livingfallevent and sync functions

[11:06:39] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Rohzek'/316, l='SpiralTEST', x=5.33, y=64.00, z=339.56]
[11:06:39] [server thread/INFO] [sTDOUT/]: [com.Rohzek.handlers.LivingFallEvent:fallingEvent:36]: EntityPlayerMP['Rohzek'/316, l='SpiralTEST', x=5.33, y=64.00, z=339.56] has 46 mana left
[11:06:50] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Rohzek'/316, l='SpiralTEST', x=5.38, y=74.00, z=344.98]

Then he joins and tries and again it works as intended:

[11:09:14] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Ad_the_Red'/6989, l='SpiralTEST', x=-2.22, y=64.00, z=344.01]
[11:09:14] [server thread/INFO] [sTDOUT/]: [com.Rohzek.handlers.LivingFallEvent:fallingEvent:36]: EntityPlayerMP['Ad_the_Red'/6989, l='SpiralTEST', x=-2.22, y=64.00, z=344.01] has 46 mana left
[11:09:26] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Ad_the_Red'/6989, l='SpiralTEST', x=-0.83, y=64.00, z=339.95]

And then the next time I try... it detects my falling damage as intended... but it draws/syncs from his NBT

[11:09:48] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Ad_the_Red'/6989, l='SpiralTEST', x=9.14, y=64.00, z=334.32]
[11:09:48] [server thread/INFO] [sTDOUT/]: [com.Rohzek.handlers.LivingFallEvent:fallingEvent:36]: EntityPlayerMP['Rohzek'/316, l='SpiralTEST', x=-0.22, y=64.00, z=343.33] has 46 mana left
[11:09:56] [server thread/INFO] [sTDOUT/]: [com.Rohzek.player.SPExtendedPlayerStats:sync:157]: Sending packet: Player.NBT to EntityPlayerMP['Ad_the_Red'/6989, l='SpiralTEST', x=8.74, y=65.25, z=349.13]

 

 

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Posted

I will try to pretend that didn't come off as quite rude... Yes I know what static does/is, it was the first thing we learned in the first class in uni. Something slightly more useful would be helpful.. Like "There is only one instance of that class in the game, not one per person" That might actually explain something.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

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.

Announcements



×
×
  • Create New...

Important Information

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