aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle.kts16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/compat/World.kt51
-rw-r--r--versions/1.21/buildpaths-test.txt2
-rw-r--r--versions/1.21/buildpaths.txt1
-rw-r--r--versions/1.21/src/test/kotlin/TestLegacyColorFormat.kt22
-rw-r--r--versions/1.21/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension0
-rw-r--r--versions/mapping-1.16.5-forge-1.12.2.txt3
7 files changed, 85 insertions, 10 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 400dd12b1..d833b509e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -275,6 +275,21 @@ if (target == ProjectTarget.MAIN) {
}
}
+fun includeBuildPaths(buildPathsFile: File, sourceSet: Provider<SourceSet>) {
+ if (buildPathsFile.exists()) {
+ sourceSet.get().apply {
+ val buildPaths = buildPathsFile.readText().lineSequence()
+ .map { it.substringBefore("#").trim() }
+ .filter { it.isNotBlank() }
+ .toSet()
+ kotlin.include(buildPaths)
+ java.include(buildPaths)
+ }
+ }
+}
+includeBuildPaths(file("buildpaths.txt"), sourceSets.main)
+includeBuildPaths(file("buildpaths-test.txt"), sourceSets.test)
+
tasks.withType<KotlinCompile> {
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(target.minecraftVersion.formattedJavaLanguageVersion))
}
@@ -426,6 +441,7 @@ tasks.withType<DetektCreateBaselineTask>().configureEach {
abstract class ShotApplicationJarProcessor @Inject constructor(val shots: Shots) : MinecraftJarProcessor<MinecraftJarProcessor.Spec> {
private class EnsureCompile(shots: Shots) : ShotApplicationJarProcessor(shots)
+
override fun buildSpec(context: SpecContext?): MinecraftJarProcessor.Spec? {
return object : MinecraftJarProcessor.Spec {}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/compat/World.kt b/src/main/java/at/hannibal2/skyhanni/utils/compat/World.kt
index 7916eb4e5..827e7d3cf 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/compat/World.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/compat/World.kt
@@ -1,5 +1,13 @@
package at.hannibal2.skyhanni.utils.compat
+//#if MC > 1.16
+//$$import net.minecraft.ChatFormatting
+//$$import net.minecraft.network.chat.TextColor
+//#endif
+//#if MC > 1.20
+//$$import net.minecraft.text.MutableText
+//$$import net.minecraft.text.PlainTextContent
+//#endif
import net.minecraft.client.Minecraft
import net.minecraft.client.multiplayer.WorldClient
import net.minecraft.entity.Entity
@@ -36,19 +44,44 @@ fun Minecraft.isOnMainThread() =
//$$ this.isSameThread
//#endif
+fun IChatComponent.getDirectlyContainedText() =
+//#if MC < 1.16
+ this.unformattedTextForChat
+//#elseif MC < 1.20
+//$$ this.contents
+//#else
+//$$ (this.content as? PlainTextContent)?.string() ?: ""
+//#endif
fun IChatComponent.getFormattedTextCompat() =
//#if MC < 1.16
this.formattedText
//#else
-//$$ run {
-//$$ val sb = StringBuilder()
-//$$ for (component in iterator()) {
-//$$ sb.append(component.style.formattingCode)
-//$$ sb.append(component.unformattedComponentText)
-//$$ sb.append("§r")
-//$$ }
-//$$ sb.toString()
-//$$ }
+//$$run {
+//$$ val sb = StringBuilder()
+//$$ for (component in iterator()) {
+//$$ sb.append(component.style.color?.toChatFormatting()?.toString() ?: "§r")
+//$$ sb.append(component.getDirectlyContainedText())
+//$$ sb.append("§r")
+//$$ }
+//$$ sb.toString()
+//$$}
+//$$
+//$$private val textColorLUT = ChatFormatting.entries
+//$$ .mapNotNull { formatting -> formatting.color?.let { it to formatting } }
+//$$ .toMap()
+//$$
+//$$fun TextColor.toChatFormatting(): ChatFormatting? {
+//$$ return textColorLUT[this.value]
+//$$}
+//$$
+//$$fun Component.iterator(): Sequence<Component> {
+//$$ return sequenceOf(this) + siblings.asSequence().flatMap { it.iterator() } // TODO: in theory we want to properly inherit styles here
+//$$}
+//#endif
+//#if MC > 1.20
+//$$fun MutableText.withColor(formatting: Formatting): Text {
+//$$ return this.styled { it.withColor(formatting) }
+//$$}
//#endif
object Effects {
diff --git a/versions/1.21/buildpaths-test.txt b/versions/1.21/buildpaths-test.txt
new file mode 100644
index 000000000..44c9fb263
--- /dev/null
+++ b/versions/1.21/buildpaths-test.txt
@@ -0,0 +1,2 @@
+at/hannibal2/skyhanni/utils/compat/World.kt
+TestLegacyColorFormat.kt
diff --git a/versions/1.21/buildpaths.txt b/versions/1.21/buildpaths.txt
new file mode 100644
index 000000000..2b9d32c89
--- /dev/null
+++ b/versions/1.21/buildpaths.txt
@@ -0,0 +1 @@
+at/hannibal2/skyhanni/utils/compat/World.kt
diff --git a/versions/1.21/src/test/kotlin/TestLegacyColorFormat.kt b/versions/1.21/src/test/kotlin/TestLegacyColorFormat.kt
new file mode 100644
index 000000000..f1c2323ef
--- /dev/null
+++ b/versions/1.21/src/test/kotlin/TestLegacyColorFormat.kt
@@ -0,0 +1,22 @@
+import net.minecraft.text.Text
+import net.minecraft.util.Formatting
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
+import at.hannibal2.skyhanni.utils.compat.*
+
+class TestLegacyColorFormat {
+ @Test
+ fun testLegacyColorFormatString() {
+ val text = Text.literal("")
+ .append(Text.literal("[").withColor(Formatting.DARK_GRAY))
+ .append(Text.literal("302").withColor(Formatting.BLUE))
+ .append(Text.literal("] ").withColor(Formatting.DARK_GRAY))
+ .append(Text.literal("♫ ").withColor(Formatting.GOLD))
+ .append(Text.literal("[MVP").withColor(Formatting.AQUA))
+ .append(Text.literal("+").withColor(Formatting.LIGHT_PURPLE))
+ .append(Text.literal("] lrg89").withColor(Formatting.AQUA))
+ .append(Text.literal(": test").withColor(Formatting.WHITE))
+ Assertions.assertEquals("§r§r§8[§r§9302§r§8] §r§6♫ §r§b[MVP§r§d+§r§b] lrg89§r§f: test§r", text.getFormattedTextCompat())
+ }
+
+}
diff --git a/versions/1.21/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension b/versions/1.21/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/versions/1.21/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
diff --git a/versions/mapping-1.16.5-forge-1.12.2.txt b/versions/mapping-1.16.5-forge-1.12.2.txt
index 71f6c71d2..4bb76b4cd 100644
--- a/versions/mapping-1.16.5-forge-1.12.2.txt
+++ b/versions/mapping-1.16.5-forge-1.12.2.txt
@@ -1,4 +1,3 @@
-
com.mojang.blaze3d.systems.RenderSystem net.minecraft.client.renderer.GlStateManager
com.mojang.blaze3d.systems.RenderSystem color4f() color()
com.mojang.blaze3d.systems.RenderSystem translatef() translate()
@@ -156,6 +155,8 @@ net.minecraft.world.entity.Entity yo posY
net.minecraft.world.entity.Entity zOld prevPosZ
net.minecraft.world.entity.Entity zo posZ
+net.minecraft.world.effect.MobEffects net.minecraft.init.PotionTypes
+
net.minecraft.world.entity.EquipmentSlot net.minecraft.inventory.EntityEquipmentSlot
net.minecraft.world.entity.LivingEntity getEffect() getActivePotionEffect()