jeudi 30 novembre 2023

Java design pattern for mod system(Minecraft mcp)

i'm coding a minecraft client at the moment but I don't know how to write efficient a modular mod system.

Until now I have one superclass called mod and subclasses with the implementation in it and one ModManager class with an ArrayList mods but when I want to get a Attribute from example Mod1 I can't get it like ModManager.getMods().get(Index).attributeName because it's not in Mod. At the Moment I coded it so that these attribute are public static but I think thats not a solution? Is there a better design Pattern or way to implement it?

//Superclass 
package Client.Mods;

import net.minecraft.client.Minecraft;

public class Mod {
    protected Minecraft minecraft;
    private static ModCategory category;
    private static String name = "NoName ERROR";
    private static boolean toggled;


    public Mod(String name, ModCategory category) {
        this.name = name;
        this.category = category;
        toggled = false;
    }

    public void toggle() {
        toggled = !toggled;
        if(toggled)
            onEnable();
        else
            onDisable();
    }

    public void onEnable() {

    }

    public void onDisable() {

    }

    public void onUpdate() {

    }

    public void onRender() {

    }

    public static String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static boolean isToggled() {
        return toggled;
    }

    public void setToggled(boolean toggled) {
        this.toggled = toggled;
    }
}

package Client.Mods;

import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;

public class BetterBowParticles extends Mod{

    public static SimpleParticleType particleType = ParticleTypes.CRIT;

    public BetterBowParticles(String name, ModCategory category) {
        super(name, category);
        particleType = ParticleTypes.ASH;
    }

    public void onRender() {

    }
}

Aucun commentaire:

Enregistrer un commentaire