Extractor: Export Recipes

This commit is contained in:
Snowiiii 2024-11-08 16:48:33 +01:00
parent 2f6f11673b
commit df1d5fb580
3 changed files with 18564 additions and 35 deletions

18554
assets/recipes.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package de.snowii.extractor.extractors package de.snowii.extractor.extractors
import com.google.gson.Gson
import com.google.gson.JsonArray import com.google.gson.JsonArray
import com.google.gson.JsonElement import com.google.gson.JsonElement
import com.google.gson.JsonObject import com.mojang.serialization.JsonOps
import de.snowii.extractor.Extractor import de.snowii.extractor.Extractor
import net.minecraft.recipe.Recipe import net.minecraft.recipe.Recipe
import net.minecraft.registry.RegistryOps
import net.minecraft.server.MinecraftServer import net.minecraft.server.MinecraftServer
class Recipes : Extractor.Extractor { class Recipes : Extractor.Extractor {
@ -15,40 +15,15 @@ class Recipes : Extractor.Extractor {
override fun extract(server: MinecraftServer): JsonElement { override fun extract(server: MinecraftServer): JsonElement {
val recipesJson = JsonArray() val recipesJson = JsonArray()
val gson = Gson()
for (recipeRaw in server.recipeManager.values()) { for (recipeRaw in server.recipeManager.values()) {
val recipeJson = JsonObject() val recipe = recipeRaw.value
recipesJson.add(
recipeJson.addProperty("name", recipeRaw.id.value.toString()) Recipe.CODEC.encodeStart(
val recipe: Recipe<*> = recipeRaw.value() RegistryOps.of(JsonOps.INSTANCE, server.registryManager),
recipeJson.addProperty("category", recipe.group) recipe
recipeJson.addProperty("group", recipe.group) ).getOrThrow()
recipeJson.addProperty("type", recipe.type.toString()) )
val placementArray = JsonArray()
for (slot in recipe.ingredientPlacement.placementSlots) {
val placementJson = JsonObject()
if (slot.isPresent) {
placementJson.addProperty("position", slot.orElseThrow().placerOutputPosition)
}
placementArray.add(placementJson)
}
recipeJson.add("placementSlots", placementArray)
val ingredientArray = JsonArray()
for (ingredient in recipe.ingredientPlacement.ingredients) {
if (ingredient != null) {
val items = ingredient.matchingItems
val ingredientJson = JsonObject()
for (item in items) {
ingredientJson.addProperty("id", item.idAsString)
}
ingredientArray.add(ingredientJson)
}
}
recipeJson.add("ingredients", ingredientArray)
recipesJson.add(recipeJson)
} }
return recipesJson return recipesJson
} }