由於犀牛引擎不支持JavaScript的class對象,所以只能使用function的protoype來建立一個類似於class的function,具體解析如下:
配方Json樣本:
{
"type": "ae2:inscriber",
"mode": "inscribe",
"result": {
"item": "ae2:printed_calculation_processor"
},
"ingredients": {
"top": {
"item": "lazierae2:universal_press"
},
"middle": {
"item": "ae2:certus_quartz_crystal"
}
}
}
代碼:
//AE2的壓印機
function ae2Inscriber() {
//初始化配方主體
this.recipe = {
type: 'ae2:inscriber',
mode: 'press',
result: {},
ingredients: {}
}
}
//定義方法,注意每個方法除了build和replace方法為最終創建方法外,都需要return本身以方便多次調用方法來設置屬性
ae2Inscriber.prototype = {
//更改配方模式
setMode: function (mode) {
this.recipe.mode = mode;
return this;
},
//更改輸出物品
setResult: function (result) {
this.recipe.result = result;
return this;
},
//更改頂部輸入,格式為Ingredient
setIngredientsTop: function (ingredientsTop) {
this.recipe.ingredients.top = ingredientsTop;
return this;
},
//更改中間輸入,格式為Ingredient
setIngredientsMiddle: function (ingredientsMiddle) {
this.recipe.ingredients.middle = ingredientsMiddle;
return this;
},
//更改底部輸入,格式為Ingredient
setIngredientsBottom: function (ingredientsBottom) {
this.recipe.ingredients.bottom = ingredientsBottom;
return this;
},
//如果是shapeless配方怎麼辦?即輸入的Ingredients為一個數組,這裡假設壓印器的ingredients是一個數組
//addIngredients: function (Ingredients) {
//this.recipe.ingredients.push(Ingredients);
// return this;
//},
//Over
//創建配方,需要傳入recipe事件和配方名稱,自動生成配方的ResourceLocation,namespace為預先設置的常量,或者直接改為你需要的字串即可
//可以取消配方名稱設置但是下面的replace方法也要去掉該變數的傳入
build: function (event, recipename) {
event.custom(this.recipe).id(namespace + ':inscriber/' + recipename);
return;
},
//替代配方,先根據配方id刪除配方,然後調用build創建配方
replaceRecipe: function (event, recipeid) {
event.remove({ id: recipeid });
let recipename = recipeid.split(':')[1].split('/').pop();
this.build(event, recipename);
}
};
//上面一個壓印器的builder定義就完成了,以下是調用
onEvent('recipes', event => {
new ae2Inscriber() //在recipes事件內調用builder
.setResult(Item.of('ae2:logic_processor').toJson()) //設置輸出,參數為Ingredient,支持修改數量、NBT等,詳見其他教學,下同
.setMode('press') //設置壓印模式為壓印
.setIngredientsTop(Item.of('ae2:printed_logic_processor').toJson()) //設置頂部輸入為邏輯電路板
.setIngredientsMiddle(Ingredient.of('#forge:ingots/copper').toJson()) //設置中間輸入為標籤:銅錠
.setIngredientsBottom(Item.of('ae2:printed_silicon').toJson()) //設置底部輸入為矽板
.replaceRecipe(event, 'ae2:inscriber/logic_processor'); //調用替代方法,替代原有的配方
});
The MIT License (MIT)
Copyright © 2022-2024 Lumynous
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
A simple docs of Create recipes
Aug 10, 2024Minecraft PVE 攻擊與裝備細節
Jun 3, 2024加裝模組推薦 圖片 各式各樣的連結們 巴哈姆特【模組包】Create: Above and Beyond 動力機械:飛越天際 任務中文化 - StarskyXIII 【密技】如何減少 Create: Above and Beyond 的樂趣 - 腦內模擬 MC百科 [CAB]机械动力:永无止境Create: Above and Beyond
May 12, 2024以下資訊皆以KubeJS最新支援版本、Forge(NeoForge優先,LexForge次要)為主
May 1, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up