Jump to content

Recommended Posts

Posted

Is it possible to get player movement when riding an entity. I have tried to use packets, however after many failed attempts to do so, I am hoping to find another solution. I have a few mobs in my mod that are rideable and I want to be able to control them using key control, rather than the carrot on a stick method. So far that has and will continue to suffice if need be, however I think it would be better to control the mob with keyboard controls rather than the stick. I have seen it done in some older mods that use modloader, a few used forge, but recently I havent seen where any mods are still using that method. Most mods use packets now, and I just dont understand how they work and have, as I said, failed numerous times in trying. So I thought I could just get player movement to control the mobs. Is this possible, and how do I do this.....

Posted

First off, I think you could look into the Minecart. They can get nudged inn a direction along the rail if a player presses movement keys.

 

About packets I assume you have read this: http://www.minecraftforge.net/wiki/Packet_Handling

If that was unclear then take a read below for a walk trough the story of Servers, Clients and packets :)

 

Server and Client

The concept of packets can be hard to grasp at the first try, especially if you read some tech description of what they do but they are rather simple.

In Minecraft you have a Server and a Client. Even if you are playing offline or well single player you are still playing on a server. The difference is that this server is closed to anyone but you and it's running on the same machine as you.

 

The Server is responsible for maintaining the correct state of the game and to update Clients on changes to the game state which are relevant to them.

The Client is responsible for rendering and drawing stuff and to notify the Server of whatever the player is doing, so the Server can take the player's action into consideration.

 

Some stuff should only be done on the Client side, for example everything that has with GUI's and rendering should be client only. The server can't draw anything on the screen, it doesn't even understand the concept of a screen and will crash if told to draw or handle rendering.

 

And some stuff should only be done on the Server side, like the spawning of entities. If you spawn a entity on the client side, the client will see the entity but the entity can't interact with anything and will never be "real" since the server doesn't know of it's existence it's just a ghost entity.

Except for a few things like those mentioned above, server and client will read the same code, if you set a block on the client side and the server side it's okay because they both agree on the block being placed and if you only do it on the server it will inform the client of the change anyways.

 

So wait a second, how does the client tell the server about thing's the player is doing? how does the server inform the client of a newly spawned entity?

The answer is packets!

 

Packets?

Yes and you can think of them as just that, a packet like a gift you send inn the mail for Christmas.

You can put whatever data you want into a packet you have created, and once you are done stuffing things into it you send it.

On the client side you can use this:

player.sendQueue.addToSendQueue(packet);

This would be like putting the packet inn the drop off box for packets at the postal office.

 

Speaking of the postal office, you need to know the region you are sending the packet to.

Or well the "Channel Name" this tells the postal service which region office should handle the packet and normally the channel name will be the one you defined inn the @NetworkMod annotation inn your mod file. You also need to have some unique identifier for the type of packet you are sending, this is typically an int and it's usually the first data into and out of the packet.

 

The Packet Handler is like the region office, it will receive and handle all the packets which belong to your mod.

in the "onPacketData" you check to see that the channel name is the one you are using and then you handle the packet.

The first thing you should do is check which type of packet you have by getting the first int we put into the packet and based upon that the postal office know's how to handle you're packet.

 

If you know the basics of Java and keep inn mind the post office metaphor above while reading the tutorial for packets again, I'm sure you will find that packets aren't that hard to grasp :) If you have trouble with your code after trying this please post the Packet Handler, along with the place you send packets from and any relevant class files to us.

 

PS: Use www.pastebin.com with Syntax Highlightning set to Java when posting code longer than 5 lines!

 

 

If you guys dont get it.. then well ya.. try harder...

Posted

Thank you Mazetar for your reply. Yes I have read the link you posted, but my java knowledge is pretty basic. I have an understanding of how a class is made, what constructors are, and what methods are too. I can read and understand a good bit of java and have some idea of what is happening in the code. I guess my biggest problem is the code in that page is not gear towards what exactly I am trying to do. I have looked in the boat and minecart, but the code there is not real clear and from what I have read in other places, not really that useful as it cant be manipulated to much, if at all. I have added keybinding code to my mobs before, but this only worked on SSP and would crash the game if trying to mount an entity while on the server. I tried to use the linked page to try and add my keybinding code to that, and it was riddled with errors, and after every error I tried to fix, would get more errors. I tried to search for this on github and in bitbucket so I could see if I could find a mod source to look at that does something similar to what I am aiming for, but have found nothing at all. Perhaps you know of a source there I can look at that may be more helpful than the linked page.

 

Ultimately I am trying to eliminate the mobs I created because I have started to mess with Forge Events and am starting to understand them quite well and feel I should be able to get rid of the cow and chicken I created and use an event to handle the mounting of these mobs already in MC and then add the riding code to that in the event. I know how to add the channels and create the packethandler class, but after that it all goes downhill.

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.