Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/kotlin/com/steelextractor/extractors/Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package com.steelextractor.extractors
import com.google.gson.JsonArray
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import com.mojang.serialization.JsonOps
import com.steelextractor.SteelExtractor
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.resources.ResourceKey
import net.minecraft.server.MinecraftServer
import net.minecraft.sounds.SoundEvent
import net.minecraft.tags.TagKey
import net.minecraft.util.valueproviders.IntProvider
import net.minecraft.util.valueproviders.IntProviders
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntitySpawnReason
import net.minecraft.world.entity.EntityType
Expand All @@ -35,13 +38,17 @@ class Classes : SteelExtractor.Extractor {
}

/// Serialize a field value into the JSON object based on its type.
/// Primitives, enums, and registry entries are serialized directly.
/// Primitives, value providers, enums, and registry entries are serialized directly.
/// Unknown object types are recursed into (one level deep) to extract their fields.
private fun trySerialize(value: Any, key: String, json: JsonObject, depth: Int) {
when (value) {
is Boolean -> json.addProperty(key, value)
is Number -> json.addProperty(key, value)
is String -> json.addProperty(key, value)
is IntProvider -> json.add(
key,
IntProviders.CODEC.encodeStart(JsonOps.INSTANCE, value).getOrThrow()
)
is Enum<*> -> json.addProperty(key, value.name.lowercase())
is Fluid -> BuiltInRegistries.FLUID.getKey(value)?.path?.let { json.addProperty(key, it) }
is SoundEvent -> BuiltInRegistries.SOUND_EVENT.getKey(value)?.path?.let { json.addProperty(key, it) }
Expand Down
Loading