Skip to content

Instantly share code, notes, and snippets.

@KisaragiEffective
Created September 29, 2019 13:44
Show Gist options
  • Save KisaragiEffective/934f3ae34b4b5bdffd01ccf2300a0dfe to your computer and use it in GitHub Desktop.
Save KisaragiEffective/934f3ae34b4b5bdffd01ccf2300a0dfe to your computer and use it in GitHub Desktop.
/**
* This script generates all 1.13 vanilla recipes except banner and firework recipes.
* This file is under GPL v3 License.
* THE FILE AUTHOR: [email protected]
*/
import java.io.File
data class Smelt(val result: String, val exp: Double)
fun void(@Suppress("UNUSED_PARAMETER") value: Any?) {
/* dispose the value: do nothing */
}
fun smelting(fileName: String, ingredient: String, result: String = fileName, exp: Double, tickToCook: Int = 200) {
with(File(dest, "$fileName.json")) {
createNewFile()
with(printWriter()) {
println("""
{
"type": "smelting",
"ingredient": {
"item": "minecraft:$ingredient"
},
"result": "minecraft:$result",
"experience": $exp,
"cookingtime": $tickToCook
}
""".trimMargin())
flush()
}
}
}
fun crafting(fileName: String, json: String) {
with(File(dest, "$fileName.json")) {
createNewFile()
with(printWriter()) {
println(json.trimMargin())
flush()
}
}
}
fun shapedCraft(fileName: String, pattern1: String, pattern2: String? = null, pattern3: String? = null,
subst: Map</* Template char -> actual material */ String, String>, result: String = fileName, amount: Int = 1) {
val tab = " "
val dqf = fun(e: String): String {
return '"' + e + '"'
}
val pat = tab + tab + dqf(pattern1) + if (pattern2 != null) {
",\n"
} else {
""
} + if (pattern2 != null) {
tab + tab + dqf(pattern2)
} else {
""
} + if (pattern3 != null) {
",\n"
} else {
""
} + if (pattern3 != null) {
tab + tab + dqf(pattern3)
} else {
""
}
val mapComputed = subst.map {
tab + tab + dqf(it.key) + ": {\n" +
tab + tab + tab + dqf("item") + ": " + "minecraft:${it.value}" + '"' + '\n' +
tab + tab + "}"
}.joinToString(",\n")
crafting(fileName, """
{
"type": "crafting_shaped",
"pattern": [
$pat
],
"key": {
$mapComputed
},
"result": {
"item": "minecraft:$result",
"count": $amount
}
}
""")
}
fun shapelessCraft(fileName: String, vararg ingredients: String, result: String = fileName, amount: Int = 1) {
val t = " " // sp * 8
val computed =
ingredients.joinToString(",\n") { """
|$t{
|$t "item": "minecraft:$it"
|$t}
""".trimMargin()
}
crafting(fileName, """
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
$computed
],
"result": {
"item": "minecraft:$result",
"count": $amount
}
}
""")
}
fun idk() = 0.0
val dest = File("""C:\Users\Obsidian550D\Documents\intellij\glowstone\src\main\resources\builtin\datapack\data\minecraft\recipes\""")
val planks = "planks"
// Mapping
val wood = setOf("oak", "spruce", "birch", "jungle", "acacia", "dark_oak")
val color = setOf(
"white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray",
"cyan", "purple", "blue", "brown", "green", "red", "black"
)
val ore = setOf("coal", "iron_ingot", "golden_ingot", "lapis_lazuli", "redstone_dust", "diamond", "emerald")
val toolRank = mapOf(
planks to "wooden", "stone" to "stone", "iron_ingot" to "iron", "golden_ingot" to "golden",
"diamond" to "diamond"
)
val tools = setOf("axe", "pickaxe", "shovel", "sword", "hoe")
val oreSmelting = mapOf(
"coal_ore" to Smelt("coal", 0.1),
"iron_ore" to Smelt("iron_ingot", 0.7),
"gold_ore" to Smelt("golden_ingot", 1.0),
"lapis_ore" to Smelt("lapis_lazuli", 0.2),
"redstone_ore" to Smelt("redstone_dust", 0.7),
"diamond_ore" to Smelt("diamond", 1.0),
"emerald_ore" to Smelt("emerald", 1.0)
)
val furnaceMap = mapOf(
"cactus" to Smelt("green_dye", idk())
) +
wood.map { Pair("${it}_log", Smelt("charcoal", 0.15)) }.toMap() +
color.map { Pair("${it}_terracotta", Smelt("${it}_glazed_terracotta_", idk())) }
oreSmelting
val dye = mapOf(
"white" to "bone_meal", "orange" to "orange_dye", "magenta" to "magenta_dye", "light_blue" to "light_blue_dye", "yellow" to "yellow_dye",
"lime" to "lime_dye", "pink" to "pink_dye", "gray" to "gray_dye", "light_gray" to "light_gray_dye", "cyan" to "cyan_dye",
"purple" to "purple_dye", "blue" to "lapis_lazuli", "brown" to "cocoa_beans", "green" to "green_dye", "red" to "red_dye", "black" to "ink_sac"
)
val armorIngredients = mapOf("leather" to "leather", "fire" to "chainmail", "iron_ingot" to "iron", "golden_ingot" to "gold", "diamond" to "diamond")
val armors = setOf("helmet", "chestplate", "leggings", "boots")
dest.walk().forEach { it.delete() }
void(dest.mkdirs())
furnaceMap.forEach {
smelting(it.value.result, it.key, exp = it.value.exp)
}
for (kind in wood) {
// planks
with(File(dest, "${kind}_planks.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shapeless",
"ingredients": [
{
"item": "minecraft:${kind}_log"
}
],
"result": {
"item": "minecraft:${kind}_planks",
"count": 4
}
}
""".trimMargin("|"))
flush()
}
}
// slabs
with(File(dest, "${kind}_slab.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"###"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_slab",
"count": 6
}
}
""".trimMargin("|"))
flush()
}
}
// stairs - right side up
with(File(dest, "${kind}_stair_right.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
" #",
" ##",
"###"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_stairs",
"count": 4
}
}
""".trimMargin("|"))
flush()
}
}
// stairs - left side up
with(File(dest, "${kind}_stair_left.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"# ",
"## ",
"###"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_stairs",
"count": 4
}
}
""".trimMargin("|"))
flush()
}
}
// pressure plates
with(File(dest, "${kind}_pressure_plates.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"##"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_pressure_plate",
"count": 1
}
}
""".trimMargin("|"))
flush()
}
}
// fences
with(File(dest, "${kind}_fence.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"#/#",
"#/#"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
},
"/": {
"item": "minecraft:stick"
}
},
"result": {
"item": "minecraft:${kind}_fence",
"count": 3
}
}
""".trimMargin("|"))
flush()
}
}
// fence gates
with(File(dest, "${kind}_fence_gate.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"#/#",
"#/#"
],
"key": {
"#": {
"item": "minecraft:stick"
},
"/": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_fence_gate",
"count": 1
}
}
""".trimMargin("|"))
flush()
}
}
// wooden doors
with(File(dest, "${kind}_door.json")) {
createNewFile()
with(printWriter()) {
println("""
|{
"type": "crafting_shaped",
"pattern": [
"##",
"##",
"##"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_door",
"count": 3
}
}
""".trimMargin("|"))
flush()
}
}
// wooden buttons
with(File(dest, "${kind}_button.json")) {
createNewFile()
with(printWriter()) {
println("""
{
"type": "crafting_shaped",
"pattern": [
"#"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_button",
"count": 1
}
}
""".trimMargin())
flush()
}
}
// wooden boats
with(File(dest, "${kind}_boat.json")) {
createNewFile()
with(printWriter()) {
println("""
{
"type": "crafting_shaped",
"pattern": [
"# #",
"###"
],
"key": {
"#": {
"item": "minecraft:${kind}_planks"
}
},
"result": {
"item": "minecraft:${kind}_boat",
"count": 1
}
}
""".trimMargin())
flush()
}
}
}
println("Generic wood recipes completed")
for (kind in ore) {
// blocks -> ores
with(File(dest, "${kind}_unblock.json")) {
createNewFile()
with(printWriter()) {
println("""
{
"type": "crafting_shapeless",
"ingredients": [
{
"item": "minecraft:${kind}_block"
}
],
"result": {
"item": "minecraft:${kind}",
"count": 1
}
}
""".trimMargin())
flush()
}
}
// blocks <- ores
crafting("${kind}_block", """
{
"type": "crafting_shaped",
"pattern": [
"###",
"###",
"###"
],
"key": {
"#": {
"item": "minecraft:$kind"
}
},
"result": {
"item": "minecraft:${kind}_block",
"count": 1
}
}
""")
}
println("Generic ore recipes completed")
// generic colored things
for (c in color) {
val cur = dye[c] ?: error("Expected key $c in dye mapping.")
shapelessCraft("${c}_wool", "white_wool", cur)
shapedCraft("${c}_terracotta", "###", "#d#", "###", mapOf("#" to "terracotta", "d" to cur), amount = 8)
shapedCraft("${c}_stained_glass", "###", "#d#", "###", mapOf("#" to "glass", "d" to cur), amount = 8)
shapedCraft("${c}_concrete_poweder", "sgs", "gdg", "sgs", mapOf("s" to "sand", "g" to "gravel", "d" to cur))
shapedCraft("${c}_carpet", "##", subst = mapOf("#" to "${c}_wool"), amount = 3)
shapedCraft("${c}_stained_glass_pane", "###", "###", "###", mapOf("#" to "${c}_stained_glass"), amount = 16)
// (re)tain recipes
// FIXME: O(n^2)
for (c2 in color) {
shapelessCraft("${c2}_shulker_box_from_${c}", "shulker_box", cur, result = "${c2}_shulker_box")
}
smelting("${c}_glazed_terracotta", "${c}_terracotta", exp = TODO())
shapedCraft("${c}_bed", "###", "///", subst = mapOf("#" to "${c}_wool", "/" to planks))
shapedCraft("${c}_banner", "###", "###" , " / ", mapOf("#" to "${c}_wool", "/" to "stick"))
}
// dyes (expect green, blue, brown, black, and white)
run {
// red
shapelessCraft("rose_red", "poppy")
shapelessCraft("rose_red", "red_tulip")
shapelessCraft("rose_red", "rose_bush", amount = 2)
}
// tools
for (k in toolRank) {
for (l in tools) {
val r1 = when (l) {
"axe" -> "##"
"pickaxe" -> "###"
"sword" -> "#"
"shovel" -> "#"
"hoe" -> "##"
else -> error("Unknown $l")
}
val r2 = when (l) {
"axe" -> "#/"
"pickaxe" -> " / "
"sword" -> "/"
"shovel" -> "/"
"hoe" -> " /"
else -> error("Unknown $l")
}
val r3 = when (l) {
"axe" -> " /"
"pickaxe" -> " / "
"sword" -> "/"
"shovel" -> "/"
"hoe" -> " /"
else -> error("Unknown $l")
}
shapedCraft(k.value + l, r1, r2, r3, mapOf("#" to k.key, "/" to "stick"))
}
}
// armors
for (k in armorIngredients) {
for (l in armors) {
val r1 = when (l) {
"helmet" -> "###"
"chestplate" -> "# #"
"leggings" -> "###"
"boots" -> "# #"
else -> error("Unknown $l")
}
val r2 = when (l) {
"helmet" -> "# #"
"chestplate" -> "###"
"leggings" -> "# #"
"boots" -> "# #"
else -> error("Unknown $l")
}
val r3 = when (l) {
"helmet" -> null
"chestplate" -> "###"
"leggings" -> "# #"
"boots" -> null
else -> error("Unknown $l")
}
shapedCraft(k.value + l, r1, r2, r3, mapOf("#" to k.key))
}
}
// other recipes
// utilities
shapedCraft("chest", "###", "# #", "###", mapOf("#" to planks))
shapedCraft("crafting_table", "##", "##", subst = mapOf("#" to planks))
shapedCraft("furnace", "###", "# #", "###", mapOf("#" to "cobblestone"))
// items
shapelessCraft("book", "leather", "paper", "paper", "paper")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment