Startup Examples
下面的所有代码都需要在 startup_scripts
目录下才能工作。
事件具体的类型可以参考 types/TaCZStartupEvents.d.ts
。
下面的代码使用 CC0 1.0 授权,你可以随意使用它们。
修改枪械/配件定义
IMPORTANT
TaCZStartupEvents.*IndexLoad
API 为 1.3.0 以前的旧 API, 在 1.3.0 及以后的版本建议使用更加灵活的 TaCZServerEvents.*IndexLoad
作为替代。
js
TaCZStartupEvents.gunIndexLoad((event) => {
const id = event.getId().toString();
// 修改 p90 的枪械类型为 `rifle`(步枪)
if (id === "tacz:p90") {
const json = JSON.parse(event.getStdJson());
json.type = "rifle";
return event.setJson(JSON.stringify(json));
}
// 删除 黄金沙漠之鹰
if (id === "tacz:deagle_golden") {
return event.removeGun();
}
});
TaCZStartupEvents.ammoIndexLoad((event) => {
const id = event.getId().toString();
// 修改 火箭弹 的堆叠数量为 33
if (id === "tacz:rpg_rocket") {
const json = JSON.parse(event.getStdJson());
json.stack_size = 33;
return event.setJson(JSON.stringify(json));
}
});
TaCZStartupEvents.attachmentIndexLoad((event) => {
const id = event.getId().toString();
// 删除 狙击弹药扩容弹匣3
if (id === "tacz:sniper_extended_mag_3") {
return event.removeAttachment();
}
});
修改枪械/配件数据
IMPORTANT
TaCZStartupEvents.*DataLoad
API 为 1.3.0 以前的旧 API, 在 1.3.0 及以后的版本建议使用更加灵活的 TaCZServerEvents.*DataLoad
作为替代。
js
TaCZStartupEvents.gunDataLoad((event) => {
const id = event.getId().toString();
// 修改 p90 的弹药数量为 123
if (id === "tacz:p90_data") {
const json = JSON.parse(event.getStdJson());
json.ammo_amount = 123;
return event.setJson(JSON.stringify(json));
}
// 修改 黄金沙漠之鹰 的伤害为 999
if (id === "tacz:deagle_golden_data") {
const json = JSON.parse(event.getStdJson());
json.bullet.extra_damage.damage_adjust = [
{ distance: 18, damage: 999 },
{ distance: 36, damage: 999 },
{ distance: 55, damage: 999 },
{ distance: "infinite", damage: 999 },
];
return event.setJson(JSON.stringify(json));
}
});
TaCZStartupEvents.attachmentDataLoad((event) => {
const id = event.getId().toString();
// 修改 克苏鲁K7制退器, 装备后会拥有 10 倍的垂直后坐力👍
if (id === "tacz:muzzle_brake_cthulhu_data") {
const json = JSON.parse(event.getStdJson());
json.recoil.pitch = { multiplier: 10 };
return event.setJson(JSON.stringify(json));
}
});
添加、修改、移除枪械工作台配方
WARNING
旧版的配方修改,新版本建议使用 KubeJS 的 ServerEvents.recipes
进行配方管理。当前配方修改方法可能会在未来的某个版本移除。
js
// TaCZ 配方加载开始前触发
TaCZStartupEvents.recipeLoadBegin((event) => {
/**
* `event.addRecipe`与`event.putRecipe`的作用都是修改或添加一个配方
* `event.addRecipe`是一个错误的命名
*/
// 添加 p90 的配方
event.putRecipe(
new ResourceLocation("tacz:gun/p90"),
JSON.stringify({
materials: [{ item: { item: "minecraft:oak_button" }, count: 3 }],
result: { type: "gun", id: "tacz:p90", count: 1 },
})
);
// 移除所有配方
// event.removeAllRecipes();
});
// TaCZ 配方加载过程, 每个配方都会触发一次事件
TaCZStartupEvents.recipeLoad((event) => {
const id = event.getId().toString();
// 移除 AA12 的配方
if (id === "tacz:aa12") return event.removeRecipe();
// 移除 762x54 的配方
if (id === "tacz:762x54") return event.removeRecipe();
// 修改 沙漠之鹰 的配方
if (id === "tacz:deagle")
return event.setJson(
JSON.stringify({
materials: [{ item: { item: "minecraft:apple" }, count: 1 }],
result: { type: "gun", id: "tacz:deagle" },
})
);
});
// TaCZ 配方加载结束后触发
TaCZStartupEvents.recipeLoadEnd((event) => {
/**
* `event.addRecipe`与`event.putRecipe`的作用都是修改或添加一个配方
* `event.addRecipe`是一个错误的命名
*/
// 添加 762x54 的配方
event.putRecipe(
new ResourceLocation("tacz:ammo/762x54"),
JSON.stringify({
materials: [{ item: { item: "minecraft:oak_button" }, count: 3 }],
result: { type: "ammo", id: "tacz:762x54", count: 60 },
})
);
// 移除所有配方
// event.removeAllRecipes();
});
赞助 ❤️
喜欢 TaCZ JS
吗?你可以在 爱发电 对我进行赞助,助力模组持续更新!