Jump to content

[1.8] Sending packets


Jedispencer21

Recommended Posts

So what I am trying to do, is I have waypoints and what I would like to do is make it so that a player can share a specified waypoint with a specified player. What I am wondering is what would be the be way to handle this. Also, would this work on servers if the mod is not installed on it?

Link to comment
Share on other sites

How, in the game, would a player specify the recipient of their waypoint? The answer will determine what kind of method you should use.

 

As for servers, I've seen some people still making client-side only mods, but most must be installed on both the server and the client to function properly. Again, the answer really depends on the specifics of your mod.

Link to comment
Share on other sites

Take a look at how private messaging works in the vanilla chat. Data is sent between two players based on a player name the sender specified. Basing it off this, you can send this information about the waypoints to the targeted client utilizing packets containing your data. If I'm not mistaken, everything should be client side (sending to client, GUI, etc.).

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

My waypoints are stored in ArrayLists, so could I make it so when the client receives the packet, it adds a waypoint to the list, and the same for removing shared waypoints? Also there is a message getPlayerEntityByName, could I pass in the player name in a GuiTextField when sharing waypoints, then send a packet to that player, which adds a shared waypoint to the list?

Link to comment
Share on other sites

Sounds like getPlayerEntityByName should be your best bet. Store the name passed in the GUI and pass it in that method. Read and write the list with the qualified waypoints somehow and send that to the PlayerEntity. That should be solid.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

So I have gotten this to work, but it only works on lan servers when the owner of the lan shares it, if anyone who connected to the lan tries to share, it crashes, also crashes on public servers.

Here is the crash:

 

 

[21:05:00] [Client thread/FATAL]: Reported exception thrown!

net.minecraft.util.ReportedException: Updating screen events

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1775) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1088) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_72]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

Caused by: java.lang.NullPointerException

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:95) ~[GuiShareWaypoint.class:?]

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510) ~[GuiScreen.class:?]

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:76) ~[GuiShareWaypoint.class:?]

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606) ~[GuiScreen.class:?]

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572) ~[GuiScreen.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1761) ~[Minecraft.class:?]

... 11 more

[21:05:00] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: ---- Minecraft Crash Report ----

// I'm sorry, Dave.

 

Time: 21/07/15 9:05 PM

Description: Updating screen events

 

java.lang.NullPointerException: Updating screen events

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:95)

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510)

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:76)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1761)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1088)

at net.minecraft.client.Minecraft.run(Minecraft.java:376)

at net.minecraft.client.main.Main.main(Main.java:117)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:95)

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510)

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:76)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572)

 

-- Affected screen --

Details:

Screen name: com.fatefulhud.client.gui.GuiShareWaypoint

 

 

 

Here is the code:

 

 

public class GuiShareWaypoint extends GuiScreen

{

private GuiScreen parentScreen;

private String title;

private Waypoint selectedPoint;

public static GuiTextField nameField;

private EntityPlayer player;

 

public GuiShareWaypoint(GuiScreen parentScreen, Waypoint point)

{

this.parentScreen = parentScreen;

this.selectedPoint = point;

}

 

public void initGui()

{

this.title = Localization.get("hud.shareWaypoint");

this.buttonList.add(new GuiButton(0, this.width / 2 + 5, this.height - 29, 100, 20, Localization.get("gui.cancel")));

this.buttonList.add(new GuiButton(1, this.width / 2 - 105, this.height - 29, 100, 20, Localization.get("gui.confirm")));

this.nameField = new GuiTextField(0, this.fontRendererObj, this.width / 2 - 100, 40, 200, 20);

this.nameField.setFocused(true);

Keyboard.enableRepeatEvents(true);

this.updateConfirmButton();

}

 

public void onGuiClosed()

{

Keyboard.enableRepeatEvents(false);

}

 

protected void keyTyped(char keyTyped, int keyCode) throws IOException

{

if (this.nameField.isFocused())

{

this.nameField.textboxKeyTyped(keyTyped, keyCode);

}

 

this.checkFields();

this.updateConfirmButton();

super.keyTyped(keyTyped, keyCode);

}

 

private void updateConfirmButton()

{

((GuiButton) this.buttonList.get(1)).enabled = this.nameField.getText().length() > 0;

}

 

protected void checkFields()

{

GuiFieldCheck.setText(this.nameField);

}

 

protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException

{

super.mouseClicked(mouseX, mouseY, mouseButton);

this.nameField.mouseClicked(mouseX, mouseY, mouseButton);

}

 

public void updateScreen()

{

this.nameField.updateCursorCounter();

}

 

protected void actionPerformed(GuiButton button) throws IOException

{

if (button.enabled)

{

switch (button.id)

{

case 0:

this.mc.displayGuiScreen(this.parentScreen);

break;

case 1:

this.player = Minecraft.getMinecraft().getIntegratedServer().getConfigurationManager().getPlayerByUsername(this.nameField.getText());

if (player == null)

{

this.mc.displayGuiScreen((GuiScreen) null);

return;

}

HUDPacketHandler.sendTo(new C00ShareWaypoint(this.mc.thePlayer.getDisplayNameString(), this.selectedPoint), (EntityPlayerMP) this.player);

this.mc.displayGuiScreen((GuiScreen) null);

}

}

}

 

public void drawScreen(int mouseX, int mouseY, float partialTicks)

{

this.drawDefaultBackground();

this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 10, 16777215);

this.nameField.drawTextBox();

super.drawScreen(mouseX, mouseY, partialTicks);

}

}

 

 

 

Now what I am assuming is causing it to crash on public servers is the fact that I am getting the player through the integrated server, since I do not know what other good way is to grab the player.

Link to comment
Share on other sites

That's what I was getting at earlier - you can't access the server from the client side. Single player you can fudge around this, but you shouldn't even be trying to access the integrated server from the logical client side, such as from a GUI.

 

To access other players on the server, you have to have code running on the server, and send a packet from you to the server, then from the server to the other player. Or have the server send your GUI a list of players in the world to select from, and then you have a reference to that player.

 

You might be able to get away with trying to fetch the player instance by username (let the player type it into the GUI or something) via mc.theWorld.getPlayerEntityByName. I have never tried using that client side, though, but I'd imagine it must work otherwise you couldn't see other players' names and the like.

Link to comment
Share on other sites

So I have been trying things, but still no success, the closest I had gotten it was before rewriting the sharing code, was to make it so the owner of the lan was able to share it to others, but now thats not even happening, I have no idea how to send the data from a player to the server to another player

Link to comment
Share on other sites

1. Make some trigger (e.g GuiButton)

2. Make Packet Client->Server that will ship data (waypoint?) and the nick of player to be send to.

3. Send that packet from trigger from point 1.

4. Server receives packet, in handler - get EntityPlayer from world's player list (note that if you want multiple world support you need to check all worlds and also ship waypoint's world).

5. From server's handler send next packet with data (waypoint) to found-by-name-player (if found).

6. On other client - handler will read waypoint and add it to its own list.

 

Where is the problem?

You will need 2 packets, 2 handlers, and some trigger (might be even command).

If ther server knows about given's player waypoints - you don't need to send them in client->server packet, but draw them directly from server's data.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

So what I have is a GuiTextField in when the person will enter the players name of which the waypoint will be shared to, so what I have to do is when they press the share/confirm button, it sends a (ShareWaypoint) packet to the server with the sendToServer method, when the server receives the (ShareWaypoint) packet it will send a (RecieveWaypoint) packet with the sendTo method to the player in which the person entered in the GuiTextField. The only problem I have is getting the player, because the only way I have ever accessed the player is through the Minecraft.getMinecraft().thePlayer, but I know that won't work because that is a client player and not a EntityPlayerMP.

Link to comment
Share on other sites

I am still having some crashes, like before, only the owner of the lan can share the waypoint, while when others try to share, it just crashes.

Crash Report:

 

 

[15:44:29] [Client thread/FATAL]: Reported exception thrown!

net.minecraft.util.ReportedException: Updating screen events

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1774) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_72]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_72]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

Caused by: java.lang.NullPointerException

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:94) ~[GuiShareWaypoint.class:?]

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510) ~[GuiScreen.class:?]

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:75) ~[GuiShareWaypoint.class:?]

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606) ~[GuiScreen.class:?]

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572) ~[GuiScreen.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1760) ~[Minecraft.class:?]

... 11 more

[15:44:29] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:663]: ---- Minecraft Crash Report ----

// Uh... Did I do that?

 

Time: 22/07/15 3:44 PM

Description: Updating screen events

 

java.lang.NullPointerException: Updating screen events

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:94)

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510)

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:75)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1760)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1087)

at net.minecraft.client.Minecraft.run(Minecraft.java:376)

at net.minecraft.client.main.Main.main(Main.java:117)

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:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.fatefulhud.client.gui.GuiShareWaypoint.actionPerformed(GuiShareWaypoint.java:94)

at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:510)

at com.fatefulhud.client.gui.GuiShareWaypoint.mouseClicked(GuiShareWaypoint.java:75)

at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606)

at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572)

 

 

 

Here is the code: http://pastebin.com/J0MabeH2

 

I know no one is going to code this for me, I would just like to know where I am going wrong with this.

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



×
×
  • Create New...

Important Information

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