mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
Create diamondBlockCustomCraft.js
This commit is contained in:
parent
ef39278f70
commit
b4660e0250
51
examplemods/diamondBlockCustomCraft.js
Normal file
51
examplemods/diamondBlockCustomCraft.js
Normal file
@ -0,0 +1,51 @@
|
||||
(function AddDiamondRecipe() {
|
||||
ModAPI.meta.title("DiamondCraftingRecipeMod");
|
||||
ModAPI.meta.description("Adds a crafting recipe to create diamond blocks from dirt.");
|
||||
|
||||
async function addDiamondRecipe() {
|
||||
await new Promise((res,rej)=>{var x = setInterval(()=>{if(ModAPI.blocks){clearInterval(x);res();}}, 100);})
|
||||
var ObjectClass = ModAPI.reflect.getClassById("java.lang.Object").class;
|
||||
function ToChar(char) {
|
||||
return ModAPI.reflect.getClassById("java.lang.Character").staticMethods.valueOf.method(char[0].charCodeAt(0));
|
||||
}
|
||||
|
||||
// Define the recipe legend to map characters to items
|
||||
var recipeLegend = {
|
||||
"D": {
|
||||
type: "block",
|
||||
id: "dirt" // Using dirt blocks
|
||||
}
|
||||
};
|
||||
|
||||
// Define the crafting grid pattern for the recipe
|
||||
var recipePattern = [
|
||||
"DDD",
|
||||
"DDD",
|
||||
"DDD"
|
||||
];
|
||||
|
||||
// Convert the recipe pattern and legend into the required format
|
||||
var recipeInternal = [];
|
||||
Object.keys(recipeLegend).forEach((key) => {
|
||||
recipeInternal.push(ToChar(key));
|
||||
var ingredient = ModAPI.blocks[recipeLegend[key].id].getRef();
|
||||
recipeInternal.push(ingredient);
|
||||
});
|
||||
|
||||
var recipeContents = recipePattern.flatMap(row => ModAPI.util.str(row));
|
||||
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal));
|
||||
|
||||
// Define the output item as diamond_block
|
||||
var resultItem = ModAPI.reflect.getClassById("net.minecraft.item.ItemStack").constructors[1](ModAPI.blocks["diamond_block"].getRef(), 1);
|
||||
|
||||
|
||||
|
||||
// Register the recipe with CraftingManager
|
||||
var craftingManager = ModAPI.reflect.getClassById("net.minecraft.item.crafting.CraftingManager").staticMethods.getInstance.method();
|
||||
ModAPI.hooks.methods.nmic_CraftingManager_addRecipe(craftingManager, resultItem, recipe);
|
||||
}
|
||||
|
||||
ModAPI.dedicatedServer.appendCode(addDiamondRecipe);
|
||||
|
||||
addDiamondRecipe();
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user