feat(dev): add more elaborate automatic texture exporter (stealthisfit)
This commit is contained in:
@@ -2,6 +2,7 @@ package moe.nea.firmament.util
|
||||
|
||||
import io.github.moulberry.repo.data.Coordinate
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.gui.hud.InGameHud
|
||||
import net.minecraft.client.gui.screen.Screen
|
||||
@@ -16,10 +17,14 @@ import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
|
||||
import net.minecraft.registry.BuiltinRegistries
|
||||
import net.minecraft.registry.Registry
|
||||
import net.minecraft.registry.RegistryKey
|
||||
import net.minecraft.registry.RegistryKeys
|
||||
import net.minecraft.registry.RegistryWrapper
|
||||
import net.minecraft.registry.entry.RegistryEntry
|
||||
import net.minecraft.resource.ReloadableResourceManagerImpl
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.World
|
||||
import moe.nea.firmament.events.TickEvent
|
||||
@@ -120,6 +125,19 @@ object MC {
|
||||
return field
|
||||
}
|
||||
private set
|
||||
|
||||
|
||||
fun <T> unsafeGetRegistryEntry(registry: RegistryKey<out Registry<T>>, identifier: Identifier) =
|
||||
unsafeGetRegistryEntry(RegistryKey.of(registry, identifier))
|
||||
|
||||
|
||||
fun <T> unsafeGetRegistryEntry(registryKey: RegistryKey<T>): T? {
|
||||
return currentOrDefaultRegistries
|
||||
.getOrThrow(registryKey.registryRef)
|
||||
.getOptional(registryKey)
|
||||
.getOrNull()
|
||||
?.value()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
91
src/main/kotlin/util/mc/NbtPrism.kt
Normal file
91
src/main/kotlin/util/mc/NbtPrism.kt
Normal file
@@ -0,0 +1,91 @@
|
||||
package moe.nea.firmament.util.mc
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonPrimitive
|
||||
import com.mojang.brigadier.StringReader
|
||||
import com.mojang.brigadier.arguments.ArgumentType
|
||||
import com.mojang.brigadier.arguments.StringArgumentType
|
||||
import com.mojang.brigadier.context.CommandContext
|
||||
import com.mojang.brigadier.suggestion.Suggestions
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder
|
||||
import com.mojang.serialization.JsonOps
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import kotlin.collections.indices
|
||||
import kotlin.collections.map
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.nbt.NbtElement
|
||||
import net.minecraft.nbt.NbtList
|
||||
import net.minecraft.nbt.NbtOps
|
||||
import net.minecraft.nbt.NbtString
|
||||
import moe.nea.firmament.util.Base64Util
|
||||
|
||||
class NbtPrism(val path: List<String>) {
|
||||
companion object {
|
||||
fun fromElement(path: JsonElement): NbtPrism? {
|
||||
if (path is JsonArray) {
|
||||
return NbtPrism(path.map { (it as JsonPrimitive).asString })
|
||||
} else if (path is JsonPrimitive && path.isString) {
|
||||
return NbtPrism(path.asString.split("."))
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
object Argument : ArgumentType<NbtPrism> {
|
||||
override fun parse(reader: StringReader): NbtPrism? {
|
||||
return fromElement(JsonPrimitive(StringArgumentType.string().parse(reader)))
|
||||
}
|
||||
|
||||
override fun getExamples(): Collection<String?>? {
|
||||
return listOf("some.nbt.path", "some.other.*", "some.path.*json.in.a.json.string")
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "Prism($path)"
|
||||
}
|
||||
|
||||
fun access(root: NbtElement): Collection<NbtElement> {
|
||||
var rootSet = mutableListOf(root)
|
||||
var switch = mutableListOf<NbtElement>()
|
||||
for (pathSegment in path) {
|
||||
if (pathSegment == ".") continue
|
||||
if (pathSegment != "*" && pathSegment.startsWith("*")) {
|
||||
if (pathSegment == "*json") {
|
||||
for (element in rootSet) {
|
||||
val eString = element.asString().getOrNull() ?: continue
|
||||
val element = Gson().fromJson(eString, JsonElement::class.java)
|
||||
switch.add(JsonOps.INSTANCE.convertTo(NbtOps.INSTANCE, element))
|
||||
}
|
||||
} else if (pathSegment == "*base64") {
|
||||
for (element in rootSet) {
|
||||
val string = element.asString().getOrNull() ?: continue
|
||||
switch.add(NbtString.of(Base64Util.decodeString(string)))
|
||||
}
|
||||
}
|
||||
}
|
||||
for (element in rootSet) {
|
||||
if (element is NbtList) {
|
||||
if (pathSegment == "*")
|
||||
switch.addAll(element)
|
||||
val index = pathSegment.toIntOrNull() ?: continue
|
||||
if (index !in element.indices) continue
|
||||
switch.add(element[index])
|
||||
}
|
||||
if (element is NbtCompound) {
|
||||
if (pathSegment == "*")
|
||||
element.keys.mapTo(switch) { element.get(it)!! }
|
||||
switch.add(element.get(pathSegment) ?: continue)
|
||||
}
|
||||
}
|
||||
val temp = switch
|
||||
switch = rootSet
|
||||
rootSet = temp
|
||||
switch.clear()
|
||||
}
|
||||
return rootSet
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user