Skip to content

Instantly share code, notes, and snippets.

@dadencukillia
Last active April 21, 2024 19:24
Show Gist options
  • Save dadencukillia/006473a91295191963596ab21f9d3b8b to your computer and use it in GitHub Desktop.
Save dadencukillia/006473a91295191963596ab21f9d3b8b to your computer and use it in GitHub Desktop.

What is HttpInfoServer?

This is a project that consists of two parts: HttpInfoServer (hereinafter referred to as the "server part") and HttpInfoServer-mod (hereinafter referred to as the "mod part"). Both of these parts are important and necessary for correct operation. By combining them, you will create a REST API server based on the HTTP protocol that will collect and send up-to-date information about the player's state in the Minecraft game.

IMPORTANT INFORMATION: The mod part uses the Fabric Mod Loader to work, if you are not a Fabric fan, then this project is not for you.

Who is it for?

It is primarily intended for developers who want to create their own application that needs information about the status of a Minecraft player. It is forbidden to use the project to create cheats and track players without their consent. So, with that said, here is an example of projects you can create using HttpInfoServer:

  • A table lamp that synchronizes with the lighting from the game.
  • A program with a GUI interface that shows information about the players you play with on the same server.
  • An Arduino project that performs an action depending on the object the player is holding.
  • And much more, the possibilities increase with each new version of Minecraft and the project.

How to use?

Downloading the necessary files and setting up

As mentioned earlier, the project consists of two parts. Therefore, for the project to work properly, we need to download the files of the two parts. Let's start with the mod part.

The mod part

For its correct implementation, we need to download and install the Fabric Loader client. You can do this by going to the website at link and downloading the installer. In the installer, don't forget to select the required version of Minecraft (don't forget to additionally check if we have created a mod for this version). When you install the Fabric Loader client, the "mods" folder should appear in the Minecraft data folder (otherwise, create this folder yourself). The "mods" folder stores mods, where we will need to put the file of our mod, which we will download in the next step.

Go to link and select and click on the required version of Minecraft from the list for which you downloaded the Fabric Loader client. You should see a list of data that can be retrieved from the server's REST API. Yes, the data that the client will receive from the REST API server depends on the mod. So, scrolling down a little bit, you can find a link to a file that will look something like "httpinfoserver-X.X.X.jar", click on it and place the downloaded file in the "mods" folder.

After all the operations in your Minecraft launcher, do not forget to change the version of the game to the modded version, which usually has the word "fabric" in its name.

The server part

Click link and select the most recent version from the list (preferably the word "release" in the version name). Before you will be links to files that will be called something like this: "darwin_arm64"," "linux_amd64"," win_amd64.exe". The file selection will depend on your operating system. Most likely your operating system is Windows, if so, then download a file called "win_amd64". If your operating system is MacOS, then download "darwin_arm64". If you use an operating system based on Linux, then select the file "linux_amd64". To start the HTTP Rest API server, run the downloaded file.

Start the server

We recommend that you first run the downloaded file from the server part section, and then a modified version of minecraft. After starting the first one, if successful, you will see the following messages in the console: "WebSocket server started!" and "HTTP Server started on 8000 port (URL: http://127.0.0.1:8000)," It is important to note that the console should remain open in the future and its closure indicates an error. After Minecraft launches, a similar message should appear in the server console: "player name connected." From this moment we can say that everything works correctly.

Use REST API

REST API will work at http://127.0.0.1:8000 and you can send GET requests there. However, how do you make a functional client that does not know the existing endpoints? The following endpoints will be available in the REST API server:

  • /users returns JSON a list of nicknames of connected Minecraft clients.
  • /user/{player's name} returns a JSON object with information about the player whose nickname you specify in the path.

Of course, you can experimentally find out the format of the data that the server returns, but if you are familiar with TypeScript, then you can follow this link TypeScript Response Schema to look at the data format. Don't forget that it also depends on the mod version, but the link will be updated and show the data format for the latest mod version.

Support

Problem or suggestion

If you have any problems or have any suggestions, then you can write a comment for this gist, I or other users will answer your comment.

Found a bug

If you find a bug, then on GitHub you can report it, you can do it at the following links: Report bug in the server part | Report bug in the mod part.

Contribute

Also, you can help with the development of the project by doing contribution, I will be happy with your edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment