How to create a simple server plugin for Hytale
cd ..

How to create a simple server plugin for Hytale

Introduction

Hytale is a game released in early-access, that have grown considerably in this few months, the game is already on it’s third update and the new one is already coming in the pre-release branch

Now, the history of Hytale is full of twist and turns and it’s pretty caothic as it is, but for the ones that doesn’t know this game yet, here is a little summary of the story

What is Hytale

Hytale developed by Hypixel Studios, has suffered development-hell for at least 7 years, at first with the acquisition of the IP from Riot Games and after that their statement of dropping the game production, and then the “resurrection” thanks to the previous know also known as Simon

Now, the game has reached funding for at least 2 years and probably many to come…

How can i mod Hytale?

Now the question, that everyone is wanderning, is Hytale easy to mod? and the answer is YES. Incredibly easy, in fact so easy that there are two main ways to create mod that are:

Packs are easy to make and can add or modify new items,blocks and particle with custom model, sound and a lot of already implement features, easily accessible from the in-game asset editor that is basically and editor for JSON document with some auto-completition that is always a good sight to see

Plugins in the other hand are written in Java (like minecraft) using a type of paradigm called E.C.S. or Entity-Component-System; We will talk later about this.

Setup

Now, let’s talk about some technicalities. In this post, we will focus on how to create a basic server plugin and the best resources you’ll need for a smooth modding experience.

We will use IntelliJ IDEA for developing this plugin, but you can use whatever editor you prefer. To start, we could generate the Gradle or Maven project and then add the dependencies and other settings. However, the community has already created some excellent Gradle and Maven templates that we can utilize.

The best site for finding guides and all the available resources for developing Hytale plugins is the Hytale Modding website.

And we will use the Gradle template provided by them:

git clone https://github.com/HytaleModding/plugin-template.git MyFirstMod
cd MyFirstMod

And It will generate a basic plugin with all the dependencies and settings already configured, so you can start coding right away, with the fowllowing structure:


/gradle
/src
/.gitignore
/build.gradle.kts
/gradle.properties
/gradlew
/gradlew.bat
/README.md
/settings.gradle.kts

When opened in IntelliJ, it will automatically recognize it as a Gradle project and import all dependencies. You just need to wait for the process to finish, and then you can start coding your plugin.

After that, you can customize the settings.gradle.kts file to set the name, description.

Understending the code

When the project is generated, you will find a src/main/java folder with a ExampleMod.java file, that is the main class of your plugin, and it will look like this:

package dev.hytalemodding;

import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import dev.hytalemodding.commands.ExampleCommand;
import dev.hytalemodding.events.ExampleEvent;

import javax.annotation.Nonnull;

public class ExamplePlugin extends JavaPlugin {

    public ExamplePlugin(@Nonnull JavaPluginInit init) {
        super(init);
    }

    @Override
    protected void setup() {
        this.getCommandRegistry().registerCommand(new ExampleCommand("example", "An example command"));
        this.getEventRegistry().registerGlobal(PlayerReadyEvent.class, ExampleEvent::onPlayerReady);
    }
}

As you can see, the main class extends JavaPlugin and it has a constructor that takes a JavaPluginInit object, that is used to initialize the plugin, and a setup method that is called when the plugin is loaded, where you can register your commands and events.

In this case, we are registering a command called example and an event that listens to the PlayerReadyEvent and calls the onPlayerReady method in the ExampleEvent class.

In the ExampleCommand class located in the commands package, we have a very simple command that sends a message to the player when executed:

package dev.hytalemodding.commands;

import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.command.system.CommandContext;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.CompletableFuture;

public class ExampleCommand extends AbstractCommand {

    public ExampleCommand(String name, String description) {
        super(name, description);
    }

    @Nullable
    @Override
    protected CompletableFuture<Void> execute(@Nonnull CommandContext context) {
        context.sendMessage(Message.raw("Hello from ExampleCommand!"));
        return CompletableFuture.completedFuture(null);
    }

}

This was a little introduction to the Hytale modding, in the next post we will talk about how to create a custom item and a custom block, and how to use the asset editor to create custom models and textures for them.

For all other information and resources, you can check the Hytale Modding website, that is the best place to find guides, documentation and all the available resources for developing Hytale plugins.

Have fun modding!