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

@@ -27,7 +27,7 @@ class Items : Extractor.Extractor {
val realItem: Item = item.value()
itemJson.addProperty("id", Registries.ITEM.getRawId(realItem))
itemJson.addProperty("name", Registries.ITEM.getId(realItem).toString())
itemJson.addProperty("name", Registries.ITEM.getId(realItem).toString())
itemJson.addProperty("translation_key", realItem.translationKey)
itemJson.addProperty("max_stack", realItem.maxCount)
itemJson.addProperty("max_durability", realItem.defaultStack.maxDamage)

View File

@@ -1,11 +1,11 @@
package de.snowii.extractor.extractors
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.mojang.serialization.JsonOps
import de.snowii.extractor.Extractor
import net.minecraft.recipe.Recipe
import net.minecraft.registry.RegistryOps
import net.minecraft.server.MinecraftServer
class Recipes : Extractor.Extractor {
@@ -15,40 +15,15 @@ class Recipes : Extractor.Extractor {
override fun extract(server: MinecraftServer): JsonElement {
val recipesJson = JsonArray()
val gson = Gson()
for (recipeRaw in server.recipeManager.values()) {
val recipeJson = JsonObject()
recipeJson.addProperty("name", recipeRaw.id.value.toString())
val recipe: Recipe<*> = recipeRaw.value()
recipeJson.addProperty("category", recipe.group)
recipeJson.addProperty("group", recipe.group)
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)
val recipe = recipeRaw.value
recipesJson.add(
Recipe.CODEC.encodeStart(
RegistryOps.of(JsonOps.INSTANCE, server.registryManager),
recipe
).getOrThrow()
)
}
return recipesJson
}