object MinecraftPlugin extends IPlugin with ICustomRecipe with IRecipeSubtypes{ val modID: String = "minecraft" def getMachineRecipes: JCollection[ICustomRecipe] = Seq(this) def getMachineIDs: JCollection[String] = Seq("wb", "bench", "workbench", "furnace") def getSubtypes: JCollection[String] = Seq("shaped", "shapeless", null) def addRecipe(machine: String, subtype: String, recipe: JsonObject) = machine match{ case "wb" | "bench" | "workbench" => addWorkbenchRecipe(subtype, recipe) case "furnace" => addFurnaceRecipe(recipe) } def removeRecipes() = { //TODO Save all custom recipes in the list and remove it here } @throws[AddRecipeException] def check(json: JsonObject, tag: String, recipeType: String) = { if(!json.has(tag)) throw new AddRecipeException("%s recipe don't have %s tag! JSON: %s", recipeType.capitalize, tag, json.toString) } private def addWorkbenchRecipe(subtype: String, recipe: JsonObject) = subtype match{ case "shapeless" => check(recipe, "input", "shapeless") check(recipe, "output", "shapeless") val output: JsonItemStack = RecipeParser.decodeItemStack(recipe.get("output")) if(output == null) throw new AddRecipeException("Shapeless recipe output tag is invalid! JSON: %s", recipe.get("output").toString) if(output.isOredict) throw new AddRecipeException("Shapeless output can't be oredict! JSON: %s", recipe.get("output").toString) val inputs: Array[Object] = RecipeParser.decodeItemStackArray(recipe.get("input")) .map(jis => if(jis.isOredict) jis.getItemName else jis.toItemStack) //TODO Add recipes to reload list GameRegistry.addRecipe(new ShapelessOreRecipe(output.toItemStack, inputs:_*)) case "shaped" => //TODO Decode and add a shaped recipes } private def addFurnaceRecipe(recipe: JsonObject) = { //TODO Find a way to remove recipe for reloading check(recipe, "input", "furnace") check(recipe, "output", "furnace") val in: JsonItemStack = RecipeParser.decodeItemStack(recipe.get("input")) val out: JsonItemStack = RecipeParser.decodeItemStack(recipe.get("output")) if(in == null) throw new AddRecipeException("Furnace recipe input tag is invalid! JSON: %s", recipe.get("output").toString) if(out == null) throw new AddRecipeException("Furnace recipe output tag is invalid! JSON: %s", recipe.get("output").toString) if(in.isOredict) //TODO Furnace recipe CAN be oredict, just add recipe for each type of ore throw new AddRecipeException("Furnace input can't be oredict! JSON: %s", recipe.get("output").toString) if(out.isOredict) throw new AddRecipeException("Furnace output can't be oredict! JSON: %s", recipe.get("output").toString) val xp: Float = if(recipe.has("xp") && recipe.get("xp").isJsonPrimitive && recipe.getAsJsonPrimitive("xp").isNumber) recipe.getAsJsonPrimitive("xp").getAsFloat else 0.0F FurnaceRecipes.smelting().func_151394_a(in.toItemStack, out.toItemStack, xp) } }