diff --git a/buildSrc/src/main/kotlin/core-convention.gradle.kts b/buildSrc/src/main/kotlin/core-convention.gradle.kts index 24631c194..3c8730c37 100644 --- a/buildSrc/src/main/kotlin/core-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/core-convention.gradle.kts @@ -71,7 +71,9 @@ tasks { duplicatesStrategy = DuplicatesStrategy.EXCLUDE val relocationPrefix: String by project - relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt") + relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt") { + exclude("net.kyori.adventure.nbt.api.**") + } relocate("org.spongepowered.configurate", "$relocationPrefix.configurate") } diff --git a/gradle.properties b/gradle.properties index 2fb28085c..c8fc390e5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled javaVersion=25 mcVersion=26.1.2 group=dev.slne.surf.api -version=3.19.0 +version=3.20.0 relocationPrefix=dev.slne.surf.api.libs snapshot=false diff --git a/surf-api-core/surf-api-core/api/surf-api-core.api b/surf-api-core/surf-api-core/api/surf-api-core.api index ef6c3960b..9446f8039 100644 --- a/surf-api-core/surf-api-core/api/surf-api-core.api +++ b/surf-api-core/surf-api-core/api/surf-api-core.api @@ -8902,6 +8902,9 @@ public final class dev/slne/surf/api/core/nbt/InternalNbtBridge$Companion : dev/ } public final class dev/slne/surf/api/core/nbt/Nbt_extensionKt { + public static final fun asTagHolder (Lnet/kyori/adventure/nbt/BinaryTag;)Lnet/kyori/adventure/nbt/api/BinaryTagHolder; + public static final fun decodeCompoundTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/CompoundBinaryTag; + public static final fun decodeTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/BinaryTag; public static final fun isCollectionTag (Lnet/kyori/adventure/nbt/BinaryTag;)Z public static final fun tagIterator (Lnet/kyori/adventure/nbt/ByteArrayBinaryTag;)Ljava/util/Iterator; public static final fun tagIterator (Lnet/kyori/adventure/nbt/IntArrayBinaryTag;)Ljava/util/Iterator; diff --git a/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/nbt/nbt-extension.kt b/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/nbt/nbt-extension.kt index 946523d25..2a157f8a0 100644 --- a/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/nbt/nbt-extension.kt +++ b/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/nbt/nbt-extension.kt @@ -1,10 +1,43 @@ package dev.slne.surf.api.core.nbt import net.kyori.adventure.nbt.* +import net.kyori.adventure.nbt.api.BinaryTagHolder +import net.kyori.adventure.util.Codec +import java.io.IOException import java.util.* import java.util.stream.Stream import java.util.stream.StreamSupport +private val binaryTagHolderCodec = object : Codec { + private val tagStringIO = TagStringIO.builder() + .acceptLegacy(false) + .build() + + override fun decode(encoded: String): BinaryTag { + return tagStringIO.asTag(encoded) + } + + override fun encode(decoded: BinaryTag): String { + return tagStringIO.asString(decoded) + } +} + +fun BinaryTag.asTagHolder(): BinaryTagHolder { + return BinaryTagHolder.encode(this, binaryTagHolderCodec) +} + +fun BinaryTagHolder.decodeTag(): BinaryTag { + return get(binaryTagHolderCodec) +} + +fun BinaryTagHolder.decodeCompoundTag(): CompoundBinaryTag { + val decoded = get(binaryTagHolderCodec) + if (decoded !is CompoundBinaryTag) { + error("Expected a CompoundBinaryTag, but got ${decoded::class.simpleName}") + } + return decoded +} + fun BinaryTag.isCollectionTag() = this is ListBinaryTag || this is ByteArrayBinaryTag || this is LongArrayBinaryTag || this is IntArrayBinaryTag diff --git a/surf-api-gradle-plugin/build.gradle.kts b/surf-api-gradle-plugin/build.gradle.kts index 625d90cba..c47ea602f 100644 --- a/surf-api-gradle-plugin/build.gradle.kts +++ b/surf-api-gradle-plugin/build.gradle.kts @@ -20,7 +20,7 @@ plugins { group = groupId version = buildString { - append("2.0.7") + append("2.0.8") if (snapshot) append("-SNAPSHOT") } diff --git a/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/common/CommonSurfPlugin.kt b/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/common/CommonSurfPlugin.kt index b96e0a6a9..3fd6c9db6 100644 --- a/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/common/CommonSurfPlugin.kt +++ b/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/common/CommonSurfPlugin.kt @@ -35,7 +35,7 @@ abstract class CommonSurfPlugin( "com.google.devtools.ksp" ) - private val relocations = mutableMapOf() + private val relocations = mutableListOf() private val dependencyDependentRelocations = mutableMapOf>() init { @@ -70,7 +70,15 @@ abstract class CommonSurfPlugin( } protected infix fun String.relocatesTo(to: String) { - relocations[this] = to + relocations += Relocation(this, to) + } + + protected fun relocatePackage( + from: String, + to: String, + excludes: List = emptyList(), + ) { + relocations += Relocation(from, to, excludes) } fun addRelocationsForDependency( @@ -116,8 +124,13 @@ abstract class CommonSurfPlugin( private fun Project.configure() { tasks.withType { - relocations.forEach { (from, to) -> - relocate(from, "${Constants.RELOCATION_PREFIX}.$to") + relocations.forEach { relocation -> + relocate( + relocation.from, + "${Constants.RELOCATION_PREFIX}.${relocation.to}" + ) { + relocation.excludes.forEach { exclude(it) } + } } } @@ -285,4 +298,10 @@ abstract class CommonSurfPlugin( protected open fun Project.afterEvaluated0(extension: E) { } + + private data class Relocation( + val from: String, + val to: String, + val excludes: List = emptyList(), + ) } \ No newline at end of file diff --git a/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt b/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt index 289d294d9..32dfe6415 100644 --- a/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt +++ b/surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt @@ -10,7 +10,11 @@ internal abstract class AbstractCoreSurfPlugin( init { "com.mojang.serialization" relocatesTo "mojang.serialization" "com.mojang.datafixers" relocatesTo "mojang.datafixers" - "net.kyori.adventure.nbt" relocatesTo "kyori.nbt" + relocatePackage( + from = "net.kyori.adventure.nbt", + to = "kyori.nbt", + excludes = listOf("net.kyori.adventure.nbt.api.**") + ) } final override fun Project.afterEvaluated0(extension: E) {