Skip to content

imfi-jz/hx-mc-api

Repository files navigation

Haxe Minecraft API

This is an API that will allow you to write plugins for Minecraft in Haxe. At this time "plugins" means, a plugin for a Spigot server. However in the future this might also include forge/fabric.

Here are some pros and cons using this API compared to the official Spigot API:

✅ Pros ❎ Cons
Simple functions / easy to use New API to learn
All Haxe language features Limited features
Automatically multi-threaded (plugins will never lag the server) Requires a loader (included)
Plugin to plugin communication/events Patches to game updates might be delayed
Conditionally compiled debug logs

Installation

Install the haxelib minecraft-api. There is no need to clone/download this repository. To install the library download and install Haxe and run the command haxelib install minecraft-api in a command prompt/terminal.

Plugins written with this API require a special loader to run. Currently there is only a loader for Spigot. Follow the official instructions to install a Spigot server or download it elsewhere. Then download the beforementioned loader and put it in the plugins folder inside your Spigot server.

Usage

Before you can start writing code you need a hxml file that contains instructions for Haxe to compile your code. Create for example build.hxml and add the following content to it:

--library minecraft-api

# If your source code is placed in ./src
--class-path src
# The namespace of your project, example: nl.imfi_jz.api_tutorial
your.full.namespace

The minimum requirement for a Haxe Minecraft plugin to load is a class that implements the Gate interface. Don't forget to add @:keep to it, to allow compilatoin with dead code elimination.

package nl.imfi_jz.api_tutorial;

import nl.imfi_jz.minecraft_api.Gate;

@:keep
class TutorialGate implements Gate {

    public function enable(plugin:Plugin) {
        trace('Hello world!');
    }

    public function disable(plugin:Plugin) {
        trace('Goodbye!');
    }
}

I recommend putting your source code in a folder called src, followed by subfolders of your namespace. For example src/nl/imfi_jz/api_tutorial. In there you would create the file TutorialGate.hx with the above content.

Now you can compile your code with the command haxe build.hxml. Your plugin will appear in the same directory, named HxMcPlugin.jar. Make sure you have the loader jar file in your server's plugin directory. Move your plugin jar file into either the plugins or plugins/HxMcPluginLoader folder.

The plugins/HxMcPluginLoader folder is recommended. Using the plugins folder will cause the server to throw an error because the Haxe plugins do not have a plugin.yml file. However, your plugin will load regardless.

Haxe MC plugin loader destination folder

Haxe MC plugin destination folder

Your plugin should now load and do its thing!

For a more in depth tutorial please watch my introduction video:

Thumbnail

Showcase

Custom Blueprints

Custom Blueprints is a small plugin I made in Haxe that allows players to craft blueprints. Blueprints are a new item that contain a strucuture that can be placed down multiple times at different locations. See it in action in this showcase video:

Thumbnail

Learn more & download the plugin on the Spigot page. Also the source code is publicly available for reference / learning purposes. Feel free to browse around!

Machine learning AI

There is also a in progress plugin I am working which adds machine learning to the monster's AI. The source code for that is currently closed and there is no proper video on it, but there are some clips of a prototype version on my Twitch channel.

Hardcore Lightly

Hardcore Lightly is a simple plugin that makes players lose a portion of their max health each time they die. When a player runs out of hearts, they are put into spectator mode. This way players get punished for dying and have a limited number of lives.

The plugin can be downloaded from Spigot and has its source code publicly available.

Contributions & contact

Currently the loader is closed source. However, feel free to make suggestions for changes/additions on the discussions section. If you run into issues using the API feel free to report the issue or make a pull request on the repository.

This is my first big public project so advice is welcome.

Contact / get support / share your work

Feel free to share things you made using this API. Join my Discord server to easily get in touch or get support. You can also check out the discussions.

QR code to join the Discord

Support

This project is free to use as stated by the license. If you would like to support this project you can donate to the developer.

QR code to donate

License

Apache 2.0 (see LICENSE.txt).