-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hannibal002:beta' into optimal-speed-without-ranchers
- Loading branch information
Showing
15 changed files
with
242 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/at/hannibal2/skyhanni/utils/compat/TextCompat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package at.hannibal2.skyhanni.utils.compat | ||
|
||
import net.minecraft.util.IChatComponent | ||
//#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 | ||
|
||
fun IChatComponent.getDirectlyContainedText() = | ||
//#if MC < 1.16 | ||
this.unformattedTextForChat | ||
//#elseif MC < 1.20 | ||
//$$ this.contents | ||
//#else | ||
//$$ (this.content as? PlainTextContent)?.string().orEmpty() | ||
//#endif | ||
|
||
fun IChatComponent.getFormattedTextCompat() = | ||
//#if MC < 1.16 | ||
this.formattedText | ||
//#else | ||
//$$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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
at/hannibal2/skyhanni/utils/compat/TextCompat.kt | ||
TestLegacyColorFormat.kt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
at/hannibal2/skyhanni/utils/compat/TextCompat.kt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
net.fabricmc.api.Environment net.minecraftforge.api.distmarker.OnlyIn | ||
|
||
net.fabricmc.api.EnvType net.minecraftforge.api.distmarker.Dist | ||
net.fabricmc.api.Environment net.minecraftforge.api.distmarker.OnlyIn | ||
|
Oops, something went wrong.