aboutsummaryrefslogtreecommitdiff
path: root/src/texturePacks/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/texturePacks/java')
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt4
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt3
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomTextReplacements.kt56
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/StringMatcher.kt308
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt79
-rw-r--r--src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/SkullPredicate.kt2
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/CustomSkullTexturePatch.java4
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceTextsInDrawContext.java55
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java6
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceAnvilScreen.java6
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceFurnaceBackgrounds.java5
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplacePlayerBackgrounds.java11
-rw-r--r--src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceTextColorInHandledScreen.java17
13 files changed, 396 insertions, 160 deletions
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
index 8a2bde5..f731982 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomGlobalArmorOverrides.kt
@@ -85,7 +85,9 @@ object CustomGlobalArmorOverrides {
false,
false,
false,
- false
+ false,
+ false,
+ null
)
}
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
index 4785e90..69a1c7e 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomScreenLayouts.kt
@@ -4,6 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.minecraft.client.font.TextRenderer
+import net.minecraft.client.gl.RenderPipelines
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.HandledScreen
@@ -82,7 +83,7 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
val textureWidth = this.width
val textureHeight = this.height
context.drawTexture(
- RenderLayer::getGuiTextured,
+ RenderPipelines.GUI_TEXTURED,
this.texture,
modifiedX,
modifiedY,
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomTextReplacements.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomTextReplacements.kt
new file mode 100644
index 0000000..8f7fc06
--- /dev/null
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomTextReplacements.kt
@@ -0,0 +1,56 @@
+package moe.nea.firmament.features.texturepack
+
+import net.minecraft.resource.ResourceManager
+import net.minecraft.resource.SinglePreparationResourceReloader
+import net.minecraft.text.Text
+import net.minecraft.util.profiler.Profiler
+import moe.nea.firmament.Firmament
+import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.events.FinalizeResourceManagerEvent
+import moe.nea.firmament.util.ErrorUtil.intoCatch
+
+object CustomTextReplacements : SinglePreparationResourceReloader<List<TreeishTextReplacer>>() {
+
+ override fun prepare(
+ manager: ResourceManager,
+ profiler: Profiler
+ ): List<TreeishTextReplacer> {
+ return manager.findResources("overrides/texts") { it.namespace == "firmskyblock" && it.path.endsWith(".json") }
+ .mapNotNull {
+ Firmament.tryDecodeJsonFromStream<TreeishTextReplacer>(it.value.inputStream)
+ .intoCatch("Failed to load text override from ${it.key}").orNull()
+ }
+ }
+
+ var textReplacers: List<TreeishTextReplacer> = listOf()
+
+ override fun apply(
+ prepared: List<TreeishTextReplacer>,
+ manager: ResourceManager,
+ profiler: Profiler
+ ) {
+ this.textReplacers = prepared
+ }
+
+ @JvmStatic
+ fun replaceTexts(texts: List<Text>): List<Text> {
+ return texts.map { replaceText(it) }
+ }
+
+ @JvmStatic
+ fun replaceText(text: Text): Text {
+ // TODO: add a config option for this
+ val rawText = text.string
+ var text = text
+ for (replacer in textReplacers) {
+ if (!replacer.match.matches(rawText)) continue
+ text = replacer.replaceText(text)
+ }
+ return text
+ }
+
+ @Subscribe
+ fun onReloadStart(event: FinalizeResourceManagerEvent) {
+ event.resourceManager.registerReloader(this)
+ }
+}
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/StringMatcher.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/StringMatcher.kt
index dd28d9f..863ca3b 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/StringMatcher.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/StringMatcher.kt
@@ -1,4 +1,3 @@
-
package moe.nea.firmament.features.texturepack
import com.google.gson.JsonArray
@@ -13,148 +12,191 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
-import kotlin.jvm.optionals.getOrNull
import net.minecraft.nbt.NbtString
import net.minecraft.text.Text
-import moe.nea.firmament.util.MC
import moe.nea.firmament.util.removeColorCodes
@Serializable(with = StringMatcher.Serializer::class)
interface StringMatcher {
- fun matches(string: String): Boolean
- fun matches(text: Text): Boolean {
- return matches(text.string)
- }
-
- fun matches(nbt: NbtString): Boolean {
- val string = nbt.value
- val jsonStart = string.indexOf('{')
- val stringStart = string.indexOf('"')
- val isString = stringStart >= 0 && string.subSequence(0, stringStart).isBlank()
- val isJson = jsonStart >= 0 && string.subSequence(0, jsonStart).isBlank()
- if (isString || isJson)
- return matches(Text.Serialization.fromJson(string, MC.defaultRegistries) ?: return false)
- return matches(string)
- }
-
- class Equals(input: String, val stripColorCodes: Boolean) : StringMatcher {
- private val expected = if (stripColorCodes) input.removeColorCodes() else input
- override fun matches(string: String): Boolean {
- return expected == (if (stripColorCodes) string.removeColorCodes() else string)
- }
-
- override fun toString(): String {
- return "Equals($expected, stripColorCodes = $stripColorCodes)"
- }
- }
-
- class Pattern(val patternWithColorCodes: String, val stripColorCodes: Boolean) : StringMatcher {
- private val regex: Predicate<String> = patternWithColorCodes.toPattern().asMatchPredicate()
- override fun matches(string: String): Boolean {
- return regex.test(if (stripColorCodes) string.removeColorCodes() else string)
- }
-
- override fun toString(): String {
- return "Pattern($patternWithColorCodes, stripColorCodes = $stripColorCodes)"
- }
- }
-
- object Serializer : KSerializer<StringMatcher> {
- val delegateSerializer = kotlinx.serialization.json.JsonElement.serializer()
- override val descriptor: SerialDescriptor
- get() = SerialDescriptor("StringMatcher", delegateSerializer.descriptor)
-
- override fun deserialize(decoder: Decoder): StringMatcher {
- val delegate = decoder.decodeSerializableValue(delegateSerializer)
- val gsonDelegate = delegate.intoGson()
- return parse(gsonDelegate)
- }
-
- override fun serialize(encoder: Encoder, value: StringMatcher) {
- encoder.encodeSerializableValue(delegateSerializer, serialize(value).intoKotlinJson())
- }
-
- }
-
- companion object {
- fun serialize(stringMatcher: StringMatcher): JsonElement {
- TODO("Cannot serialize string matchers rn")
- }
-
- fun parse(jsonElement: JsonElement): StringMatcher {
- if (jsonElement is JsonPrimitive) {
- return Equals(jsonElement.asString, true)
- }
- if (jsonElement is JsonObject) {
- val regex = jsonElement["regex"] as JsonPrimitive?
- val text = jsonElement["equals"] as JsonPrimitive?
- val shouldStripColor = when (val color = (jsonElement["color"] as JsonPrimitive?)?.asString) {
- "preserve" -> false
- "strip", null -> true
- else -> error("Unknown color preservation mode: $color")
- }
- if ((regex == null) == (text == null)) error("Could not parse $jsonElement as string matcher")
- if (regex != null)
- return Pattern(regex.asString, shouldStripColor)
- if (text != null)
- return Equals(text.asString, shouldStripColor)
- }
- error("Could not parse $jsonElement as a string matcher")
- }
- }
+ fun matches(string: String): Boolean
+ fun matches(text: Text): Boolean {
+ return matches(text.string)
+ }
+
+ val asRegex: java.util.regex.Pattern
+
+ fun matchWithGroups(string: String): MatchNamedGroupCollection?
+
+ fun matches(nbt: NbtString): Boolean {
+ val string = nbt.value
+ val jsonStart = string.indexOf('{')
+ val stringStart = string.indexOf('"')
+ val isString = stringStart >= 0 && string.subSequence(0, stringStart).isBlank()
+ val isJson = jsonStart >= 0 && string.subSequence(0, jsonStart).isBlank()
+ if (isString || isJson) {
+ // TODO: return matches(TextCodecs.CODEC.parse(MC.defaultRegistryNbtOps, string) ?: return false)
+ }
+ return matches(string)
+ }
+
+ class Equals(input: String, val stripColorCodes: Boolean) : StringMatcher {
+ override val asRegex by lazy(LazyThreadSafetyMode.PUBLICATION) { input.toPattern(java.util.regex.Pattern.LITERAL) }
+ private val expected = if (stripColorCodes) input.removeColorCodes() else input
+ override fun matches(string: String): Boolean {
+ return expected == (if (stripColorCodes) string.removeColorCodes() else string)
+ }
+
+ override fun matchWithGroups(string: String): MatchNamedGroupCollection? {
+ if (matches(string))
+ return object : MatchNamedGroupCollection {
+ override fun get(name: String): MatchGroup? {
+ return null
+ }
+
+ override fun get(index: Int): MatchGroup? {
+ return null
+ }
+
+ override val size: Int
+ get() = 0
+
+ override fun isEmpty(): Boolean {
+ return true
+ }
+
+ override fun contains(element: MatchGroup?): Boolean {
+ return false
+ }
+
+ override fun iterator(): Iterator<MatchGroup?> {
+ return emptyList<MatchGroup>().iterator()
+ }
+
+ override fun containsAll(elements: Collection<MatchGroup?>): Boolean {
+ return elements.isEmpty()
+ }
+ }
+ return null
+ }
+
+ override fun toString(): String {
+ return "Equals($expected, stripColorCodes = $stripColorCodes)"
+ }
+ }
+
+ class Pattern(val patternWithColorCodes: String, val stripColorCodes: Boolean) : StringMatcher {
+ private val pattern = patternWithColorCodes.toRegex()
+ override val asRegex = pattern.toPattern()
+ override fun matches(string: String): Boolean {
+ return pattern.matches(if (stripColorCodes) string.removeColorCodes() else string)
+ }
+
+ override fun matchWithGroups(string: String): MatchNamedGroupCollection? {
+ return pattern.matchEntire(if (stripColorCodes) string.removeColorCodes() else string)?.groups as MatchNamedGroupCollection?
+ }
+
+ override fun toString(): String {
+ return "Pattern($patternWithColorCodes, stripColorCodes = $stripColorCodes)"
+ }
+ }
+
+ object Serializer : KSerializer<StringMatcher> {
+ val delegateSerializer = kotlinx.serialization.json.JsonElement.serializer()
+ override val descriptor: SerialDescriptor
+ get() = SerialDescriptor("StringMatcher", delegateSerializer.descriptor)
+
+ override fun deserialize(decoder: Decoder): StringMatcher {
+ val delegate = decoder.decodeSerializableValue(delegateSerializer)
+ val gsonDelegate = delegate.intoGson()
+ return parse(gsonDelegate)
+ }
+
+ override fun serialize(encoder: Encoder, value: StringMatcher) {
+ encoder.encodeSerializableValue(delegateSerializer, serialize(value).intoKotlinJson())
+ }
+
+ }
+
+ companion object {
+ fun serialize(stringMatcher: StringMatcher): JsonElement {
+ TODO("Cannot serialize string matchers rn")
+ }
+
+ fun parse(jsonElement: JsonElement): StringMatcher {
+ if (jsonElement is JsonPrimitive) {
+ return Equals(jsonElement.asString, true)
+ }
+ if (jsonElement is JsonObject) {
+ val regex = jsonElement["regex"] as JsonPrimitive?
+ val text = jsonElement["equals"] as JsonPrimitive?
+ val shouldStripColor = when (val color = (jsonElement["color"] as JsonPrimitive?)?.asString) {
+ "preserve" -> false
+ "strip", null -> true
+ else -> error("Unknown color preservation mode: $color")
+ }
+ if ((regex == null) == (text == null)) error("Could not parse $jsonElement as string matcher")
+ if (regex != null)
+ return Pattern(regex.asString, shouldStripColor)
+ if (text != null)
+ return Equals(text.asString, shouldStripColor)
+ }
+ error("Could not parse $jsonElement as a string matcher")
+ }
+ }
}
fun JsonElement.intoKotlinJson(): kotlinx.serialization.json.JsonElement {
- when (this) {
- is JsonNull -> return kotlinx.serialization.json.JsonNull
- is JsonObject -> {
- return kotlinx.serialization.json.JsonObject(this.entrySet()
- .associate { it.key to it.value.intoKotlinJson() })
- }
-
- is JsonArray -> {
- return kotlinx.serialization.json.JsonArray(this.map { it.intoKotlinJson() })
- }
-
- is JsonPrimitive -> {
- if (this.isString)
- return kotlinx.serialization.json.JsonPrimitive(this.asString)
- if (this.isBoolean)
- return kotlinx.serialization.json.JsonPrimitive(this.asBoolean)
- return kotlinx.serialization.json.JsonPrimitive(this.asNumber)
- }
-
- else -> error("Unknown json variant $this")
- }
+ when (this) {
+ is JsonNull -> return kotlinx.serialization.json.JsonNull
+ is JsonObject -> {
+ return kotlinx.serialization.json.JsonObject(
+ this.entrySet()
+ .associate { it.key to it.value.intoKotlinJson() })
+ }
+
+ is JsonArray -> {
+ return kotlinx.serialization.json.JsonArray(this.map { it.intoKotlinJson() })
+ }
+
+ is JsonPrimitive -> {
+ if (this.isString)
+ return kotlinx.serialization.json.JsonPrimitive(this.asString)
+ if (this.isBoolean)
+ return kotlinx.serialization.json.JsonPrimitive(this.asBoolean)
+ return kotlinx.serialization.json.JsonPrimitive(this.asNumber)
+ }
+
+ else -> error("Unknown json variant $this")
+ }
}
fun kotlinx.serialization.json.JsonElement.intoGson(): JsonElement {
- when (this) {
- is kotlinx.serialization.json.JsonNull -> return JsonNull.INSTANCE
- is kotlinx.serialization.json.JsonPrimitive -> {
- if (this.isString)
- return JsonPrimitive(this.content)
- if (this.content == "true")
- return JsonPrimitive(true)
- if (this.content == "false")
- return JsonPrimitive(false)
- return JsonPrimitive(LazilyParsedNumber(this.content))
- }
-
- is kotlinx.serialization.json.JsonObject -> {
- val obj = JsonObject()
- for ((k, v) in this) {
- obj.add(k, v.intoGson())
- }
- return obj
- }
-
- is kotlinx.serialization.json.JsonArray -> {
- val arr = JsonArray()
- for (v in this) {
- arr.add(v.intoGson())
- }
- return arr
- }
- }
+ when (this) {
+ is kotlinx.serialization.json.JsonNull -> return JsonNull.INSTANCE
+ is kotlinx.serialization.json.JsonPrimitive -> {
+ if (this.isString)
+ return JsonPrimitive(this.content)
+ if (this.content == "true")
+ return JsonPrimitive(true)
+ if (this.content == "false")
+ return JsonPrimitive(false)
+ return JsonPrimitive(LazilyParsedNumber(this.content))
+ }
+
+ is kotlinx.serialization.json.JsonObject -> {
+ val obj = JsonObject()
+ for ((k, v) in this) {
+ obj.add(k, v.intoGson())
+ }
+ return obj
+ }
+
+ is kotlinx.serialization.json.JsonArray -> {
+ val arr = JsonArray()
+ for (v in this) {
+ arr.add(v.intoGson())
+ }
+ return arr
+ }
+ }
}
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt
new file mode 100644
index 0000000..a9ac6d9
--- /dev/null
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/TreeishTextReplacer.kt
@@ -0,0 +1,79 @@
+package moe.nea.firmament.features.texturepack
+
+import java.util.regex.Matcher
+import util.json.CodecSerializer
+import kotlinx.serialization.Serializable
+import net.minecraft.text.Style
+import net.minecraft.text.Text
+import net.minecraft.text.TextCodecs
+import moe.nea.firmament.util.directLiteralStringContent
+import moe.nea.firmament.util.transformEachRecursively
+
+@Serializable
+data class TreeishTextReplacer(
+ val match: StringMatcher,
+ val replacements: List<SubPartReplacement>
+) {
+ @Serializable
+ data class SubPartReplacement(
+ val match: StringMatcher,
+ val style: @Serializable(StyleSerializer::class) Style? = null,
+ val replace: @Serializable(TextSerializer::class) Text,
+ )
+
+ object TextSerializer : CodecSerializer<Text>(TextCodecs.CODEC)
+ object StyleSerializer : CodecSerializer<Style>(Style.Codecs.CODEC)
+ companion object {
+ val pattern = "[$]\\{(?<name>[^}]+)}".toPattern()
+ fun injectMatchResults(text: Text, matches: Matcher): Text {
+ return text.transformEachRecursively { it ->
+ val content = it.directLiteralStringContent ?: return@transformEachRecursively it
+ val matcher = pattern.matcher(content)
+ val builder = StringBuilder()
+ while (matcher.find()) {
+ matcher.appendReplacement(builder, matches.group(matcher.group("name")).toString())
+ }
+ matcher.appendTail(builder)
+ Text.literal(builder.toString()).setStyle(it.style)
+ }
+ }
+ }
+
+ fun match(text: Text): Boolean {
+ return match.matches(text)
+ }
+
+ fun replaceText(text: Text): Text {
+ return text.transformEachRecursively { part ->
+ var part: Text = part
+ for (replacement in replacements) {
+ val rawPartText = part.string
+ replacement.style?.let { expectedStyle ->
+ val parentStyle = part.style
+ val parented = expectedStyle.withParent(parentStyle)
+ if (parented.isStrikethrough != parentStyle.isStrikethrough
+ || parented.isObfuscated != parentStyle.isObfuscated
+ || parented.isBold != parentStyle.isBold
+ || parented.isUnderlined != parentStyle.isUnderlined
+ || parented.isItalic != parentStyle.isItalic
+ || parented.color?.rgb != parentStyle.color?.rgb)
+ continue
+ }
+ val matcher = replacement.match.asRegex.matcher(rawPartText)
+ if (!matcher.find()) continue
+ val p = Text.literal("")
+ p.setStyle(part.style)
+ var lastAppendPosition = 0
+ do {
+ p.append(rawPartText.substring(lastAppendPosition, matcher.start()))
+ lastAppendPosition = matcher.end()
+ p.append(injectMatchResults(replacement.replace, matcher))
+ } while (matcher.find())
+ p.append(rawPartText.substring(lastAppendPosition))
+ part = p
+ }
+ part
+ }
+ }
+
+}
diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/SkullPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/SkullPredicate.kt
index 416e86c..f17582d 100644
--- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/SkullPredicate.kt
+++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/SkullPredicate.kt
@@ -42,7 +42,7 @@ class SkullPredicate(
}
when {
profileId != null
- && profileId != profile.id.getOrNull() ->
+ && profileId != profile.uuid.getOrNull() ->
return false
textureValue != null
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/CustomSkullTexturePatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/CustomSkullTexturePatch.java
index fede766..cc59d99 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/CustomSkullTexturePatch.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/CustomSkullTexturePatch.java
@@ -16,11 +16,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(SkullBlockEntityRenderer.class)
public class CustomSkullTexturePatch {
@Inject(
- method = "getRenderLayer(Lnet/minecraft/block/SkullBlock$SkullType;Lnet/minecraft/component/type/ProfileComponent;Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;",
+ method = "getRenderLayer",
at = @At("HEAD"),
cancellable = true
)
- private static void onGetRenderLayer(SkullBlock.SkullType type, ProfileComponent profile, Identifier texture, CallbackInfoReturnable<RenderLayer> cir) {
+ private static void onGetRenderLayer(SkullBlock.SkullType type, ProfileComponent profile, CallbackInfoReturnable<RenderLayer> cir) {
CustomSkyBlockTextures.INSTANCE.modifySkullTexture(type, profile, cir);
}
}
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceTextsInDrawContext.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceTextsInDrawContext.java
new file mode 100644
index 0000000..faf15cc
--- /dev/null
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/ReplaceTextsInDrawContext.java
@@ -0,0 +1,55 @@
+package moe.nea.firmament.mixins.custommodels;
+
+import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
+import moe.nea.firmament.features.texturepack.CustomTextReplacements;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.text.StringVisitable;
+import net.minecraft.text.Text;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.ModifyVariable;
+
+import java.util.stream.Stream;
+
+@Mixin(DrawContext.class)
+public class ReplaceTextsInDrawContext {
+ // I HATE THIS SO MUCH WHY CANT I JUST OPERATE ON ORDEREDTEXTS!!!
+ // JUNE I WILL RIP ALL OF THIS OUT AND MAKE YOU REWRITE EVERYTHING
+ // TODO: be in a mood to rewrite this
+
+ @ModifyVariable(method = "drawText(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;IIIZ)V", at = @At("HEAD"), argsOnly = true)
+ private Text replaceTextInDrawText(Text text) {
+ return CustomTextReplacements.replaceText(text);
+ }
+
+ @ModifyVariable(method = "drawCenteredTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V", at = @At("HEAD"), argsOnly = true)
+ private Text replaceTextInDrawCenteredTextWithShadow(Text text) {
+ return CustomTextReplacements.replaceText(text);
+ }
+
+ @ModifyVariable(method = "drawWrappedText", at = @At("HEAD"), argsOnly = true)
+ private StringVisitable replaceTextInDrawWrappedText(StringVisitable stringVisitable) {
+ return stringVisitable instanceof Text text ? CustomTextReplacements.replaceText(text) : stringVisitable;
+ }
+
+ @ModifyExpressionValue(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/util/Identifier;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;stream()Ljava/util/stream/Stream;"))
+ private Stream<Text> replaceTextInDrawTooltipListText(Stream<Text> original) {
+ return original.map(CustomTextReplacements::replaceText);
+ }
+
+ @ModifyExpressionValue(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;IILnet/minecraft/util/Identifier;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;stream()Ljava/util/stream/Stream;"))
+ private Stream<Text> replaceTextInDrawTooltipListTextWithOptional(Stream<Text> original) {
+ return original.map(CustomTextReplacements::replaceText);
+ }
+
+ @ModifyVariable(method = "drawTooltip(Lnet/minecraft/text/Text;II)V", at = @At("HEAD"), argsOnly = true)
+ private Text replaceTextInDrawTooltipSingle(Text text) {
+ return CustomTextReplacements.replaceText(text);
+ }
+
+ @ModifyExpressionValue(method = "drawHoverEvent", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/HoverEvent$ShowText;value()Lnet/minecraft/text/Text;"))
+ private Text replaceShowTextInHover(Text text) {
+ return CustomTextReplacements.replaceText(text);
+ }
+
+}
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java
index 75cedf8..8687088 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/SupplyFakeModelPatch.java
@@ -17,6 +17,7 @@ import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourcePack;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import java.io.InputStreamReader;
@@ -44,6 +45,7 @@ public class SupplyFakeModelPatch {
return original.thenCompose(oldModels -> CompletableFuture.supplyAsync(() -> supplyExtraModels(resourceManager, oldModels), executor));
}
+ @Unique
private static ItemAssetsLoader.Result supplyExtraModels(ResourceManager resourceManager, ItemAssetsLoader.Result oldModels) {
if (!CustomSkyBlockTextures.TConfig.INSTANCE.getEnableLegacyMinecraftCompat()) return oldModels;
Map<Identifier, ItemAsset> newModels = new HashMap<>(oldModels.contents());
@@ -72,13 +74,14 @@ public class SupplyFakeModelPatch {
.orElse(true)) {
newModels.put(itemModelId, new ItemAsset(
unbakedModel,
- new ItemAsset.Properties(true)
+ new ItemAsset.Properties(true, true)
));
}
}
return new ItemAssetsLoader.Result(newModels);
}
+ @Unique
private static boolean isResourcePackNewer(
ResourceManager manager,
ResourcePack null_, ResourcePack proposal) {
@@ -88,6 +91,7 @@ public class SupplyFakeModelPatch {
return pack.orElse(null_) != null_;
}
+ @Unique
private static <T> Collector<T, ?, Optional<T>> findLast() {
return Collectors.reducing(Optional.empty(), Optional::of,
(left, right) -> right.isPresent() ? right : left);
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceAnvilScreen.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceAnvilScreen.java
index 7c5dc45..5dbdc8e 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceAnvilScreen.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceAnvilScreen.java
@@ -42,11 +42,11 @@ public abstract class ReplaceAnvilScreen extends ForgingScreen<AnvilScreenHandle
}
@WrapOperation(method = "drawForeground",
- at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)I"),
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V"),
allow = 1)
- private int onDrawRepairCost(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, Operation<Integer> original) {
+ private void onDrawRepairCost(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, Operation<Void> original) {
var textOverride = CustomScreenLayouts.getTextMover(CustomScreenLayouts.CustomScreenLayout::getRepairCostTitle);
- return original.call(instance, textRenderer,
+ original.call(instance, textRenderer,
textOverride.replaceText(text),
textOverride.replaceX(textRenderer, text, x),
textOverride.replaceY(y),
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceFurnaceBackgrounds.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceFurnaceBackgrounds.java
index 6b076db..4c84143 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceFurnaceBackgrounds.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplaceFurnaceBackgrounds.java
@@ -1,6 +1,7 @@
package moe.nea.firmament.mixins.custommodels.screenlayouts;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
+import com.mojang.blaze3d.pipeline.RenderPipeline;
import moe.nea.firmament.features.texturepack.CustomScreenLayouts;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.AbstractFurnaceScreen;
@@ -21,8 +22,8 @@ public abstract class ReplaceFurnaceBackgrounds<T extends AbstractFurnaceScreenH
super(handler, recipeBook, inventory, title);
}
- @WrapWithCondition(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V"), allow = 1)
- private boolean onDrawBackground(DrawContext instance, Function<Identifier, RenderLayer> renderLayers, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) {
+ @WrapWithCondition(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/util/Identifier;IIFFIIII)V"), allow = 1)
+ private boolean onDrawBackground(DrawContext instance, RenderPipeline pipeline, Identifier sprite, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) {
final var override = CustomScreenLayouts.getActiveScreenOverride();
if (override == null || override.getBackground() == null) return true;
override.getBackground().renderGeneric(instance, this);
diff --git a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplacePlayerBackgrounds.java b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplacePlayerBackgrounds.java
index e02a821..9ae2e2f 100644
--- a/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplacePlayerBackgrounds.java
+++ b/src/texturePacks/java/moe/nea/firmament/mixins/custommodels/screenlayouts/ReplacePlayerBackgrounds.java
@@ -3,6 +3,7 @@ package moe.nea.firmament.mixins.custommodels.screenlayouts;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.mojang.blaze3d.pipeline.RenderPipeline;
import moe.nea.firmament.features.texturepack.CustomScreenLayouts;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
@@ -28,10 +29,10 @@ public abstract class ReplacePlayerBackgrounds extends RecipeBookScreen<PlayerSc
@WrapOperation(method = "drawForeground",
allow = 1,
- at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawText(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;IIIZ)I"))
- private int onDrawForegroundText(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, boolean shadow, Operation<Integer> original) {
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawText(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;IIIZ)V"))
+ private void onDrawForegroundText(DrawContext instance, TextRenderer textRenderer, Text text, int x, int y, int color, boolean shadow, Operation<Void> original) {
var textOverride = CustomScreenLayouts.getTextMover(CustomScreenLayouts.CustomScreenLayout::getContainerTitle);
- return original.call(instance, textRenderer,
+ original.call(instance, textRenderer,
textOverride.replaceText(text),
textOverride.replaceX(textRenderer, text, x),
textOverride.replaceY(y),
@@ -39,8 +40,8 @@ public abstract class ReplacePlayerBackgrounds extends RecipeBookScreen<PlayerSc
shadow);
}
- @WrapWithCondition(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V"))
- private boolean onDraw