mirror of
https://github.com/eaglerforge/EaglerForgeInjector.git
synced 2025-09-04 19:50:02 +00:00
custom crafting example mod on 1.12
This commit is contained in:
43
examplemods/diamondBlockCustomCraft_112.js
Normal file
43
examplemods/diamondBlockCustomCraft_112.js
Normal file
@@ -0,0 +1,43 @@
|
||||
(function AddDiamondRecipe() {
|
||||
ModAPI.meta.title("DiamondCraftingRecipeMod 1.12");
|
||||
ModAPI.meta.description("Adds a crafting recipe to create diamond blocks from dirt.");
|
||||
|
||||
async function registerRecipe(isServer) {
|
||||
if (isServer) {
|
||||
await new Promise((res, rej) => {
|
||||
ModAPI.addEventListener("bootstrap", res);
|
||||
});
|
||||
}
|
||||
const parseJson = ModAPI.reflect.getClassByName("JSONObject").constructors.findLast(x => x.length === 1);
|
||||
const CraftingManager = ModAPI.reflect.getClassByName("CraftingManager");
|
||||
const CraftingManagerMethods = CraftingManager.staticMethods;
|
||||
const jsonData = parseJson(ModAPI.util.str(`{
|
||||
"type": "crafting_shaped", ${/*/or crafting_shapeless/*/""}
|
||||
"pattern": [
|
||||
"I I",
|
||||
" i ",
|
||||
"iii"
|
||||
],
|
||||
"key": {
|
||||
"I": {
|
||||
"item": "minecraft:dirt",
|
||||
data: 0 ${/*/data param optional!!!/*/""}
|
||||
},
|
||||
"i": {
|
||||
"item": "minecraft:grass",
|
||||
data: 0 ${/*/data param optional!!!/*/""}
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "minecraft:diamond",
|
||||
"data": 0,
|
||||
"count": 4
|
||||
}
|
||||
}`.trim()));
|
||||
const recipeObj = CraftingManagerMethods.func_193376_a.method(jsonData); //convert json to an IRecipe
|
||||
CraftingManagerMethods.func_193379_a.method(ModAPI.util.str("coolrecipeid"), recipeObj); //register recipe under resource location
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(registerRecipe);
|
||||
registerRecipe(false);
|
||||
})();
|
Reference in New Issue
Block a user