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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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