概述
这是一个直接对服务端进度进行操作的 KubeJS 拓展。尽管会写进度的人用不上,不会写的不想用就是了。
以下是一个进度操作示例【2.7.0版本】
Startup 脚本
AdvJSEvents.trigger(event => {
event.create("advjs:get_adv")
// 在这里定义多少匹配,在触发它时就需要匹配多少参数
// 在这个例子中,我们定义了两个匹配
.match(advancement => advancement.getId() == "minecraft:story/smelt_iron")
.match(playerName => playerName == "Dev")
})
Server 脚本
AdvJSEvents.advancement(event => {
const { PREDICATE, TRIGGER } = event;
// 定义触发器实例
const jump5times = TRIGGER.tick(triggerBuilder =>
triggerBuilder.addStat(Stats.JUMP, Stats.CUSTOM, { min: 5 }));
const bred_in_nether = TRIGGER.bredAnimals(triggerBuilder => {
triggerBuilder.setChildByPredicate(PREDICATE.entityFromJson({
stepping_on: {
dimension: "the_nether"
}
}))
});
// AdvJS 自定义触发器的实例
const destroy_dirt = TRIGGER.blockDestroyed(triggerBuilder => triggerBuilder.setBlock("dirt"));
// 你的自定义触发器实例
const get_adv = TRIGGER.custom("advjs:get_adv");
// 创建根进度
const root = event.create("advjs:hell")
.display(displayBuilder => {
displayBuilder.setTitle("AdvancementJS")
displayBuilder.setDescription("Quick example")
displayBuilder.setIcon("diamond")
})
.criteria(criteriaBuilder => criteriaBuilder.add("dirt", destroy_dirt))
// AdvJS 自定义奖励
.rewards(rewardsBuilder => rewardsBuilder.addEffect("absorption", 200));
// 为根进度添加字进度
root.addChild("child1", childBuilder => {
childBuilder
.display(displayBuilder => {
displayBuilder.setTitle(Text.red("Holy"))
displayBuilder.setDescription(Text.red("Hell starts"))
})
.criteria(criteriaBuilder => {
criteriaBuilder.setStrategy(RequirementsStrategy.OR)
criteriaBuilder.add("bred", bred_in_nether)
criteriaBuilder.add("jump", jump5times)
criteriaBuilder.add("get_adv", get_adv)
})
.rewards(rewardsBuilder => {
rewardsBuilder.setRecipes("minecraft:lodestone", "minecraft:brewing_stand")
rewardsBuilder.setExperience(100)
})
.requireParentDone()
});
event.remove({
icon: "minecraft:lava_bucket"
});
event.get("minecraft:story/smelt_iron")
// Apply offset to display
.displayOffset(1, 1, true)
.modifyDisplay(displayBuilder => displayBuilder.setIcon("diamond_pickaxe"))
.addChild("child2", childBuilder => {
childBuilder
.display(displayBuilder => {
displayBuilder.setIcon("recovery_compass")
displayBuilder.setTitle('I will come back!')
displayBuilder.setDescription(Text.green("Good luck"))
displayBuilder.offset(-1, 0)
})
.criteria(criteriaBuilder => criteriaBuilder.add("go_back_to_home", TRIGGER.fromJson({
"trigger": "minecraft:changed_dimension",
"conditions": {
"from": "minecraft:the_end",
"to": "minecraft:overworld"
}
})))
});
})
AdvJSEvents.lock(event => {
event.result("stone_slab", "minecraft:story/smelt_iron");
})
PlayerEvents.advancement(event => {
const player = event.getPlayer();
// 第一个参数用来匹配player predicate,剩下的参数是你定义的匹配
CustomTriggers.of("advjs:get_adv").trigger(player, event.getAdvancement(), player.username)
})
客户端脚本
// 与 Revelationary(EventHorizon) 的联动事件
AdvJSEvents.revelation(event => {
event.onFlush((done, removed, isFirst) => {
event.player.sendSystemMessage(Text.aqua(done.size() + " advancement has done"))
event.player.sendSystemMessage(Text.red(removed.size() + " advancement has removed"))
event.player.sendSystemMessage(Text.green(isFirst ? "Is" : "Isn't" + " first flush"))
})
})
该模组支持热重载
只需在修改完代码后在游戏内输入“/reload”即可
特色
自定义触发器
blockDestroyed: 当玩家破坏一个方块时触发。
playerTouch: 当玩家触碰到一个实体时触发。
bossEvent: 当玩家加入一个Boss战时触发。
increasedKillScore: 当玩家杀死生物时触发,它会检查玩家获得的分数
自定义奖励
addEffect: 要给予的药水效果
自定义条件
displayOffset: 为进度组件配置偏移
requireParentDone: 检查父进度是否已完成,否则该进度不能触发
requireOthersDone: 检查你放入的进度是否全部完成
效果图
添加新进度
修改已有进度