├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── logo ├── recipe-images-exporter.png └── recipe-images-exporter.xcf ├── src └── main │ ├── resources │ ├── assets │ │ └── recipeimagesexporter │ │ │ └── icon.png │ ├── recipeimagesexporter.mixins.json │ └── fabric.mod.json │ └── kotlin │ └── net │ └── bloople │ └── recipeimagesexporter │ ├── RecipeImageGenerator.kt │ ├── ImageMaskColor.kt │ ├── ItemsData.kt │ ├── GifSequenceWriter.kt │ ├── RecipeImagesExporterMod.kt │ ├── ItemLabelsExtractor.kt │ ├── CampfireCookingRecipeImageGenerator.kt │ ├── SmithingRecipeImageGenerator.kt │ ├── StonecuttingRecipeImageGenerator.kt │ ├── SmeltingRecipeImageGenerator.kt │ ├── Rendering.kt │ ├── SmokingRecipeImageGenerator.kt │ ├── ItemIconsExtractor.kt │ ├── RecipesExporter.kt │ ├── BlastingRecipeImageGenerator.kt │ ├── CraftingRecipeImageGenerator.kt │ ├── RecipeConverters.kt │ ├── RecipeInfos.kt │ └── Util.kt ├── .gitignore ├── settings.gradle.kts ├── README.md ├── gradle.properties ├── LICENSE ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/recipe-images-exporter/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /logo/recipe-images-exporter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/recipe-images-exporter/master/logo/recipe-images-exporter.png -------------------------------------------------------------------------------- /logo/recipe-images-exporter.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/recipe-images-exporter/master/logo/recipe-images-exporter.xcf -------------------------------------------------------------------------------- /src/main/resources/assets/recipeimagesexporter/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bloopletech/recipe-images-exporter/master/src/main/resources/assets/recipeimagesexporter/icon.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME 6 | -------------------------------------------------------------------------------- /src/main/resources/recipeimagesexporter.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "package": "net.bloople.recipeimagesexporter.mixins", 4 | "compatibilityLevel": "JAVA_${java}", 5 | "injectors": { 6 | "defaultRequire": 1 7 | }, 8 | "mixins": [] 9 | } -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/RecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import java.awt.image.BufferedImage 4 | 5 | interface RecipeImageGenerator { 6 | val width: Int 7 | val height: Int 8 | fun generate(imageWidth: Int = width, imageHeight: Int = height): BufferedImage 9 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | 8 | # eclipse 9 | 10 | *.launch 11 | 12 | # idea 13 | 14 | .idea/ 15 | *.iml 16 | *.ipr 17 | *.iws 18 | 19 | # vscode 20 | 21 | .settings/ 22 | .vscode/ 23 | bin/ 24 | .classpath 25 | .project 26 | 27 | # macos 28 | 29 | *.DS_Store 30 | 31 | # fabric 32 | 33 | run/ 34 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven("https://maven.fabricmc.net") { name = "Fabric" } 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | plugins { 8 | id("fabric-loom").version(settings.extra["loom_version"] as String) 9 | kotlin("jvm").version(System.getProperty("kotlin_version")) 10 | } 11 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Recipe Images Exporter 2 | 3 | Automatically generates recipe images for all recipes that are loaded into the game, including recipes from mods and data packs. 4 | 5 | To use this mod: 6 | 1. simply install it as normal 7 | 2. open Minecraft 8 | 3. load a world 9 | 4. enter chat command `/export-recipe-images` and hit Enter. 10 | 11 | You will get chat feedback from the mod on export progress. 12 | 13 | Once complete, in your Minecraft game directory there will be a "recipe-images-exporter" directory, and the exported recipe images will be in there. -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # Standard Properties 3 | kotlin.code.style = official 4 | org.gradle.jvmargs = -Xmx1G 5 | org.gradle.warning.mode = all 6 | ########################################################################## 7 | # Standard Fabric Dependencies 8 | # Check these on https://fabricmc.net/develop/ 9 | minecraft_version = 1.19.2 10 | yarn_mappings = 1.19.2+build.28 11 | loader_version = 0.14.10 12 | # Fabric API 13 | fabric_version = 0.66.0+1.19.2 14 | loom_version = 1.0-SNAPSHOT 15 | java_version = 17 16 | ########################################################################## 17 | # Mod Properties 18 | mod_version = 1.2.0 19 | maven_group = net.bloople 20 | archives_base_name = recipe-images-exporter 21 | ########################################################################## 22 | # Kotlin Dependencies 23 | systemProp.kotlin_version = 1.7.20 24 | fabric_language_kotlin_version = 1.8.5+kotlin.1.7.20 25 | ########################################################################## -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "recipeimagesexporter", 4 | "version": "${version}", 5 | "name": "Recipe Images Exporter", 6 | "description": "Recipe Images Exporter", 7 | "authors": [ 8 | "Brenton \"B-Train\" Fletcher" 9 | ], 10 | "contact": { 11 | "homepage": "https://github.com/bloopletech/recipe-images-exporter", 12 | "sources": "https://github.com/bloopletech/recipe-images-exporter" 13 | }, 14 | "license": "MIT", 15 | "icon": "assets/recipeimagesexporter/icon.png", 16 | "environment": "client", 17 | "entrypoints": { 18 | "client": [ 19 | { 20 | "adapter": "kotlin", 21 | "value": "net.bloople.recipeimagesexporter.RecipeImagesExporterMod" 22 | } 23 | ] 24 | }, 25 | "mixins": [ 26 | "recipeimagesexporter.mixins.json" 27 | ], 28 | "depends": { 29 | "fabric-key-binding-api-v1": "*", 30 | "fabricloader": ">=${fabricloader}", 31 | "fabric-api": ">=${fabric_api}", 32 | "fabric-language-kotlin": ">=${fabric_language_kotlin}", 33 | "minecraft": ">=${minecraft}", 34 | "java": ">=${java}" 35 | } 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2022 Brenton Fletcher (i@bloople.net) 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/ImageMaskColor.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import java.awt.Color 4 | import java.awt.image.BufferedImage 5 | import kotlin.random.Random 6 | import kotlin.random.nextUInt 7 | 8 | fun findMaskColor(input: BufferedImage): Color { 9 | val pixels = getPixels(input) 10 | 11 | var red: Int 12 | var green: Int 13 | var blue: Int 14 | var argb: Int 15 | while(true) { 16 | red = Random.nextUInt(256u).toInt() 17 | green = Random.nextUInt(256u).toInt() 18 | blue = Random.nextUInt(256u).toInt() 19 | argb = 0xFF shl 24 or (red shl 16) or (green shl 8) or (blue shl 0) 20 | 21 | if(!pixels.contains(argb)) break 22 | } 23 | 24 | return Color(red, green, blue, 255) 25 | } 26 | 27 | private fun getPixels(input: BufferedImage): IntArray { 28 | return IntArray(input.width * input.height).apply { 29 | for(x in 0 until input.width) { 30 | for(y in 0 until input.height) { 31 | this[x * y] = input.getRGB(x, y) 32 | } 33 | } 34 | } 35 | } 36 | 37 | fun applyMaskColor(color: Color, destination: BufferedImage) { 38 | destination.apply { 39 | for(x in 0 until width) { 40 | for(y in 0 until height) { 41 | if(getRGB(x, y) == color.rgb) setRGB(x, y, 0) 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/ItemsData.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.bloople.recipeimagesexporter.CraftingRecipeImageGenerator.Companion.labelBackground 4 | import net.bloople.recipeimagesexporter.CraftingRecipeImageGenerator.Companion.slotBackground 5 | import net.minecraft.item.Item 6 | import net.minecraft.item.ItemStack 7 | import java.awt.image.BufferedImage 8 | 9 | data class ItemsData( 10 | val icons: Map, 11 | val labels: Map, 12 | val itemNameWidths: Map 13 | ) { 14 | private val slotIcons = icons.mapValues { it.value.scaleImage(30, 30).fillBackground(slotBackground) } 15 | private val slotLabelIcons = icons.mapValues { it.value.scaleImage(30, 30).fillBackground(labelBackground) } 16 | private val transparentSlotIcons = icons.mapValues { it.value.scaleImage(30, 30) } 17 | 18 | fun slotImage(itemStack: ItemStack): BufferedImage { 19 | return slotIcons[itemStack.uniqueKey]!! 20 | } 21 | 22 | fun transparentSlotImage(itemStack: ItemStack): BufferedImage { 23 | return transparentSlotIcons[itemStack.uniqueKey]!! 24 | } 25 | 26 | fun slotLabelImage(itemStack: ItemStack): BufferedImage { 27 | return slotLabelIcons[itemStack.uniqueKey]!! 28 | } 29 | 30 | fun outputImage(itemStack: ItemStack): BufferedImage { 31 | return icons[itemStack.uniqueKey]!! 32 | } 33 | 34 | fun labelImage(item: Item): BufferedImage { 35 | return labels[item]!! 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/GifSequenceWriter.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import java.awt.image.RenderedImage 4 | import java.io.Closeable 5 | import javax.imageio.* 6 | import javax.imageio.metadata.IIOMetadata 7 | import javax.imageio.metadata.IIOMetadataNode 8 | import javax.imageio.stream.ImageOutputStream 9 | 10 | class GifSequenceWriter(out: ImageOutputStream, imageType: Int, delay: Int, loop: Boolean) : Closeable { 11 | private var writer: ImageWriter = ImageIO.getImageWritersBySuffix("gif").next() 12 | private var params: ImageWriteParam = writer.defaultWriteParam 13 | private var metadata: IIOMetadata 14 | 15 | init { 16 | val imageTypeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(imageType) 17 | metadata = writer.getDefaultImageMetadata(imageTypeSpecifier, params) 18 | 19 | val metaFormatName = metadata.nativeMetadataFormatName 20 | val root = metadata.getAsTree(metaFormatName) as IIOMetadataNode 21 | 22 | getNode(root, "GraphicControlExtension").apply { 23 | setAttribute("disposalMethod", "none") 24 | setAttribute("userInputFlag", "FALSE") 25 | setAttribute("transparentColorFlag", "FALSE") 26 | setAttribute("delayTime", (delay / 10).toString()) 27 | setAttribute("transparentColorIndex", "0") 28 | } 29 | 30 | getNode(root, "ApplicationExtensions").appendChild(IIOMetadataNode("ApplicationExtension").apply { 31 | setAttribute("applicationID", "NETSCAPE") 32 | setAttribute("authenticationCode", "2.0") 33 | val loopContinuously = if(loop) 0 else 1 34 | userObject = byteArrayOf(0x1, (loopContinuously and 0xFF).toByte(), 0x0) 35 | }) 36 | 37 | metadata.setFromTree(metaFormatName, root) 38 | 39 | writer.output = out 40 | writer.prepareWriteSequence(null) 41 | } 42 | 43 | fun writeToSequence(img: RenderedImage) { 44 | writer.writeToSequence(IIOImage(img, null, metadata), params) 45 | } 46 | 47 | override fun close() { 48 | writer.endWriteSequence() 49 | } 50 | 51 | companion object { 52 | private fun getNode(rootNode: IIOMetadataNode, nodeName: String): IIOMetadataNode { 53 | val nNodes = rootNode.length 54 | for(i in 0 until nNodes) { 55 | if(rootNode.item(i).nodeName.equals(nodeName, ignoreCase = true)) { 56 | return rootNode.item(i) as IIOMetadataNode 57 | } 58 | } 59 | val node = IIOMetadataNode(nodeName) 60 | rootNode.appendChild(node) 61 | return node 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/RecipeImagesExporterMod.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import com.mojang.brigadier.CommandDispatcher 4 | import com.mojang.brigadier.context.CommandContext 5 | import net.fabricmc.api.* 6 | import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager 7 | import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback 8 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource 9 | import net.minecraft.client.MinecraftClient 10 | import net.minecraft.command.CommandRegistryAccess 11 | import org.slf4j.Logger 12 | import java.util.concurrent.CompletionException 13 | 14 | 15 | const val MOD_ID = "recipeimagesexporter" 16 | 17 | @Suppress("UNUSED") 18 | @EnvironmentInterface(value=EnvType.CLIENT, itf=ClientModInitializer::class) 19 | object RecipeImagesExporterMod: ClientModInitializer { 20 | private var exportRunning = false 21 | 22 | @Environment(value=EnvType.CLIENT) 23 | override fun onInitializeClient() { 24 | LOGGER.info("onInitializeClient()") 25 | 26 | ClientCommandRegistrationCallback.EVENT.register(ClientCommandRegistrationCallback { 27 | dispatcher: CommandDispatcher, _: CommandRegistryAccess? -> 28 | dispatcher.register( 29 | ClientCommandManager.literal("export-recipe-images").executes { 30 | context: CommandContext -> 31 | export(context.source.client) 32 | 0 33 | } 34 | ) 35 | }) 36 | 37 | LOGGER.info("end onInitializeClient()") 38 | } 39 | 40 | private fun export(client: MinecraftClient) { 41 | try { 42 | if(exportRunning) { 43 | client.sendMessage("Please wait for the current export to complete before starting another one") 44 | return 45 | } 46 | 47 | exportRunning = true 48 | RecipesExporter().export(client).thenRunAsync { exportRunning = false }.exceptionallyAsync { exception -> 49 | handleException(client, if(exception is CompletionException) exception.cause else exception) 50 | return@exceptionallyAsync null 51 | } 52 | } 53 | catch(exception: Exception) { 54 | handleException(client, exception) 55 | } 56 | } 57 | 58 | private fun handleException(client: MinecraftClient, throwable: Throwable?) { 59 | LOGGER.error("Caught exception during export", throwable) 60 | exportRunning = false 61 | client.sendMessage("Export failed due to an error, see log for details") 62 | } 63 | 64 | val LOGGER: Logger = getLogger(this::class) 65 | } -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/ItemLabelsExtractor.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.client.MinecraftClient 4 | import net.minecraft.client.font.TextRenderer 5 | import net.minecraft.item.Item 6 | import java.awt.image.BufferedImage 7 | import java.nio.file.Path 8 | import javax.imageio.ImageIO 9 | 10 | class ItemLabelsExtractor( 11 | items: List, 12 | private val exportDir: Path, 13 | private val textRenderer: TextRenderer 14 | ) { 15 | private val chunks = items.chunked(chunkSize).mapIndexed { index, itemStacks -> Chunk(itemStacks, index) } 16 | 17 | lateinit var widths: Map 18 | lateinit var labels: Map 19 | 20 | fun exportLabels(client: MinecraftClient) { 21 | client.sendMessage("Generating labels") 22 | var labelsCount = 0 23 | for(chunk in chunks) { 24 | chunk.exportLabels() 25 | labelsCount += chunk.size 26 | client.sendMessage("Generated $labelsCount labels") 27 | } 28 | } 29 | 30 | fun importLabels() { 31 | widths = HashMap().also { 32 | for(chunk in chunks) it += chunk.widths 33 | } 34 | 35 | labels = HashMap().also { 36 | for(chunk in chunks) it += chunk.importLabels() 37 | } 38 | } 39 | 40 | private inner class Chunk(private val items: List, index: Int) { 41 | private val labelsPath = exportDir.resolve("labels_$index.png") 42 | val size = items.size 43 | val widths by lazy { items.associateWith { textRenderer.getWidth(it.name) * 2 } } 44 | 45 | fun exportLabels() { 46 | val width = widths.values.max() 47 | val height = items.size * 18 48 | 49 | val nativeImage = renderToTexture(width, height, 0.7765f, 0.7765f, 0.7765f, 2.0) { 50 | var y = 0 51 | for(item in items) { 52 | renderText(textRenderer, item.name, 0, y, 0x000000) 53 | y += 9 54 | } 55 | } 56 | 57 | nativeImage.use { it.writeTo(labelsPath.toFile()) } 58 | } 59 | 60 | fun importLabels(): Map { 61 | val labelsImage = ImageIO.read(labelsPath.toFile()).asARGB() 62 | 63 | return items.mapIndexed { index, item -> 64 | val y = index * 18 65 | val labelWidth = widths[item]!! 66 | 67 | val image = BufferedImage(labelWidth, 18, BufferedImage.TYPE_INT_ARGB).apply { 68 | raster.setRect(0, 0, labelsImage.getData(0, y, width, height)) 69 | } 70 | 71 | item to image 72 | }.toMap() 73 | } 74 | } 75 | 76 | companion object { 77 | private const val chunkSize = 100 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/CampfireCookingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import java.awt.image.BufferedImage 5 | import java.lang.Integer.max 6 | import javax.imageio.ImageIO 7 | 8 | 9 | class CampfireCookingRecipeImageGenerator( 10 | private val recipeInfo: CampfireCookingRecipeInfo, 11 | private val itemsData: ItemsData 12 | ) : RecipeImageGenerator { 13 | override val width = max(166 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 14 | override val height = 120 15 | 16 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 17 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 18 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 19 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 20 | 21 | createGraphics().use { 22 | drawImage(itemsData.slotImage(recipeInfo.slot), 11, 11, null) 23 | drawImage(itemsData.slotImage(recipeInfo.output), 127, 11, null) 24 | 25 | val x = 8 26 | var y = 50 27 | 28 | for(item in recipeInfo.items) { 29 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 30 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 31 | y += 34 32 | } 33 | } 34 | } 35 | } 36 | 37 | companion object { 38 | private const val campfireCookingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAAB4CAIAAADjQRdrAAAC8ElEQVR42u3bsW2DUBSG0euEeViANVgEiQFpEEMwAku4oA2xE8nAe/ecxoULW08p/L0/PNZ1DQAAIIcvRwAAAHk0+8u2bc4CAACqZwEAAAABAAAACAAAAEAAAAAAAgAAALiZ5uiNYRhO+Pi+7yOi67pUh+5sAQC4igUAAAASaX5/e79F/pxxHCNiWZaER+9sAQA4nwUAAAAEQFbzPM/z7BwAABAAAACAAKiRHQAAAAEAAAAIgHrZAQAAEAAAAIAAqJcdAAAAAQAAAAiAetkBAAAQAAAAgAColx0AAAABAAAAFKMp96tfdRm/f27Xdf56AAAojgUAAAAEAK94HgAAAAEAAADcWuMI/sczAAAAlMgCAAAAiRS8AHziDv6df+t39w8AQLksAAAAkIhnAP7A3T8AAKWzAAAAQCIWgLe4+wcAoA4WAAAASMQC8IK7fwAAamIBAACARCwAh9z9AwBQHwsAAAAkYgH4gbt/AABqZQEAAIBEDheAvu8jYhzHVMdxzt1/zrMFAOAOLAAAAJDIY13XiNi2zVkAAED1LAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAF2siYpqmaZqcBQAAVO+7bVu//gEAIIknHjRVKxSIUvIAAAAASUVORK5CYII=" 39 | private val baseImage = ImageIO.read(decodeBase64(campfireCookingLeftImage)).asARGB() 40 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/SmithingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import java.awt.image.BufferedImage 5 | import java.lang.Integer.max 6 | import javax.imageio.ImageIO 7 | 8 | 9 | class SmithingRecipeImageGenerator( 10 | private val recipeInfo: SmithingRecipeInfo, 11 | private val itemsData: ItemsData 12 | ) : RecipeImageGenerator { 13 | override val width = max(264 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 14 | override val height = 154 15 | 16 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 17 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 18 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 19 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 20 | 21 | createGraphics().use { 22 | drawImage(itemsData.slotImage(recipeInfo.slotBase), 11, 11, null) 23 | drawImage(itemsData.slotImage(recipeInfo.slotAddition), 109, 11, null) 24 | drawImage(itemsData.outputImage(recipeInfo.output), 225, 11, null) 25 | 26 | val x = 8 27 | var y = 50 28 | 29 | for(item in recipeInfo.items) { 30 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 31 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 32 | y += 34 33 | } 34 | } 35 | } 36 | } 37 | 38 | companion object { 39 | private const val smithingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAACaCAIAAAC4za3iAAADqUlEQVR42u3dwW3CQBBA0SFxPTRAG27Ekgv0xXIRLsFNcOCIsIhiw+7Oe5cciBQxyiF/BsJlXdcAAABy+DECAADIo3t82bbNLAAAoHkuAAAAIAAAAAABAAAACAAAAEAAAAAAhelePTAMwwd+fN/3EXG73SodnymZLQBAXVwAAAAgkW7/4cd+9DzjOEbEsixVD9GUzBYAoBYuAAAAIADgtX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(smithingLeftImage)).asARGB() 41 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/StonecuttingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import java.awt.image.BufferedImage 5 | import java.lang.Integer.max 6 | import javax.imageio.ImageIO 7 | 8 | 9 | class StonecuttingRecipeImageGenerator( 10 | private val recipeInfo: StonecuttingRecipeInfo, 11 | private val itemsData: ItemsData 12 | ) : RecipeImageGenerator { 13 | override val width = max(168 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 14 | override val height = 164 15 | 16 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 17 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 18 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 19 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 20 | 21 | createGraphics().use { 22 | drawImage(itemsData.slotImage(recipeInfo.slot), 11, 47, null) 23 | drawImage(itemsData.transparentSlotImage(recipeInfo.slot), 54, 22, null) 24 | drawImage(itemsData.outputImage(recipeInfo.output), 119, 45, null) 25 | 26 | val x = 8 27 | var y = 94 28 | 29 | for(item in recipeInfo.items) { 30 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 31 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 32 | y += 34 33 | } 34 | } 35 | } 36 | } 37 | 38 | companion object { 39 | private const val stonecuttingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAACkCAIAAACGvcs/AAAEJ0lEQVR42u3dMU7jUBSG0QvjOhvKNryIaS15Hy4o2AHS9HQ0biyLmtJL8CYoXCERJYxC8vzuOc10g/VC8/kP9sOyLAEAAOTw6AgAACC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ACAAAAEAAAAAAAgAAABAAAACAAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAACAAAAEAAAAIAAAAAABAAAACAAAACAO2vGcRzH0UEAAEAGfw6Hg1MAAIAkPgFAS2b4uVKNgQAAAABJRU5ErkJggg==" 40 | private val baseImage = ImageIO.read(decodeBase64(stonecuttingLeftImage)).asARGB() 41 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/SmeltingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import net.minecraft.util.Identifier 5 | import net.minecraft.util.registry.Registry 6 | import java.awt.image.BufferedImage 7 | import java.lang.Integer.max 8 | import javax.imageio.ImageIO 9 | 10 | 11 | class SmeltingRecipeImageGenerator( 12 | private val recipeInfo: SmeltingRecipeInfo, 13 | private val itemsData: ItemsData 14 | ) : RecipeImageGenerator { 15 | override val width = max(178 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 16 | override val height = 192 17 | 18 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 19 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 20 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 21 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 22 | 23 | createGraphics().use { 24 | drawImage(itemsData.slotImage(recipeInfo.slot), 11, 11, null) 25 | val coalStack = ItemStack(Registry.ITEM.get(Identifier("coal")), 1) 26 | drawImage(itemsData.slotImage(coalStack), 11, 83, null) 27 | drawImage(itemsData.outputImage(recipeInfo.output), 130, 46, null) 28 | 29 | val x = 8 30 | var y = 122 31 | 32 | for(item in recipeInfo.items) { 33 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 34 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 35 | y += 34 36 | } 37 | } 38 | } 39 | } 40 | 41 | companion object { 42 | private const val smeltingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAADACAIAAAAV2IZzAAAE4ElEQVR42u3dzXGjMBiA4S+71OMGaINGmFGBXBiKcAk0kYNmZ3JYvLC2MZKe55JMnB8PXPLqs+Sv+/0eAABAG365BAAA0I4uf1jX1bUAAIDqmQAAAIAAAAAABAAAACAAAAAAAQAAAFxMt/XAOI4n/PlhGCKi73t3AgAATmACAAAADekeP5xX6N8npRQRy7K4EwAAcAITAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAABAAAACAAAACASnQuwTnGcbzgsxqGISL6vneDAAAaYQIAAAANMQE4VV5xv46UUkQsy+LWAAA0wgQAAAAEAAAAIAAAAICibe4ByK9Wz68RBwAA6mACAAAADdmcAOSz4Z0PAwAANTEBAAAAAdCSeZ7neXYdAAAQAAAAgACokTkAAAACAAAAaDUAnlkjL2V93RwAAAABAAAACIB6mQMAACAAAACA4nX7vzW/N3BeGs+f/3T069dX7jMHAIAtJgAAACAA+MN+AAAABAAAAFCkA3sAHi+E/98OgaM+tRhvPwAAAHUwAQAAAAHA39gPAACAAAAAAIqxaw/AnmXv/d9T7ivp7QEAAKB0JgAAANCQ7ugPHF0F/3k60PPesQa/57lZ+wcAoA4mAAAA0JDu+V9R98E41v4BAKiJCQAAADTk8ATg8Uk+W+8BXCJr/wAA1McEAAAAGrJrAvCqk3xKWVO39g8AQK1MAAAAoCHda3+d9/oFAIArMwEAAICG7JoAvOoknyvPB6z9AwDQAhMAAABoyIFTgN7x6BVY+wcAoB0mAAAAIAAAAAABAAAAFG1zD8A4jif8+WEYwqvwAQDgLCYAAADQkH+cApRX6N8npRQRy7K4EwAAcAITAAAAEAAAAIAAAAAAita5BOfIuynyngcAAPgUEwAAAGiICcBJ8nsdOO8IAIDPMgEAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAEAAAAAAAgAAAKhEt/XAMAwRkVJyjQAAoBomAAAA0JCv+/0eEeu6uhYAAFA9EwAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAACAAAAEAAAAIAAAAAABAAAACAAAACAD+siYpqmaZpcCwAAqN7v2+3mv38AAGjEN+eEoeCDKRi7AAAAAElFTkSuQmCC" 43 | private val baseImage = ImageIO.read(decodeBase64(smeltingLeftImage)).asARGB() 44 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/Rendering.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import com.mojang.blaze3d.platform.GlConst 4 | import com.mojang.blaze3d.systems.RenderSystem 5 | import net.minecraft.client.MinecraftClient.IS_SYSTEM_MAC 6 | import net.minecraft.client.font.TextRenderer 7 | import net.minecraft.client.gl.SimpleFramebuffer 8 | import net.minecraft.client.gui.widget.ClickableWidget 9 | import net.minecraft.client.render.* 10 | import net.minecraft.client.texture.NativeImage 11 | import net.minecraft.client.util.ScreenshotRecorder 12 | import net.minecraft.client.util.math.MatrixStack 13 | import net.minecraft.text.Text 14 | import net.minecraft.util.math.Matrix4f 15 | 16 | 17 | fun renderToTexture( 18 | width: Int, 19 | height: Int, 20 | r: Float, 21 | g: Float, 22 | b: Float, 23 | scaleFactor: Double, 24 | block: () -> Unit 25 | ): NativeImage { 26 | RenderSystem.assertOnRenderThread() 27 | 28 | val framebuffer = SimpleFramebuffer(width, height, true, IS_SYSTEM_MAC) 29 | framebuffer.setClearColor(r, g, b, 0.0f) 30 | framebuffer.resize(width, height, IS_SYSTEM_MAC) 31 | 32 | try { 33 | val matrixStack: MatrixStack = RenderSystem.getModelViewStack() 34 | matrixStack.push() 35 | RenderSystem.applyModelViewMatrix() 36 | RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT or GlConst.GL_COLOR_BUFFER_BIT, IS_SYSTEM_MAC) 37 | framebuffer.beginWrite(true) 38 | BackgroundRenderer.clearFog() 39 | RenderSystem.enableTexture() 40 | RenderSystem.enableCull() 41 | 42 | RenderSystem.viewport(0, 0, width, height) 43 | 44 | RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT, IS_SYSTEM_MAC) 45 | val matrix4f = Matrix4f.projectionMatrix( 46 | 0.0f, 47 | (width.toDouble() / scaleFactor).toFloat(), 48 | 0.0f, 49 | (height.toDouble() / scaleFactor).toFloat(), 50 | 1000.0f, 51 | 3000.0f 52 | ) 53 | RenderSystem.setProjectionMatrix(matrix4f) 54 | val matrixStack2 = RenderSystem.getModelViewStack() 55 | matrixStack2.loadIdentity() 56 | matrixStack2.translate(0.0, 0.0, -2000.0) 57 | RenderSystem.applyModelViewMatrix() 58 | DiffuseLighting.enableGuiDepthLighting() 59 | 60 | RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f) 61 | RenderSystem.setShader { GameRenderer.getPositionTexShader() } 62 | RenderSystem.setShaderTexture(0, ClickableWidget.WIDGETS_TEXTURE) 63 | 64 | RenderSystem.enableBlend() 65 | RenderSystem.defaultBlendFunc() 66 | 67 | block() 68 | 69 | RenderSystem.disableBlend() 70 | 71 | RenderSystem.clear(GlConst.GL_DEPTH_BUFFER_BIT, IS_SYSTEM_MAC) 72 | 73 | framebuffer.endWrite() 74 | matrixStack.pop() 75 | matrixStack.push() 76 | RenderSystem.applyModelViewMatrix() 77 | framebuffer.draw(width, height) 78 | matrixStack.pop() 79 | RenderSystem.applyModelViewMatrix() 80 | 81 | return ScreenshotRecorder.takeScreenshot(framebuffer) 82 | } 83 | finally { 84 | framebuffer.delete() 85 | } 86 | } 87 | 88 | fun renderText(textRenderer: TextRenderer, text: Text, x: Int, y: Int, color: Int) { 89 | val matrixStack = MatrixStack() 90 | 91 | matrixStack.translate(0.0, 0.0, 0.0) 92 | val immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().buffer) 93 | 94 | textRenderer.draw( 95 | text, 96 | x.toFloat(), 97 | y.toFloat(), 98 | color, 99 | false, 100 | matrixStack.peek().positionMatrix, 101 | immediate as VertexConsumerProvider, 102 | false, 103 | 0, 104 | LightmapTextureManager.MAX_LIGHT_COORDINATE 105 | ) 106 | immediate.draw() 107 | } -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/SmokingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import net.minecraft.util.Identifier 5 | import net.minecraft.util.registry.Registry 6 | import java.awt.image.BufferedImage 7 | import java.lang.Integer.max 8 | import javax.imageio.ImageIO 9 | 10 | 11 | class SmokingRecipeImageGenerator( 12 | private val recipeInfo: SmokingRecipeInfo, 13 | private val itemsData: ItemsData 14 | ) : RecipeImageGenerator { 15 | override val width = max(178 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 16 | override val height = 192 17 | 18 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 19 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 20 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 21 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 22 | 23 | createGraphics().use { 24 | drawImage(itemsData.slotImage(recipeInfo.slot), 11, 11, null) 25 | val coalStack = ItemStack(Registry.ITEM.get(Identifier("coal")), 1) 26 | drawImage(itemsData.slotImage(coalStack), 11, 83, null) 27 | drawImage(itemsData.outputImage(recipeInfo.output), 130, 46, null) 28 | 29 | val x = 8 30 | var y = 122 31 | 32 | for(item in recipeInfo.items) { 33 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 34 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 35 | y += 34 36 | } 37 | } 38 | } 39 | } 40 | 41 | companion object { 42 | private const val smokingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAADACAIAAAAV2IZzAAAFf0lEQVR42u3dzW3iUBSA0ZsZ15MGaMONWPImFaQtNshFuAQ3MQtrJDSOGfNneO+es0kExCCzyfcuz3yM4xgAAEAOv5wCAADIo5l/TNPkXAAAQPVMAAAAQAAAAAACAAAAEAAAAIAAAAAA3kyzdkfXdTs8fdu2EXE4HAo9fV9fXz/e/v39/fBneewxAQDIyQQAAAASaS7fPa/QP0/f9xExDENxJ86qPAAAJTIBAACARBqn4Dbz2v9yD8D5TOD83vPHL+cGl4+ztDzOlleyfM0mGAAA2ZgAAABAIiYAd1lbyz+/fbn2v/b75eOs3X7PI+1kAADIxgQAAAASMQEoxuXV+rVvJDi3/Ftr/wAA2ZgAAABAIiYAN7r20/P3r7Vf3jNgLR8AgC1MAAAAIBET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gAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAAPBiTUQcj8fj8ehcAABA9X5/fn767x8AAJL4A/OcFbFtQzs2AAAAAElFTkSuQmCC" 43 | private val baseImage = ImageIO.read(decodeBase64(smokingLeftImage)).asARGB() 44 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/ItemIconsExtractor.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.bloople.recipeimagesexporter.CraftingRecipeImageGenerator.Companion.slotBackground 4 | import net.minecraft.client.MinecraftClient 5 | import net.minecraft.client.font.TextRenderer 6 | import net.minecraft.client.render.item.ItemRenderer 7 | import net.minecraft.item.ItemStack 8 | import java.awt.Color 9 | import java.awt.image.BufferedImage 10 | import java.nio.file.Path 11 | import javax.imageio.ImageIO 12 | import kotlin.math.ceil 13 | import kotlin.math.sqrt 14 | 15 | class ItemIconsExtractor( 16 | itemStacks: List, 17 | private val exportDir: Path, 18 | private val itemRenderer: ItemRenderer, 19 | private val textRenderer: TextRenderer 20 | ) { 21 | private val chunks = itemStacks.chunked(chunkSize).mapIndexed { index, itemStacks -> Chunk(itemStacks, index) } 22 | lateinit var icons: Map 23 | 24 | fun exportIcons(client: MinecraftClient) { 25 | client.sendMessage("Generating icons") 26 | var iconsCount = 0 27 | for(chunk in chunks) { 28 | chunk.exportIcons(slotBackground) 29 | chunk.findMaskColor() 30 | chunk.exportIcons(chunk.maskColor) 31 | iconsCount += chunk.size 32 | client.sendMessage("Generated $iconsCount icons") 33 | } 34 | } 35 | 36 | fun importIcons() { 37 | for(chunk in chunks) chunk.eraseMaskColor() 38 | icons = HashMap().also { 39 | for(chunk in chunks) it += chunk.importIcons() 40 | } 41 | } 42 | 43 | private inner class Chunk(private val itemStacks: List, index: Int) { 44 | private val iconsPath = exportDir.resolve("icons_$index.png") 45 | private val iconsStride = ceil(sqrt(itemStacks.size.toDouble())).toInt() 46 | val size = itemStacks.size 47 | lateinit var maskColor: Color 48 | 49 | fun exportIcons(background: Color) { 50 | val width = iconsStride * 34 51 | val height = iconsStride * 34 52 | val scaledWidth = iconsStride * 17 53 | val r = background.red / 255.0f 54 | val g = background.green / 255.0f 55 | val b = background.blue / 255.0f 56 | 57 | val nativeImage = renderToTexture(width, height, r, g, b, 2.0) { 58 | var x = 0 59 | var y = 0 60 | for(itemStack in itemStacks) { 61 | itemRenderer.renderInGui(itemStack, x, y) 62 | itemRenderer.renderGuiItemOverlay(textRenderer, itemStack, x, y) 63 | 64 | x += 17 65 | if(x >= scaledWidth) { 66 | x = 0 67 | y += 17 68 | } 69 | } 70 | } 71 | 72 | nativeImage.use { it.writeTo(iconsPath.toFile()) } 73 | } 74 | 75 | private fun getImage(): BufferedImage { 76 | return ImageIO.read(iconsPath.toFile()).asARGB() 77 | } 78 | 79 | fun findMaskColor() { 80 | maskColor = findMaskColor(getImage()) 81 | } 82 | 83 | fun eraseMaskColor() { 84 | val maskedImage = getImage().apply { applyMaskColor(maskColor, this) } 85 | ImageIO.write(maskedImage, "PNG", iconsPath.toFile()) 86 | } 87 | 88 | fun importIcons(): Map { 89 | val iconsImage = ImageIO.read(iconsPath.toFile()).asARGB() 90 | 91 | return itemStacks.mapIndexed { index, itemStack -> 92 | val x = (index % iconsStride) * 34 93 | val y = (index / iconsStride) * 34 94 | 95 | val image = BufferedImage(34, 34, BufferedImage.TYPE_INT_ARGB).apply { 96 | raster.setRect(0, 0, iconsImage.getData(x, y, width, height)) 97 | } 98 | 99 | itemStack.uniqueKey to image 100 | }.toMap() 101 | } 102 | } 103 | 104 | companion object { 105 | private const val chunkSize = 1000 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/RecipesExporter.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.client.MinecraftClient 4 | import net.minecraft.util.Util 5 | import java.awt.image.BufferedImage 6 | import java.nio.file.Files 7 | import java.nio.file.Path 8 | import java.util.concurrent.CompletableFuture 9 | import javax.imageio.ImageIO 10 | import javax.imageio.stream.FileImageOutputStream 11 | 12 | class RecipesExporter { 13 | private lateinit var exportDir: Path 14 | 15 | fun export(client: MinecraftClient): CompletableFuture { 16 | client.sendMessage("Starting export of recipe images") 17 | 18 | val step1 = CompletableFuture.runAsync({ 19 | client.sendMessage("Deleting any existing export") 20 | exportDir = client.runDirectory.toPath().toAbsolutePath().resolve("recipe-images-exporter") 21 | exportDir.toFile().deleteRecursively() 22 | Files.createDirectories(exportDir) 23 | 24 | client.sendMessage("Deleted any existing export and created export directory $exportDir") 25 | }, Util.getIoWorkerExecutor()) 26 | 27 | lateinit var recipeInfos: RecipeInfos 28 | lateinit var itemIconsExtractor: ItemIconsExtractor 29 | lateinit var itemLabelsExtractor: ItemLabelsExtractor 30 | 31 | val step2 = step1.thenRunAsync({ 32 | client.sendMessage("Gathering icons and labels") 33 | recipeInfos = RecipeInfos(client.world!!.recipeManager) 34 | client.sendMessage("Gathered ${recipeInfos.all.size} recipes for export") 35 | client.sendMessage("Generating icons and labels") 36 | 37 | itemIconsExtractor = ItemIconsExtractor( 38 | recipeInfos.itemStacks, 39 | exportDir, 40 | client.itemRenderer, 41 | client.textRenderer 42 | ) 43 | itemIconsExtractor.exportIcons(client) 44 | 45 | itemLabelsExtractor = ItemLabelsExtractor(recipeInfos.items, exportDir, client.textRenderer) 46 | itemLabelsExtractor.exportLabels(client) 47 | 48 | client.sendMessage("Generated icons and labels") 49 | }, client) 50 | 51 | val step3 = step2.thenRunAsync({ 52 | itemIconsExtractor.importIcons() 53 | itemLabelsExtractor.importLabels() 54 | 55 | val itemsData = ItemsData( 56 | itemIconsExtractor.icons, 57 | itemLabelsExtractor.labels, 58 | itemLabelsExtractor.widths 59 | ) 60 | 61 | var count = 0 62 | for(groupChunk in recipeInfos.groups.chunked(100)) { 63 | for(group in groupChunk) exportGroup(group, itemsData) 64 | count += groupChunk.size 65 | client.sendMessage("Exported $count recipes") 66 | } 67 | 68 | client.sendMessage("Export complete") 69 | }, Util.getIoWorkerExecutor()) 70 | 71 | return step3 72 | } 73 | 74 | private fun exportGroup(group: List, itemsData: ItemsData) { 75 | for(recipeInfo in group) writeRecipeImage(recipeInfo, recipeInfo.imageGenerator(itemsData).generate()) 76 | 77 | if(group.size == 1) return 78 | val imageGenerators = group.map { it.imageGenerator(itemsData) } 79 | val maxWidth = imageGenerators.maxOf { it.width } 80 | val maxHeight = imageGenerators.maxOf { it.height } 81 | val images = imageGenerators.map { it.generate(maxWidth, maxHeight) } 82 | writeRecipesAnimation(group[0], images) 83 | } 84 | 85 | private fun writeRecipeImage(recipeInfo: RecipeInfo, image: BufferedImage) { 86 | val recipeFilePath = exportDir.resolve("${recipeInfo.recipePath}.png") 87 | Files.createDirectories(recipeFilePath.parent) 88 | ImageIO.write(image, "PNG", recipeFilePath.toFile()) 89 | } 90 | 91 | private fun writeRecipesAnimation(firstRecipeInfo: RecipeInfo, images: List) { 92 | val recipeFilePath = exportDir.resolve("${firstRecipeInfo.recipeBasePath}.gif") 93 | Files.createDirectories(recipeFilePath.parent) 94 | FileImageOutputStream(recipeFilePath.toFile()).use { outStream -> 95 | GifSequenceWriter(outStream, images[0].type, 500, true).use { 96 | for(image in images) it.writeToSequence(image) 97 | } 98 | } 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/BlastingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import net.minecraft.util.Identifier 5 | import net.minecraft.util.registry.Registry 6 | import java.awt.image.BufferedImage 7 | import java.lang.Integer.max 8 | import javax.imageio.ImageIO 9 | 10 | 11 | class BlastingRecipeImageGenerator( 12 | private val recipeInfo: BlastingRecipeInfo, 13 | private val itemsData: ItemsData 14 | ) : RecipeImageGenerator { 15 | override val width = max(178 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 16 | override val height = 192 17 | 18 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 19 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 20 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 21 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 22 | 23 | createGraphics().use { 24 | drawImage(itemsData.slotImage(recipeInfo.slot), 11, 11, null) 25 | val coalStack = ItemStack(Registry.ITEM.get(Identifier("coal")), 1) 26 | drawImage(itemsData.slotImage(coalStack), 11, 83, null) 27 | drawImage(itemsData.outputImage(recipeInfo.output), 130, 46, null) 28 | 29 | val x = 8 30 | var y = 122 31 | 32 | for(item in recipeInfo.items) { 33 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 34 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 35 | y += 34 36 | } 37 | } 38 | } 39 | } 40 | 41 | companion object { 42 | private const val blastingLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAADACAIAAAAV2IZzAAAJL0lEQVR42u3dTW9bVR7A4WP7xnlx7JZpgClJUxpSpEqjgjTdVXyCETt/CjRIWLKQIDs2SPRLDBJfAGbDCI3UBZnAomJgA4lnhnbS0DZOWufFiePXWViVKkI6Ttukse/zbFo5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6fzwdX4QMAwHExAQAAgBj5P3cB6u7QH51isRhCWFhY8E4AAMAxMAEAAAABAAAACAAAAKCvRZbgeHRPU3TPPAAAwPNiAgAAADFiAnBMup914H5HAAA8XyYAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAIAAAAQAAAAAADIjroC/l8PoRQLBatEQAADAwTAAAAiJFEqVQKIZTLZWsBAAADzwQAAAAEAAAAIAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAACAAAAEAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAABAAAACAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAIAAAAAABAAAACAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAEAAAAAAAgAAABAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAAQAAAAAACAAAAEAAAAIAAAAAAAQAAAAgAAABAAAAAAAIAAAAQAAAAgAAAAAAEAAAAIAAAAAABAAAACAAAAEAAAACAAAAAAAQAAAAgAAAAAAEAAAAIAAAA4DmLQgjXr1+/fv26tQAAgIGXunz5sv/9AwBATPwPu9St/o4zCzoAAAAASUVORK5CYII=" 43 | private val baseImage = ImageIO.read(decodeBase64(blastingLeftImage)).asARGB() 44 | private val rightImage = ImageIO.read(decodeBase64(CraftingRecipeImageGenerator.craftingRightImage)).asARGB() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/CraftingRecipeImageGenerator.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import java.awt.Color 5 | import java.awt.image.BufferedImage 6 | import java.lang.Integer.max 7 | import javax.imageio.ImageIO 8 | 9 | 10 | class CraftingRecipeImageGenerator( 11 | private val recipeInfo: CraftingRecipeInfo, 12 | private val itemsData: ItemsData 13 | ) : RecipeImageGenerator { 14 | override val width = max(214 + rightImage.width, recipeInfo.items.maxOf { itemsData.itemNameWidths[it]!! } + 44 + 8) 15 | override val height = 122 + bottomImage.height + 6 + (recipeInfo.items.size * 30) + (max(recipeInfo.items.size - 1, 0) * 4) 16 | 17 | override fun generate(imageWidth: Int, imageHeight: Int): BufferedImage { 18 | return BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB).apply { 19 | raster.setRect(0, 0, baseImage.getData(0, 0, width, height)) 20 | raster.setRect(0, height - 2, bottomImage.getData(0, 0, width, 2)) 21 | raster.setRect(width - 2, 0, rightImage.getData(0, 0, 2, height)) 22 | 23 | createGraphics().use { 24 | if(recipeInfo.slot1 != null) drawImage(itemsData.slotImage(recipeInfo.slot1), 11, 11, null) 25 | if(recipeInfo.slot2 != null) drawImage(itemsData.slotImage(recipeInfo.slot2), 47, 11, null) 26 | if(recipeInfo.slot3 != null) drawImage(itemsData.slotImage(recipeInfo.slot3), 83, 11, null) 27 | if(recipeInfo.slot4 != null) drawImage(itemsData.slotImage(recipeInfo.slot4), 11, 47, null) 28 | if(recipeInfo.slot5 != null) drawImage(itemsData.slotImage(recipeInfo.slot5), 47, 47, null) 29 | if(recipeInfo.slot6 != null) drawImage(itemsData.slotImage(recipeInfo.slot6), 83, 47, null) 30 | if(recipeInfo.slot7 != null) drawImage(itemsData.slotImage(recipeInfo.slot7), 11, 83, null) 31 | if(recipeInfo.slot8 != null) drawImage(itemsData.slotImage(recipeInfo.slot8), 47, 83, null) 32 | if(recipeInfo.slot9 != null) drawImage(itemsData.slotImage(recipeInfo.slot9), 83, 83, null) 33 | drawImage(itemsData.outputImage(recipeInfo.output), 166, 46, null) 34 | 35 | val x = 8 36 | var y = 122 37 | 38 | for(item in recipeInfo.items) { 39 | drawImage(itemsData.slotLabelImage(ItemStack(item, 1)), x, y, null) 40 | // val labelImage = recipesExporter.getLabel(item) 41 | // raster.setRect(44, y + 7, labelImage.getData(0, 0, width - 44 - 2, labelImage.height)) 42 | drawImage(itemsData.labelImage(item), 44, y + 6, null) 43 | y += 34 44 | } 45 | } 46 | } 47 | } 48 | 49 | companion object { 50 | private const val craftingTopLeftImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAAQABAMAAACNMzawAAAAFVBMVEXb29ubm5tbW1vGxsY3NzeLi4v////TAbtBAAAHI0lEQVR42u3cwQmEMBRFUXv6LdjCb8H+S5h9xCEMImPeucssHweiC902ScmVkgMAAAEgAASAUgHsYz1zYjwAtAiAHjpmTowHgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgFYBsF/lQzIAlACgL3JhACAABID+EEAfYzMnAAAAwCJXwG2/iAEAAAA8BAIAAABRABoAAABIBtAAAABAMoAGAAAAkgE0AAAAkAygAQAAgCwAwwkAAACQDKABAAAAVwAAAADgNRAAAACIAlAAAABALoACAAAAcgEUAAAAkAugAAAAgFwABQAAAAAAAAAAvBGAX8QAAED0FeAXMQAA4CHQQyAAAAAAAAAAAPAjgPPL4reXRgGgtQAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAD0H4L5fxAgAvQ+AABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAABgAwAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACAAAbACAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAANgAAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAAwAYACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABAAANgBAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAACwAQACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABAIANABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAAGwAgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAAYAMABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAgAAGwAgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAAEgAASAABAAAkAACAABIAAEgAAQAAJAAAgAASAABIAAEAACQAAIAD3aB4UGTr2qmgFLAAAAAElFTkSuQmCC" 51 | const val craftingRightImage = "iVBORw0KGgoAAAANSUhEUgAAAAIAAAQABAMAAAA5H5UPAAAAFVBMVEXb29ubm5tbW1vGxsY3NzeLi4v////TAbtBAAAAG0lEQVQ4y2NgZBBiUBqFo3AUjsJROApH4UiCAKATh9ANBbyxAAAAAElFTkSuQmCC" 52 | private const val craftingBottomImage = "iVBORw0KGgoAAAANSUhEUgAABAAAAAACBAMAAAA0tLOoAAAAFVBMVEXb29ubm5tbW1vGxsY3NzeLi4v////TAbtBAAAAFUlEQVQ4y2NgVBoFIxkwCI2GwYgGAPfCh9AdT+awAAAAAElFTkSuQmCC" 53 | private val baseImage = ImageIO.read(decodeBase64(craftingTopLeftImage)).asARGB() 54 | private val rightImage = ImageIO.read(decodeBase64(craftingRightImage)).asARGB() 55 | private val bottomImage = ImageIO.read(decodeBase64(craftingBottomImage)).asARGB() 56 | val slotBackground = Color(139, 139, 139) 57 | val labelBackground = Color(198, 198, 198) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/RecipeConverters.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.ItemStack 4 | import net.minecraft.recipe.* 5 | 6 | 7 | class CraftingRecipeAdapter(val slots: Array?> = arrayOfNulls(9)) : RecipeGridAligner { 8 | override fun acceptAlignedInput( 9 | inputs: MutableIterator, 10 | slot: Int, 11 | amount: Int, 12 | gridX: Int, 13 | gridY: Int 14 | ) { 15 | val itemStacks = inputs.next().matchingStacks 16 | if(itemStacks.isNotEmpty()) slots[slot] = itemStacks 17 | } 18 | } 19 | 20 | fun convertCraftingRecipe(recipe: CraftingRecipe): List { 21 | val recipePath = "crafting/${recipe.id.namespace}/${recipe.id.path}" 22 | 23 | val ingredients = recipe.ingredients 24 | 25 | val adapter = CraftingRecipeAdapter() 26 | adapter.alignRecipeToGrid(3, 3, -1, recipe, recipe.ingredients.iterator(), 0) 27 | 28 | val maxStacksSize = ingredients.maxOf { it.matchingStacks.size } 29 | 30 | val recipeInfos = ArrayList() 31 | 32 | repeat(maxStacksSize) { index -> 33 | recipeInfos.add( 34 | CraftingRecipeInfo( 35 | recipePath, 36 | if(maxStacksSize > 1) "${recipePath}_$index" else recipePath, 37 | adapter.slots[0]?.getOrLast(index), 38 | adapter.slots[1]?.getOrLast(index), 39 | adapter.slots[2]?.getOrLast(index), 40 | adapter.slots[3]?.getOrLast(index), 41 | adapter.slots[4]?.getOrLast(index), 42 | adapter.slots[5]?.getOrLast(index), 43 | adapter.slots[6]?.getOrLast(index), 44 | adapter.slots[7]?.getOrLast(index), 45 | adapter.slots[8]?.getOrLast(index), 46 | recipe.output 47 | ) 48 | ) 49 | } 50 | 51 | return recipeInfos 52 | } 53 | 54 | fun convertSmeltingRecipe(recipe: SmeltingRecipe): List { 55 | val recipePath = "smelting/${recipe.id.namespace}/${recipe.id.path}" 56 | 57 | val ingredient = recipe.ingredients[0] 58 | 59 | val recipeInfos = ArrayList() 60 | 61 | for((index, matchingStack) in ingredient.matchingStacks.withIndex()) { 62 | recipeInfos.add(SmeltingRecipeInfo( 63 | recipePath, 64 | if(ingredient.matchingStacks.size > 1) "${recipePath}_$index" else recipePath, 65 | matchingStack, 66 | recipe.output 67 | )) 68 | } 69 | return recipeInfos 70 | } 71 | 72 | fun convertBlastingRecipe(recipe: BlastingRecipe): List { 73 | val recipePath = "blasting/${recipe.id.namespace}/${recipe.id.path}" 74 | 75 | val ingredient = recipe.ingredients[0] 76 | 77 | val recipeInfos = ArrayList() 78 | 79 | for((index, matchingStack) in ingredient.matchingStacks.withIndex()) { 80 | recipeInfos.add(BlastingRecipeInfo( 81 | recipePath, 82 | if(ingredient.matchingStacks.size > 1) "${recipePath}_$index" else recipePath, 83 | matchingStack, 84 | recipe.output 85 | )) 86 | } 87 | return recipeInfos 88 | } 89 | 90 | fun convertSmokingRecipe(recipe: SmokingRecipe): List { 91 | val recipePath = "smoking/${recipe.id.namespace}/${recipe.id.path}" 92 | 93 | val ingredient = recipe.ingredients[0] 94 | 95 | val recipeInfos = ArrayList() 96 | 97 | for((index, matchingStack) in ingredient.matchingStacks.withIndex()) { 98 | recipeInfos.add(SmokingRecipeInfo( 99 | recipePath, 100 | if(ingredient.matchingStacks.size > 1) "${recipePath}_$index" else recipePath, 101 | matchingStack, 102 | recipe.output 103 | )) 104 | } 105 | return recipeInfos 106 | } 107 | 108 | fun convertCampfireCookingRecipe(recipe: CampfireCookingRecipe): List { 109 | val recipePath = "campfire_cooking/${recipe.id.namespace}/${recipe.id.path}" 110 | 111 | val ingredient = recipe.ingredients[0] 112 | 113 | val recipeInfos = ArrayList() 114 | 115 | for((index, matchingStack) in ingredient.matchingStacks.withIndex()) { 116 | recipeInfos.add(CampfireCookingRecipeInfo( 117 | recipePath, 118 | if(ingredient.matchingStacks.size > 1) "${recipePath}_$index" else recipePath, 119 | matchingStack, 120 | recipe.output 121 | )) 122 | } 123 | return recipeInfos 124 | } 125 | 126 | fun convertStonecuttingRecipe(recipe: StonecuttingRecipe): List { 127 | val recipePath = "stonecutting/${recipe.id.namespace}/${recipe.id.path}" 128 | 129 | val ingredient = recipe.ingredients[0] 130 | 131 | val recipeInfos = ArrayList() 132 | 133 | for((index, matchingStack) in ingredient.matchingStacks.withIndex()) { 134 | recipeInfos.add(StonecuttingRecipeInfo( 135 | recipePath, 136 | if(ingredient.matchingStacks.size > 1) "${recipePath}_$index" else recipePath, 137 | matchingStack, 138 | recipe.output 139 | )) 140 | } 141 | return recipeInfos 142 | } 143 | 144 | fun convertSmithingRecipe(recipe: SmithingRecipe): List { 145 | val recipePath = "smithing/${recipe.id.namespace}/${recipe.id.path}" 146 | 147 | val base = recipe.javaClass.getDeclaredField("base").get(recipe) as Ingredient 148 | val addition = recipe.javaClass.getDeclaredField("addition").get(recipe) as Ingredient 149 | 150 | val maxStacksSize = arrayOf(base, addition).maxOf { it.matchingStacks.size } 151 | 152 | val recipeInfos = ArrayList() 153 | 154 | repeat(maxStacksSize) { index -> 155 | recipeInfos.add( 156 | SmithingRecipeInfo( 157 | recipePath, 158 | if(maxStacksSize > 1) "${recipePath}_$index" else recipePath, 159 | base.matchingStacks.getOrLast(index)!!, 160 | addition.matchingStacks.getOrLast(index)!!, 161 | recipe.output 162 | ) 163 | ) 164 | } 165 | 166 | return recipeInfos 167 | } 168 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/RecipeInfos.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.item.Item 4 | import net.minecraft.item.ItemStack 5 | import net.minecraft.recipe.RecipeManager 6 | import net.minecraft.recipe.RecipeType 7 | 8 | interface RecipeInfo { 9 | val recipeBasePath: String 10 | val recipePath: String 11 | val itemStacks: List 12 | val items: List 13 | get() { 14 | return itemStacks.map { it.item }.distinct() 15 | } 16 | fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator 17 | } 18 | 19 | data class CraftingRecipeInfo( 20 | override val recipeBasePath: String, 21 | override val recipePath: String, 22 | val slot1: ItemStack?, 23 | val slot2: ItemStack?, 24 | val slot3: ItemStack?, 25 | val slot4: ItemStack?, 26 | val slot5: ItemStack?, 27 | val slot6: ItemStack?, 28 | val slot7: ItemStack?, 29 | val slot8: ItemStack?, 30 | val slot9: ItemStack?, 31 | val output: ItemStack 32 | ) : RecipeInfo { 33 | override val itemStacks: List 34 | get() { 35 | return arrayOf( 36 | slot1, 37 | slot2, 38 | slot3, 39 | slot4, 40 | slot5, 41 | slot6, 42 | slot7, 43 | slot8, 44 | slot9, 45 | output 46 | ).filterNotNull().distinct() 47 | } 48 | 49 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 50 | return CraftingRecipeImageGenerator(this, itemsData) 51 | } 52 | } 53 | 54 | data class StonecuttingRecipeInfo( 55 | override val recipeBasePath: String, 56 | override val recipePath: String, 57 | val slot: ItemStack, 58 | val output: ItemStack 59 | ) : RecipeInfo { 60 | override val itemStacks: List 61 | get() = listOf(slot, output).distinct() 62 | 63 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 64 | return StonecuttingRecipeImageGenerator(this, itemsData) 65 | } 66 | } 67 | 68 | data class SmeltingRecipeInfo( 69 | override val recipeBasePath: String, 70 | override val recipePath: String, 71 | val slot: ItemStack, 72 | val output: ItemStack 73 | ) : RecipeInfo { 74 | override val itemStacks: List 75 | get() = listOf(slot, output).distinct() 76 | 77 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 78 | return SmeltingRecipeImageGenerator(this, itemsData) 79 | } 80 | } 81 | 82 | data class BlastingRecipeInfo( 83 | override val recipeBasePath: String, 84 | override val recipePath: String, 85 | val slot: ItemStack, 86 | val output: ItemStack 87 | ) : RecipeInfo { 88 | override val itemStacks: List 89 | get() = listOf(slot, output).distinct() 90 | 91 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 92 | return BlastingRecipeImageGenerator(this, itemsData) 93 | } 94 | } 95 | 96 | data class SmokingRecipeInfo( 97 | override val recipeBasePath: String, 98 | override val recipePath: String, 99 | val slot: ItemStack, 100 | val output: ItemStack 101 | ) : RecipeInfo { 102 | override val itemStacks: List 103 | get() = listOf(slot, output).distinct() 104 | 105 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 106 | return SmokingRecipeImageGenerator(this, itemsData) 107 | } 108 | } 109 | 110 | data class CampfireCookingRecipeInfo( 111 | override val recipeBasePath: String, 112 | override val recipePath: String, 113 | val slot: ItemStack, 114 | val output: ItemStack 115 | ) : RecipeInfo { 116 | override val itemStacks: List 117 | get() = listOf(slot, output).distinct() 118 | 119 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 120 | return CampfireCookingRecipeImageGenerator(this, itemsData) 121 | } 122 | } 123 | 124 | data class SmithingRecipeInfo( 125 | override val recipeBasePath: String, 126 | override val recipePath: String, 127 | val slotBase: ItemStack, 128 | val slotAddition: ItemStack, 129 | val output: ItemStack 130 | ) : RecipeInfo { 131 | override val itemStacks: List 132 | get() = listOf(slotBase, slotAddition, output).distinct() 133 | 134 | override fun imageGenerator(itemsData: ItemsData): RecipeImageGenerator { 135 | return SmithingRecipeImageGenerator(this, itemsData) 136 | } 137 | } 138 | 139 | class RecipeInfos(recipeManager: RecipeManager) { 140 | private val craftingGroups = recipeManager.listAllOfType(RecipeType.CRAFTING) 141 | .filterNot { it.isIgnoredInRecipeBook }.map { convertCraftingRecipe(it) } 142 | private val smeltingGroups = recipeManager.listAllOfType(RecipeType.SMELTING) 143 | .filterNot { it.isIgnoredInRecipeBook }.map { convertSmeltingRecipe(it) } 144 | private val blastingGroups = recipeManager.listAllOfType(RecipeType.BLASTING) 145 | .filterNot { it.isIgnoredInRecipeBook }.map { convertBlastingRecipe(it) } 146 | private val smokingGroups = recipeManager.listAllOfType(RecipeType.SMOKING) 147 | .filterNot { it.isIgnoredInRecipeBook }.map { convertSmokingRecipe(it) } 148 | private val campfireCookingGroups = recipeManager.listAllOfType(RecipeType.CAMPFIRE_COOKING) 149 | .filterNot { it.isIgnoredInRecipeBook }.map { convertCampfireCookingRecipe(it) } 150 | private val stonecuttingGroups = recipeManager.listAllOfType(RecipeType.STONECUTTING) 151 | .filterNot { it.isIgnoredInRecipeBook }.map { convertStonecuttingRecipe(it) } 152 | private val smithingGroups = recipeManager.listAllOfType(RecipeType.SMITHING) 153 | .filterNot { it.isIgnoredInRecipeBook }.map { convertSmithingRecipe(it) } 154 | 155 | val groups = listOf( 156 | craftingGroups, 157 | smeltingGroups, 158 | blastingGroups, 159 | smokingGroups, 160 | campfireCookingGroups, 161 | stonecuttingGroups, 162 | smithingGroups 163 | ).flatten() 164 | 165 | val all = groups.flatten() 166 | 167 | val items = all.flatMap { it.items }.distinctBy { it.identifier }.sortedBy { it.identifier } 168 | 169 | val itemStacks = (all.flatMap { it.itemStacks } + items.map { ItemStack(it) }).distinctBy { it.uniqueKey } 170 | .sortedBy { it.uniqueKey } 171 | } 172 | -------------------------------------------------------------------------------- /src/main/kotlin/net/bloople/recipeimagesexporter/Util.kt: -------------------------------------------------------------------------------- 1 | package net.bloople.recipeimagesexporter 2 | 3 | import net.minecraft.client.MinecraftClient 4 | import net.minecraft.item.Item 5 | import net.minecraft.item.ItemStack 6 | import net.minecraft.text.Text 7 | import net.minecraft.util.Identifier 8 | import net.minecraft.util.registry.Registry 9 | import org.slf4j.Logger 10 | import org.slf4j.LoggerFactory 11 | import java.awt.AlphaComposite 12 | import java.awt.Color 13 | import java.awt.Graphics2D 14 | import java.awt.Image 15 | import java.awt.Rectangle 16 | import java.awt.geom.AffineTransform 17 | import java.awt.image.AffineTransformOp 18 | import java.awt.image.BufferedImage 19 | import java.awt.image.Raster 20 | import java.io.ByteArrayInputStream 21 | import java.io.InputStream 22 | import java.util.* 23 | import kotlin.math.PI 24 | import kotlin.math.ceil 25 | import kotlin.reflect.KClass 26 | 27 | fun Array.getOrLast(index: Int): T? { 28 | if(isEmpty()) return null 29 | return if (index in 0..lastIndex) get(index) else get(lastIndex) 30 | } 31 | 32 | val Item.identifier: Identifier get() = Registry.ITEM.getId(this) 33 | 34 | val Identifier.itemResourceLocation: Identifier get() = Identifier(namespace, "textures/item/$path.png") 35 | 36 | val ItemStack.uniqueKey: String get() = "${item.identifier}:$count" 37 | 38 | fun decodeBase64(input: String): InputStream { 39 | return ByteArrayInputStream(Base64.getDecoder().decode(input)) 40 | } 41 | 42 | fun Raster.createChild(parentX: Int, parentY: Int, width: Int, height: Int): Raster { 43 | return this.createChild(parentX, parentY, width, height, parentX, parentY, null) 44 | } 45 | 46 | fun BufferedImage.asARGB(): BufferedImage { 47 | if(type == BufferedImage.TYPE_INT_ARGB) return this 48 | return BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB).apply { 49 | val graphics = graphics 50 | graphics.drawImage(this@asARGB, 0, 0, null) 51 | graphics.dispose() 52 | } 53 | } 54 | 55 | fun BufferedImage.blankClone(): BufferedImage { 56 | return BufferedImage(width, height, type) 57 | } 58 | 59 | fun BufferedImage.getData(x: Int, y: Int, width: Int, height: Int): Raster { 60 | return this.getData(Rectangle(x, y, width, height)).createTranslatedChild(0, 0) 61 | } 62 | 63 | // Based on https://stackoverflow.com/a/46211880 64 | fun BufferedImage.scaleImage(w2: Int, h2: Int): BufferedImage { 65 | // Create a new image of the proper size 66 | val scalex = w2 / width.toDouble() 67 | val scaley = h2 / height.toDouble() 68 | val after = BufferedImage(w2, h2, type) 69 | val scaleInstance = AffineTransform.getScaleInstance(scalex, scaley) 70 | val scaleOp = AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BICUBIC) 71 | scaleOp.filter(this, after) 72 | return after 73 | } 74 | 75 | // Based on https://stackoverflow.com/a/46211880 76 | fun BufferedImage.scaleImage(h2: Int): BufferedImage { 77 | // Create a new image of the proper size 78 | val scaley = h2 / height.toDouble() 79 | val w2 = ceil(width.toDouble() * scaley).toInt() 80 | 81 | val after = BufferedImage(w2, h2, type) 82 | val scaleInstance = AffineTransform.getScaleInstance(scaley, scaley) 83 | val scaleOp = AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BICUBIC) 84 | scaleOp.filter(this, after) 85 | return after 86 | } 87 | 88 | // Based on https://stackoverflow.com/a/47994302 89 | fun BufferedImage.rotateImage(degrees: Double): BufferedImage { 90 | val affineTransform = AffineTransform.getRotateInstance( 91 | degrees * (PI / 180.0), 92 | width / 2.0, 93 | height / 2.0) 94 | val affineTransformOp = AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BICUBIC) 95 | return affineTransformOp.filter(this, null) 96 | } 97 | 98 | private fun createFlipTransform(mode: ImageFlipMode, imageWidth: Double, imageHeight: Double): AffineTransform { 99 | return when(mode) { 100 | ImageFlipMode.NORMAL -> AffineTransform() 101 | ImageFlipMode.TOP_BOTTOM -> { 102 | AffineTransform(doubleArrayOf(1.0, 0.0, 0.0, -1.0)).apply { translate(0.0, -imageHeight) } 103 | } 104 | ImageFlipMode.LEFT_RIGHT -> { 105 | AffineTransform(doubleArrayOf(-1.0, 0.0, 0.0, 1.0)).apply { translate(-imageWidth, 0.0) } 106 | } 107 | ImageFlipMode.TOP_BOTTOM_LEFT_RIGHT -> { 108 | AffineTransform(doubleArrayOf(-1.0, 0.0, 0.0, -1.0)).apply { translate(-imageWidth, -imageHeight) } 109 | } 110 | } 111 | } 112 | 113 | enum class ImageFlipMode { 114 | NORMAL, 115 | TOP_BOTTOM, 116 | LEFT_RIGHT, 117 | TOP_BOTTOM_LEFT_RIGHT 118 | } 119 | 120 | // Based on https://www.informit.com/articles/article.aspx?p=23667&seqNum=11 121 | 122 | fun BufferedImage.flipImage(mode: ImageFlipMode): BufferedImage { 123 | val affineTransform = 124 | createFlipTransform(mode, width.toDouble(), height.toDouble()) 125 | val affineTransformOp = AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BICUBIC) 126 | return affineTransformOp.filter(this, null) 127 | } 128 | 129 | fun BufferedImage.fillBackground(background: Color): BufferedImage { 130 | return blankClone().apply { 131 | createGraphics().use { 132 | color = background 133 | fillRect(0, 0, width, height) 134 | drawImage(this@fillBackground) 135 | } 136 | } 137 | } 138 | 139 | inline fun Graphics2D.use(block: Graphics2D.() -> R): R { 140 | try { 141 | return block(this) 142 | } 143 | finally { 144 | dispose() 145 | } 146 | } 147 | 148 | inline fun Graphics2D.applyComposite(newComposite: AlphaComposite, block: Graphics2D.() -> R): R { 149 | val oldComposite = composite 150 | composite = newComposite 151 | return block(this).apply { composite = oldComposite } 152 | } 153 | 154 | fun Graphics2D.drawImage(image: Image) { 155 | drawImage(image, 0, 0, null) 156 | } 157 | 158 | fun MinecraftClient.sendMessage(message: Text) { 159 | execute { 160 | inGameHud.chatHud.addMessage(message) 161 | narratorManager.narrate(message) 162 | } 163 | } 164 | 165 | fun MinecraftClient.sendMessage(message: String) { 166 | sendMessage(Text.literal(message)) 167 | } 168 | 169 | fun getLogger(name: String): Logger { 170 | return LoggerFactory.getLogger("$MOD_ID/$name") 171 | } 172 | 173 | fun getLogger(clazz: KClass<*>): Logger { 174 | val fullName = if(clazz.isCompanion) clazz.java.declaringClass.name 175 | else clazz.qualifiedName 176 | 177 | val name = fullName!!.removePrefix("net.bloople.recipeimagesexporter.") 178 | 179 | return getLogger(name) 180 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | --------------------------------------------------------------------------------