Jump to content

[1.7.10] Gui Overlays and Packets


Rohzek

Recommended Posts

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 .

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

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

!

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 .

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

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

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 .

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

Link to comment
Share on other sites

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 .

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

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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