Jump to content

Recommended Posts

Posted

I setup my packet handling using a setup suggested to me by jabelar in this thread http://www.minecraftforge.net/forum/index.php/topic,18804.0.html I really like this setup because its simple and easy to use but I have a problem that I just cant figure out. It works perfectly when sending packets from the server to the client but I cant get it to work the other way (sending packets from the client to the server) This is my setup.

 

Server Packet handler:

 

  Reveal hidden contents

 

Client Packet handler:

 

  Reveal hidden contents

 

Packet:

 

  Reveal hidden contents

 

Common Proxy: (this is where the Server packet handler is registered (removed unrelated code))

 

  Reveal hidden contents

 

Client Proxy: (this is where the Client packet handler is registered (removed unrelated code))

 

  Reveal hidden contents

 

Test code: (I made a basic block and used its "onBlockActivated" method to test the packet handler)

 

  Reveal hidden contents

 

 

After a lot of debugging I think i have tracked down where things go wrong.

From what i understand the "onServerPacker" method is suposed to be called on the server side when the server receives a a packet. But unless "World world = Minecraft.getMinecraft().theWorld;" dosnt work properly in this method "onServerPacket" is being called Client side instead of server side So the packet is being sent from, received and processed all on the client side and never actually reaches the server.

 

@jabelar From what I could tell from your posts in the other thread you havent started using this system to send data to the server yet. So have you tested it it works both ways? 

I am the author of Draconic Evolution

Posted

I use a different packet system, which seems complicated at first glance, but it's actually pretty easy to setup and use:

https://github.com/SanAndreasP/SAPManagerPack/tree/master/java/de/sanandrew/core/manpack/mod/packet

https://github.com/SanAndreasP/SAPManagerPack/blob/master/java/de/sanandrew/core/manpack/mod/ModCntManPack.java

 

You basically use the IPacket interface and implement it in your custom packet class.

The ChannelHandler is registered in the mod class and everytime you send a packet, you reference it.

 

Here's an example for this:

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffplus/registry/ESPModRegistry.java

# line 82: instantiate the ChannelHandler (you can also do this in the preInit, it doesn't matter where, but not on init / postInit)

# line 121 - 125: register your custom packet classes (always after you've instantated the handler of course)

# line 153: initialise the channelHandler

# line 161: postInitialise the channelHandler

 

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffplus/packet/PacketBCGUIAction.java

# example for a packet class

 

https://github.com/SanAndreasP/EnderStuffPlus/blob/master/java/de/sanandrew/mods/enderstuffplus/client/gui/BiomeChanger/GuiBiomeChangerBase.java#L46-L47

# example for sending the packet (lines are marked yellow)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Thanks but i am already very familiar with the system i have set up now so i will wait for jabelar to reply. Buy if i cant get my current system working i will definitely look into yours.

 

Edit: I am now more confused then ever... I noticed it seemed like two packets were being received by the server packet handler (on the client side) so i disabled the server packet handler (by not registering it) but the onServerPacket method in the server packet handler is still being called its as if i have registered a second server packet handler somewhere. 

I am the author of Draconic Evolution

Posted

ok but i still know the packet isnt getting to the server because i was originally trying to use it to send a button packet from a gui to a tile but the tile was only reviving the packet on the client side.

 

Edit: Oh i am also using Minecraft.getMinecraft().theWorld my processPacketOnServerSide method to get the player which i use to get the container which i use to get the tile...

I am the author of Draconic Evolution

Posted

Hi brandon, sorry for the delay -- I had a crazy day yesterday.

 

As you mentioned, I've been concentrating on sending from server to client as I'm mostly using it to control entity animations based on AI states.

 

But at a glance, like what some others say above, I think you're using some methods that are not appropriate to the server side.

 

I'm pretty sure the Minecraft.getMinecraft(). type methods aren't right for the server side.  I think what you need to do is your server packet needs to have information on the player, use that on server side to to look up the player and get the world they're on, then you're off and running.

 

I'll look at it when I get home -- in a few hours.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Ok so maby it is actually working properly but im just not using it properly. The following is my code for receiving a gui button packet.

World theWorld = Minecraft.getMinecraft().theWorld;

switch (packetTypeID) {
case packetTypeIDButton: {
	byte buttonId = bbis.readByte();
	int playerId = bbis.readInt();
	EntityPlayer player = (EntityPlayer) theWorld.getEntityByID(playerId); 
	Container container = player.openContainer;
	if (container != null && container instanceof ContainerWeatherController){
		TileWeatherController tileWC = ((ContainerWeatherController) container).getTileWC();

		tileWC.reciveButtonEvent(buttonId);
	}
	break;
}	
}

(the complete code is in my original post)

so if "theWorld" only exists on the client side then the tile i eventially get from it must also only be on the client side. So how can i get the tile on the server side?

 

Edit: you just beat me! I am currently sending the entityId of the player and using theWorld.getEntityById() which obviously isnt working so how else can i do it?

 

 

 

I am the author of Draconic Evolution

Posted

If you look closer i have the test block set up to send both ways if the player right clicks it it sends a packet from the server to the client but if the player shift-right clicks it it sends a packet from the client to the server.

I am the author of Draconic Evolution

Posted
  On 5/6/2014 at 9:09 PM, GotoLink said:

The ServerCustomPacketEvent has "handler" field, which you can cast to NetHandlerPlayServer, and from it, get the player entity.

 

Yeah, perfect.

 

Brandon, events usually pass world and player to you.  Always good to check the fields and methods of the event to use them well.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 5/6/2014 at 9:10 PM, brandon3055 said:

If you look closer i have the test block set up to send both ways if the player right clicks it it sends a packet from the server to the client but if the player shift-right clicks it it sends a packet from the client to the server.

 

Oh right, I didn't scroll down and only saw the one method. 

 

I would suggest that you put in a bunch more System.out.println() statements to help you follow the flow of the code.  For example, inside each if block, so you can see if it is testing true and such.

 

I also tend to keep the conditions simple at first -- do you really need to be sneaking for the packet to be sent (for test purposes)?

 

Anyway, with a bunch of println() statements you can follow every hop of the code and see where it is failing.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 5/6/2014 at 9:11 PM, jabelar said:

  Quote

The ServerCustomPacketEvent has "handler" field, which you can cast to NetHandlerPlayServer, and from it, get the player entity.

 

Yeah, perfect.

 

Brandon, events usually pass world and player to you.  Always good to check the fields and methods of the event to use them well.

 

I have been trying to figure it out GotoLink told me how to get the player from the event but how can i get the world? it may come in handy.

 

Edit: I think i figured it out you have to get the player from the event then get the world from the player

 

World world = ((NetHandlerPlayServer) event.handler).playerEntity.worldObj;

 

I am the author of Draconic Evolution

Posted

I just run into one more problem... I just tested it in multiplayer and... It dosnt work I havent done any debugging yet but any idea why it isnt working in multiplayer?

 

Edit: More specifically packets sent from the client to the server don't seem to get through and sending packets from the server to the client crashes the server.

 

"ava.lang.NoClassDefFoundError:" @ Tolkienaddon.channel.sendToAll(PacketTolkienaddon.createTestPacket((byte)42));

 

Full crash log

 

  Reveal hidden contents

 

I am the author of Draconic Evolution

Posted

After learning how to run two separate consoles in eclipse and a lot more debugging i think i am getting closer to figuring out the problem.

 

First off there was a problem with the server packet handler that was preventing the packets from being read

I had to change

if (channelName == Tolkienaddon.networkChannelName)

to

if (channelName.equals(Tolkienaddon.networkChannelName))

The client packet handler was the same but for some reason it wasnt causing any problems (packets where getting through)

 

And that's where the problem is. When the server tries to ether read or send a packet it crashes.

Logs:

Sending from client to server:

#####Client#####

[DEBUG]TestBlock: Send packet from Client

[DEBUG]PacketTolkienaddon: createTestPacket

 

#####Server#####

[DEBUG]ServerPacketHandler: onServerPacket channel = tolkienaddon Looking for: tolkienaddon

[DEBUG]ServerPacketHandler: Channel Name is correct

[03:37:38] [server thread/ERROR] [FML]: NetworkEventFiringHandler exception

 

rest of crash log:

 

  Reveal hidden contents

 

It crashed at PacketTolkienaddon.processPacketOnServerSide(event, event.packet.payload(), event.packet.getTarget());

 

Sending from server to client:

#####Server#####

[DEBUG]TestBlock: Send packet from Server

[03:48:14] [server thread/ERROR]: Encountered an unexpected exception

 

rest of the crash log:

 

  Reveal hidden contents

 

it crashes at Tolkienaddon.channel.sendToAll(PacketTolkienaddon.createTestPacket((byte)42));

 

I cant figure out whats going on any ideas?

 

 

 

I am the author of Draconic Evolution

Posted

Sorry you're having continued trouble.  Things like the .equals() versus == are often tricky to find -- I'll have to look at that closer (as you said it worked in other direction).

 

Like before, these type of issues are often very specific to the actual code.  Do you mind reposting your current code, especially for the handlers and for the packet class?

 

Actually the second crash seems to be related to the world object used in your test block's onBlockActivated() mehtod.  Can you post code for that block or at least that method?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Common proxy:

 

  Reveal hidden contents

 

Client proxy:

 

  Reveal hidden contents

 

Server packet handler:

 

  Reveal hidden contents

 

Client packet handler:

 

  Reveal hidden contents

 

Packet:

 

  Reveal hidden contents

 

Test block:

 

  Reveal hidden contents

 

 

Dose it work for you in multiplayer?

I am the author of Draconic Evolution

Posted

I'm at work so can only look at this a little bit and don't have my Forge set up to work with.  I'll look at this more closely when I'm home tonight.

 

I'm looking at the Server to Client case first.  I think it is also interesting that the debug console crashes before it can print out the debug statement from your PacketTolkienaddon.createTestPacket() method.  Basically your onBlockActivated() method calls the method, but it never prints out "[DEBUG]PacketTolkienaddon: createTestPacket".  So the failure seems to be somewhere before the method is actually called. And the crash report indicates that it happens at the time of the call in the testBlock.

 

What happens if you send a packet to a specific player instead?  Anyway, this method is called within the try-catch so it might be interesting to understand if this is a situation where there was a catch -- put a debug println statement into the catch to see if that is the path being taken.

 

Sorry but I haven't tested the multiplayer yet, but will do so when I get home.  Sorry for you having so much trouble -- this is one reason I don't want to write a tutorial until I have it fully formed.  However, I can't see any obvious reason why the general approach shouldn't work, so let's see if it is something simple.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Okay, looking at the first case now, Client to Server

 

That error is a Java language error.  According to an answer at StackOverflow (http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java):

 

  Quote
java.lang.NoClassDefFoundError

 

This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

 

However, a lot of people suggest that it is still most likely a classpath problem.  Were you running this from within Eclipse?

 

Make sure you back up your forge folder before you screw around with fixing up the Eclipse setup. Look up "troubleshoot java NoClassDefFoundError" for some ideas.  It seems that there are ideas like cleaning the project in Eclipse, or someone mentioned the following:

 

  Quote
This seems to be a common error. The solution is to:

 

right-click project

choose properties

choose 'Java Compiler'

unclick the first box saying 'Enable project specific settings'

apply

save

run

Hope this helps in some cases.

 

Some people cleared the workspace and then re-imported their project.

 

Some people recommended doing Project->Clean… in Eclipse.

 

And so on.  In any case, my point is that the error seems to be a serious Java error probably related to project setup.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

1. It I put a debug println in the catch but it wasnt called

2. I tried sending it to the player that clicked the block but it made no difference.

3. As long as we can eventually figure this out I dont mind the trouble at all I have found that in some cases you learn a lot more about how something works when it dosnt work :)

 

Can you give me an estimate as to when you will be able to help more? (when do you finish work?)

 

Edit: you beat me to the post lol

 

Edit2: I tried both in eclipse and i compiled it and tried outside eclipse

 

Edit3: I will try a couple of things and get back to you.

I am the author of Draconic Evolution

Posted

I'm at work for another 4 hours.  But yeah, I'm willing to work through this with you.  I'll probably try to get my own multiplayer packet working independently to see if there is any difference in result.

 

Doing this kinda debug is worthwhile since it will make us better coders in the long run.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.