跳到正文

Classy!

作者:gdpulsar

A simple class and ability library!

收藏

介绍

中文介绍正在准备中,下面暂时显示原文。

Classy

Classy is a library for highly customizable access to a class and ability system. All it contains are methods for registering classes and abilities, casting interactions, and equipping classes. All else is done by the developer using this dependency.

Classes

Classes are designed to be expandable for every use case. Multiple classes may be equipped at one, but depending on your selection code, you can restrict the maximum number of equipped classes.

Registering a Class

Registering a class is extremely simple, and can be done like registering any other object. Just do the following:

private static final DeferredRegister<PlayerClass> CLASSES = DeferredRegister.create(MOD_ID, PlayerClass.PLAYER_CLASS);

private static final RegistrySupplier<PlayerClass> EXAMPLE_CLASS = registerClass(CLASSES, () -> new PlayerClass(
    ResourceLocation.fromNamespaceAndPath(MOD_ID, "example"),
    List.of(
        // This is where the abilities are added.
    )
));

public static void init() {
    CLASSES.register();
}

Classy has a command built-in to the mod to allow quickly equipping a class to test it. Simply just run /classy class [id] and it will equip or unequip the class.

Abilities

Abilities are very simple, not including cooldowns or a mana bar. Abilities only act as a system that are connected to a class. Choosing the ability to cast is also decided by your own code, allowing casting from index or identifier. Creating the rest of the ability is where it becomes more complicated.

An extremely basic ability can be done like this:

public class ExampleAbility extends PlayerAbility {
    public ExampleAbility() {
        super(ResourceLocation.fromNamespaceAndPath(MOD_ID, "example"));
    }

    @Override
    public void serverCast(ServerPlayer player) {
        player.hurt(player.damageSources().cactus(), 1f);
    }

    @Override
    public boolean canCast(Player player) {
        return true;
    }
}

All this ability will do is apply half a heart of cactus damage to the casting player.

If you would like more complicated interactions, such as triggering clientside player animations or having a held ability, you can use the following methods and fields:

// An ability that plays your cool player animation when cast.
public class ClientAnimationAbility extends PlayerAbility {
    public ClientAnimationAbility() {
        super(ResourceLocation.fromNamespaceAndPath(MOD_ID, "cooler_example"));
    }

    @Override
    public void clientCast(LocalPlayer player) {
        AnimationHandler.playCoolAnimation(player);
    }

    @Override
    public boolean canCast(Player player) {
        return true;
    }
}

// A held ability that charges up, and then gives you Speed I equivalent to how long you held for.
public class HeldAbility extends PlayerAbility {
    public HeldAbility() {
        super(ResourceLocation.fromNamespaceAndPath(MOD_ID, "coolest_example"));
    }

    int heldTimer = 0;

    @Override
    public void serverCast(ServerPlayer player) {
        heldTimer = 0;
        this.setActive(true);
    }

    @Override
    public void serverTick(ServerPlayer player) {
        heldTimer++;
        this.setActive(player.classy$isCasting()); // deactivate when no longer casting the ability
    }

    @Override
    public void serverEnd(ServerPlayer player) {
        player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, heldTimer, 0));
    }

    @Override
    public boolean canCast(Player player) {
        return true;
    }
}

常见问题

Classy! 支持哪些 Minecraft 版本?

Classy! 支持 Minecraft Java 版 1.21.1,可用的加载器:Fabric / NeoForge。下载时注意选择和你游戏版本一致的文件。

Classy! 怎么安装?

先用 PCL2 或 HMCL 启动器安装对应版本的 Fabric / NeoForge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。运行环境:客户端和服务端都要装。

评论

登录后评论和评分

gdpulsar 的其他作品

查看全部 →