Difference between revisions of "How to Write a Client"

From wiki.vg
Jump to navigation Jump to search
m (→‎Login: 0x0D does not directly follow 0x01)
Line 29: Line 29:
 
* Every 200 milliseconds, send one of 0x0A - 0x0D.
 
* Every 200 milliseconds, send one of 0x0A - 0x0D.
  
To test if this worked, count the number of 0x33 map chunks you get that are full-sized chunks (16,128,16). You should get hundreds.
+
To test if this worked, count the number of 0x33 map chunk messages you get that are full-sized chunks (16,128,16). You should get hundreds.
  
 
If you're not doing it right, you might only see bits and pieces of the map loading really far away, or possibly just one chunk load where you're standing.
 
If you're not doing it right, you might only see bits and pieces of the map loading really far away, or possibly just one chunk load where you're standing.

Revision as of 01:38, 6 February 2011

This tutorial is being created to document what it takes to write a stand-alone client to interact with a notchian server (version Beta 1.2_01). The tutorial is incomplete but will be updated whenever more information is discovered.

Before You Get Started

  • Make sure you don't want to join or fork an existing project instead.
  • Ponder how much work it will be.
  • Download the latest official minecraft server and run it with authentication turned off. Bind it to localhost if you want.

Parsing the messages

Main article: Protocol

Sorry, but you have to be able to parse all the messages. Write all the message parsing code. If you don't, your client will effectively crash if the server sends you any message you can't parse.

Login

Connect to the server at localhost, port 25565.

Main article: Protocol FAQ

Paraphrase (with no authentication): send a 0x02, get a 0x02, send a 0x01, get a 0x01. Then you'll eventually get a 0x0D, and that's when the game really begins.

To test if this worked, connect to your localhost server with the notchian client and see if you can see your custom client appear and float in the air.

Getting the map chunks

You have to convince the server that you deserve to know about all the map chunks that are around you.

  • Every 200 milliseconds, send one of 0x0A - 0x0D.

To test if this worked, count the number of 0x33 map chunk messages you get that are full-sized chunks (16,128,16). You should get hundreds.

If you're not doing it right, you might only see bits and pieces of the map loading really far away, or possibly just one chunk load where you're standing.

Moving around

Send the server updates on your position (0x0A - 0x0D) every 200 milliseconds. This section was written experimenting with sending only 0x0D messages.

The server will mostly keep quiet about your position, which means that your movements are acceptable. If the server sends you your position, it means you've done something wrong. After this happens, it is possible that the server will begin ignoring any future position updates. TODO: how to avoid this situation? Maybe send back identical data like after a login.

The walking animation is automatically sent to other clients when you move around on the ground. The walking animation is not sent when moving straight up and down.

Here are some restrictions you must obey:

  • You cannot move to inside of a solid block.

If you break any of the above rules, the server will send you your corrected position. Corrected positions preserve your on-ground status, even if you were trying to fall through the top of a solid block.

Here are some super-human abilities that are allowed:

  • Flying - move about in the air. Make sure on-ground is false or else you might get stuck to the ground.
  • Walking in the air - walk off a cliff with on-ground set to true. The avatar will continue walking as if there were ground bellow him. Tested over shallow holes and across water at sea level.
  • Teleporting - put yourself anywhere instantly. Tested with a teleport distance of 1000m, which exceeds the bounds of the loaded map. Only tested with on-ground set to false.
  • Moving arbitrarily fast - due to being able to teleport, simply update your position to move as far as you like with each step to move arbitrarily fast.

To test if moving around is working, watch your avatar move around from a notchian client. If your avatar remains still despite your position update messages, then you're doing something wrong. If your avatar seems to be gone completely from the world despite the server sending you reasonable spawn coordinates, it may help to delete the player file: world/players/<playername>.dat. This will cause the server to forget the player was ever logged in and spawn them in a new location. You may need to restart the server after deleting the player file.

TODO: how is fall damage calculated and how to avoid it.

TODO: can you crawl through 1x1 spaces with a stance of < 1m?

TODO: experiment with and document Look stuff.

Digging

TODO: is digging speed limited on the server side?

Placing/using stuff

TODO: can you place blocks from behind walls?

Crafting

TODO

Attacking mobs/players

TODO

Chat

Main article: Chat