Skip to content

Commit

Permalink
VanillaRecipe v4 beta
Browse files Browse the repository at this point in the history
- added addShapedRecipe and addShapelessRecipe methods
- vanilla ids can be written with "minecraft:" namespace
  • Loading branch information
MineExplorer committed Nov 2, 2021
1 parent d26e0fe commit 51e1284
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
2 changes: 2 additions & 0 deletions declarations/VanillaRecipe.d.ts
Expand Up @@ -36,6 +36,8 @@ declare namespace VanillaRecipe {
export function generateJSONRecipe(name: string, obj: any): void;
export function addWorkbenchRecipeFromJSON(obj: RecipeFormat): void;
export function addCraftingRecipe(name: string, obj: RecipeFormat, addToWorkbench?: boolean): void;
export function addShapedRecipe(name: string, obj: RecipeFormat, addToWorkbench?: boolean): void;
export function addShapelessRecipe(name: string, obj: RecipeFormat, addToWorkbench?: boolean): void;
export function deleteRecipe(name: string): void;
export function addStonecutterRecipe(name: string, obj: RecipeFormat): void;
}
23 changes: 19 additions & 4 deletions library/VanillaRecipe.js
Expand Up @@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
};
LIBRARY({
name: "VanillaRecipe",
version: 3,
version: 4,
shared: true,
api: "CoreEngine"
});
Expand Down Expand Up @@ -42,6 +42,7 @@ var VanillaRecipe;
return;
}
behavior_path = path + ("/" + BEHAVIOR_NAME + "/");
//behavior_path = Resources.addRuntimePack("behavior", BEHAVIOR_NAME) + "/";
behavior_recipes_path = behavior_path + "recipes/";
FileTools.mkdir(behavior_recipes_path);
generateManifestJson();
Expand Down Expand Up @@ -109,7 +110,8 @@ var VanillaRecipe;
}
function getNumericID(stringID) {
var stringArray = stringID.split(":");
if (stringArray.length == 1) {
if (stringArray.length == 1 || stringArray[0] == "minecraft") {
stringID = stringArray[stringArray.length - 1];
return VanillaBlockID[stringID] || VanillaItemID[stringID];
}
if (stringArray[0] == "item")
Expand All @@ -127,7 +129,10 @@ var VanillaRecipe;
__isValid__ = false;
return null;
}
return "minecraft:" + nativeConvertNameID(stringID.replace(":", "_"));
var nameID = nativeConvertNameID(stringID.replace(":", "_"));
if (!nameID.startsWith("minecraft:"))
nameID = "minecraft:" + nameID;
return nameID;
}
VanillaRecipe.convertToVanillaID = convertToVanillaID;
function generateBlankFile(recipeName) {
Expand All @@ -142,7 +147,7 @@ var VanillaRecipe;
VanillaRecipe.generateJSONRecipe = generateJSONRecipe;
function addWorkbenchRecipeFromJSON(obj) {
if (Array.isArray(obj.result)) {
Logger.Log("Recipes with multiple output are not supported in modded workbench", "ERROR");
Logger.Log("Recipes with multiple output are not supported in the modded workbench", "ERROR");
return;
}
var result = {
Expand Down Expand Up @@ -212,6 +217,16 @@ var VanillaRecipe;
}
}
VanillaRecipe.addCraftingRecipe = addCraftingRecipe;
function addShapedRecipe(name, obj, addToWorkbench) {
obj.type = "shaped";
addCraftingRecipe(name, obj, addToWorkbench);
}
VanillaRecipe.addShapedRecipe = addShapedRecipe;
function addShapelessRecipe(name, obj, addToWorkbench) {
obj.type = "shapeless";
addCraftingRecipe(name, obj, addToWorkbench);
}
VanillaRecipe.addShapelessRecipe = addShapelessRecipe;
function deleteRecipe(name) {
var recipe = recipes[name];
if (recipe) {
Expand Down
22 changes: 18 additions & 4 deletions source/VanillaRecipe/VanillaRecipe.ts
@@ -1,6 +1,6 @@
LIBRARY({
name: "VanillaRecipe",
version: 3,
version: 4,
shared: true,
api: "CoreEngine"
});
Expand Down Expand Up @@ -42,6 +42,7 @@ namespace VanillaRecipe {
return;
}
behavior_path = path + `/${BEHAVIOR_NAME}/`;
//behavior_path = Resources.addRuntimePack("behavior", BEHAVIOR_NAME) + "/";
behavior_recipes_path = behavior_path + "recipes/";
FileTools.mkdir(behavior_recipes_path);
generateManifestJson();
Expand Down Expand Up @@ -113,7 +114,8 @@ namespace VanillaRecipe {

export function getNumericID(stringID: string): number {
let stringArray = stringID.split(":");
if (stringArray.length == 1) {
if (stringArray.length == 1 || stringArray[0] == "minecraft") {
stringID = stringArray[stringArray.length - 1];
return VanillaBlockID[stringID] || VanillaItemID[stringID];
}
if (stringArray[0] == "item") return ItemID[stringArray[1]];
Expand All @@ -130,7 +132,9 @@ namespace VanillaRecipe {
__isValid__ = false;
return null;
}
return "minecraft:" + nativeConvertNameID(stringID.replace(":", "_"));
let nameID = nativeConvertNameID(stringID.replace(":", "_"));
if (!nameID.startsWith("minecraft:")) nameID = "minecraft:" + nameID;
return nameID;
}

function generateBlankFile(recipeName: string): void {
Expand All @@ -145,7 +149,7 @@ namespace VanillaRecipe {

export function addWorkbenchRecipeFromJSON(obj: RecipeFormat): void {
if (Array.isArray(obj.result)) {
Logger.Log("Recipes with multiple output are not supported in modded workbench", "ERROR");
Logger.Log("Recipes with multiple output are not supported in the modded workbench", "ERROR");
return;
}
var result = {
Expand Down Expand Up @@ -217,6 +221,16 @@ namespace VanillaRecipe {
}
}

export function addShapedRecipe(name: string, obj: RecipeFormat, addToWorkbench?: boolean): void {
obj.type = "shaped";
addCraftingRecipe(name, obj, addToWorkbench);
}

export function addShapelessRecipe(name: string, obj: RecipeFormat, addToWorkbench?: boolean): void {
obj.type = "shapeless";
addCraftingRecipe(name, obj, addToWorkbench);
}

export function deleteRecipe(name: string): void {
let recipe = recipes[name];
if (recipe) {
Expand Down

0 comments on commit 51e1284

Please sign in to comment.