Extractor: Make Recipes work
This commit is contained in:
parent
1b510eaa21
commit
b090c34228
@ -47,7 +47,7 @@ class Extractor : ModInitializer {
|
||||
try {
|
||||
val out = outputDirectory.resolve(ext.fileName())
|
||||
val fileWriter = FileWriter(out.toFile(), StandardCharsets.UTF_8)
|
||||
gson.toJson(ext.extract(server.registryManager), fileWriter)
|
||||
gson.toJson(ext.extract(server), fileWriter)
|
||||
fileWriter.close()
|
||||
logger.info("Wrote " + out.toAbsolutePath())
|
||||
} catch (e: java.lang.Exception) {
|
||||
@ -61,6 +61,6 @@ class Extractor : ModInitializer {
|
||||
fun fileName(): String
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement
|
||||
fun extract(server: MinecraftServer): JsonElement
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@ import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import de.snowii.extractor.Extractor
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.registry.Registries
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Box
|
||||
import net.minecraft.world.EmptyBlockView
|
||||
@ -17,7 +17,7 @@ class Blocks : Extractor.Extractor {
|
||||
return "blocks.json"
|
||||
}
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val topLevelJson = JsonObject()
|
||||
|
||||
val blocksJson = JsonArray()
|
||||
|
||||
@ -7,9 +7,9 @@ import com.mojang.serialization.JsonOps
|
||||
import de.snowii.extractor.Extractor
|
||||
import net.minecraft.component.ComponentMap
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.registry.RegistryKeys
|
||||
import net.minecraft.registry.RegistryOps
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
|
||||
class Items : Extractor.Extractor {
|
||||
@ -18,10 +18,10 @@ class Items : Extractor.Extractor {
|
||||
}
|
||||
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val itemsJson = JsonArray()
|
||||
|
||||
for (item in registryManager.getOrThrow(RegistryKeys.ITEM).streamEntries().toList()) {
|
||||
for (item in server.registryManager.getOrThrow(RegistryKeys.ITEM).streamEntries().toList()) {
|
||||
val itemJson = JsonObject()
|
||||
|
||||
itemJson.addProperty("id", item.key.orElseThrow().value.toString())
|
||||
@ -35,7 +35,7 @@ class Items : Extractor.Extractor {
|
||||
itemJson.add(
|
||||
"components",
|
||||
ComponentMap.CODEC.encodeStart(
|
||||
RegistryOps.of(JsonOps.INSTANCE, registryManager),
|
||||
RegistryOps.of(JsonOps.INSTANCE, server.registryManager),
|
||||
realItem.components
|
||||
).getOrThrow()
|
||||
)
|
||||
|
||||
@ -10,6 +10,7 @@ import net.minecraft.network.listener.PacketListener
|
||||
import net.minecraft.network.packet.PacketType
|
||||
import net.minecraft.network.state.*
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
|
||||
class Packet : Extractor.Extractor {
|
||||
@ -17,7 +18,7 @@ class Packet : Extractor.Extractor {
|
||||
return "packets.json"
|
||||
}
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val packetsJson = JsonArray()
|
||||
|
||||
serializeFactory(HandshakeStates.C2S_FACTORY, packetsJson)
|
||||
|
||||
@ -7,6 +7,7 @@ import de.snowii.extractor.Extractor
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.registry.Registries
|
||||
import net.minecraft.registry.RegistryKeys
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
|
||||
class Particles : Extractor.Extractor {
|
||||
@ -14,7 +15,7 @@ class Particles : Extractor.Extractor {
|
||||
return "particles.json"
|
||||
}
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val particlesJson = JsonArray()
|
||||
|
||||
for (particle in Registries.PARTICLE_TYPE) {
|
||||
|
||||
@ -8,25 +8,47 @@ import de.snowii.extractor.Extractor
|
||||
import net.minecraft.recipe.Recipe
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.registry.RegistryKeys
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
class Recipes : Extractor.Extractor {
|
||||
override fun fileName(): String {
|
||||
return "recipes.json"
|
||||
}
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val recipesJson = JsonArray()
|
||||
val gson = Gson()
|
||||
|
||||
for (recipeRaw in registryManager.getOrThrow(RegistryKeys.RECIPE).streamEntries().toList()) {
|
||||
for (recipeRaw in server.recipeManager.values()) {
|
||||
val recipeJson = JsonObject()
|
||||
|
||||
recipeJson.addProperty("id", recipeRaw.key.orElseThrow().value.toString())
|
||||
recipeJson.addProperty("name", recipeRaw.key.orElseThrow().value.toString())
|
||||
recipeJson.addProperty("name", recipeRaw.id.value.toString())
|
||||
val recipe: Recipe<*> = recipeRaw.value()
|
||||
recipeJson.addProperty("group", recipe.group)
|
||||
recipeJson.addProperty("ingredients", gson.toJson(recipe.ingredientPlacement.ingredients))
|
||||
recipeJson.addProperty("placementSlots", gson.toJson(recipe.ingredientPlacement.placementSlots))
|
||||
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);
|
||||
// recipeJson.addProperty("placementSlots", gson.toJson(recipe.ingredientPlacement.placementSlots))
|
||||
|
||||
recipesJson.add(recipeJson)
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.google.gson.JsonObject
|
||||
import de.snowii.extractor.Extractor
|
||||
import net.minecraft.registry.DynamicRegistryManager
|
||||
import net.minecraft.registry.Registries
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
||||
|
||||
class Sounds : Extractor.Extractor {
|
||||
@ -13,7 +14,7 @@ class Sounds : Extractor.Extractor {
|
||||
return "sounds.json"
|
||||
}
|
||||
|
||||
override fun extract(registryManager: DynamicRegistryManager.Immutable): JsonElement {
|
||||
override fun extract(server: MinecraftServer): JsonElement {
|
||||
val itemsJson = JsonArray()
|
||||
|
||||
for (sound in Registries.SOUND_EVENT) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user