Git Product home page Git Product logo

modtest's Introduction

Modding/Plugin System in Java

Introduction

This is a simple modding/plugin system in Java. It is a proof of concept how it could be done.

This was originally created as a Demo for Home Grown - a Farming Game made by Thinmatrix.

How to use

Implementing the Mod System

Inside the game.modding folder you can see a few files. The ModLoader will load all mods that are inside the mods folder and create, instantiate and initialize them with a reference to the Game object. The GameMod is an interface that every mod has to implement.

Inside the Game class a new ModLoader is created and updated every game cycle.

Creating a Mod

To create a mod you have to create a new class that implements the GameMod interface. Inside the GameMod interface you can see a few methods that you have to implement.

public interface GameMod {
    void init(Game game);
    void update();
}

The init method is called when the mod is loaded and the update method is called every game cycle.

Setting up this project inside your IDE

Since this project uses Maven it already comes with the correct configuration.

The Modders usually don't have access to the source code of the game, so they have to use the Game JAR itself as a dependency.

If they got the JAR they can modify the pom.xml file and change the systemPath of the dependency to the path of the JAR.

    <dependencies>
        <dependency>
            <groupId>me.lebogo</groupId>
            <artifactId>game</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
            <!-- <systemPath>${project.basedir}/../game/target/game-1.0-SNAPSHOT.jar</systemPath> -->
            <systemPath>JAR PATH HERE</systemPath>
        </dependency>
    </dependencies>

Creating a Mod JAR

Creating a Mod JAR is very simple. If you have Maven installed you can just run mvn clean package inside the mod folder and it will create a JAR inside the target folder.

This jar can be copied into the mods folder of the game and it will be loaded automatically.

modtest's People

Contributors

lebogoo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.