Jump to content

Recommended Posts

Posted

I have a car entity and i want to make it possible that more than one person mounts it. To do that i thought of creating a field of Type entitySeat and add new EntitySeats to it in the constructor of the Entity. But once i tried it it didn't even spawn the seats. I registered all the entities in the correct place and order with different id's, but it wouldn't work. Also i think ill need somebody to help me with the packetHandling for the driving mechanizm. Im thinking of a packet that takes in the id of the pressed key and sends it to the Server. On the server the entity in which the player of that message is sitting, should do the movement stuff, but i can't figure out how to excactly do it. So - here is the EntityClass and the ItemClass that spawns it:

EntityClass:

 

  Reveal hidden contents

 

 

ItemClass(Its generated in code, thats why it is not public):

 

  Reveal hidden contents

 

 

Posted

Let's begin with problems:

 

  On 8/23/2015 at 4:21 PM, ItsAMysteriousOfficial said:

 
  if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
  if (Keyboard.isKeyDown(Keyboard.KEY_D) ) {
  if(Keyboard.isKeyDown(Keyboard.KEY_W)){
  if(Keyboard.isKeyDown(Keyboard.KEY_S)){
  if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){

Wow... Apearenly you really don't know that there's no keyboard on server...

 

  Quote

  
      if (Keyboard.isKeyDown(Keyboard.KEY_RETURN)) {
         if(worldObj.isRemote)
         RealLifeMod.network.sendToServer(new MountVehicleMessage(this));
      }

Really? First you check for key press and then you check for client...

 

  Quote

 
                  Minecraft.getMinecraft().objectMouseOver.getBlockPos().getX(),
                  Minecraft.getMinecraft().objectMouseOver.getBlockPos().getY(),
                  Minecraft.getMinecraft().objectMouseOver.getBlockPos().getZ())

Seriously? You have onItemUse, and you use this???

 

In total, you need to

-Know what is server stuff and what is client stuff... Go and learn it RIGHT NOW!

-Know how to use packets... No, seriously, until you learn packets good enough do not try to do client server sync needed stuff... Plenty o tutorials...

-Know what key handler is and how to use it... Again, Plenty o tutorials...

 

 

Posted
  On 8/24/2015 at 8:31 AM, ItsAMysteriousOfficial said:

Yea, omg why did i check the key first am i stupid? And can't i just check if its client and then simulate the movement on client(eg with other variables) and send it to the server with a packet?

Bad idea - opens big doors to cheaters... You should send packets to server describing which action user wants to perform (send packet each time key state changes and not each tick while it's pressed)... Also, i highly recomend making keys configurable using key handler (so don't send key W pressed, but check if move froward key has changed and then send packet to server saying that move forward state changed)...

Posted
  On 8/24/2015 at 12:46 PM, ItsAMysteriousOfficial said:

Okay, so is it smart to create a packet taking in the keys id and the entity and then in the packethandler it updates the position?

Better would be to send where player wants to go and check for key presses per client. Like that, if players use arrow keys instead of WASD to move, they will be able to configure it personally.

Also, no need to send player or vehicle: from context of message (that you get in your handler along with message), you can get player that sent that message. And from player you can get entity it's riding or entity it's ridden by...

Then best option would be to create directional fields in tile entity and change those from packet. Then depending on those fields, in update method, you move your entity...

Oh and last thing: on client before sending a packet, check that player rides your entity, to save performance :) ...

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.