Classy
Classy 是一个用于高度自定义访问类和技能系统的库。它仅包含注册类与技能、施法交互以及装备类的各种方法。其余所有功能均由开发者基于此依赖项自行实现。
Classes(类)
类的设计旨在满足各种用例的扩展需求。虽然可以同时装备多个类,但具体允许的最大装备数量取决于你编写的选择代码。
注册一个类
注册类非常简单,就像注册其他任何对象一样。只需执行以下操作:
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(
// 技能将在此处添加。
)
));
public static void init() {
CLASSES.register();
}
Classy 在模组中内置了一个命令,以便快速装备类进行测试。只需运行 /classy class [id] 即可装备或卸下该类。
Abilities(技能)
技能本身非常基础,不包含冷却时间或法力条。技能仅作为与类关联的系统存在。选择哪个技能进行施放也由你自己的代码决定,支持通过索引或标识符进行施放。构建技能的其余部分则相对复杂。
一个极其基础的技能可以这样编写:
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;
}
}
该技能的作用是对施法玩家造成半颗心的仙人掌伤害。
如果你需要更复杂的交互,例如触发客户端玩家动画或持有型技能,可以使用以下方法和字段:
// 一个在施放时播放酷炫玩家动画的技能。
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;
}
}
// 一个需要蓄力的持有型技能,根据持有时间的长短赋予等效于速度 I 的效果。
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()); // 当不再施放技能时停用
}
@Override
public void serverEnd(ServerPlayer player) {
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, heldTimer, 0));
}
@Override
public boolean canCast(Player player) {
return true;
}
}
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!
下载 Classy!
下载 Classy!
下载 Classy!
下载 Classy!
下载 Classy!
下载 Classy!
下载 Classy!
下载 Classy!
未指定更新日志。
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
添加区块认领和玩家组队功能,并与 Xaero's Minimap 和 World Map 集成
评论 0
登录后参与评分
还没有评论,来抢沙发吧