Skip to content

Commit bcc03e5

Browse files
authored
Merge pull request #12 from Tryflle/twoconfig
Port:OC alpha.191+26.1,1.21.11,1.21.5+Feat:FadeOut
1 parent 6e6bb04 commit bcc03e5

13 files changed

Lines changed: 190 additions & 87 deletions

File tree

build.gradle.kts

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33

44
plugins {
5-
id("net.fabricmc.fabric-loom-remap") version "1.14-SNAPSHOT"
5+
id("dev.kikugie.loom-back-compat")
66
id("org.jetbrains.kotlin.jvm") version "2.3.0"
77
id("dev.deftu.gradle.bloom") version "0.2.0"
88
}
@@ -17,10 +17,31 @@ base {
1717
}
1818

1919
repositories {
20+
mavenCentral()
21+
gradlePluginPortal()
22+
google()
23+
2024
maven("https://maven.parchmentmc.org")
2125
maven("https://repo.polyfrost.org/releases")
2226
maven("https://repo.polyfrost.org/snapshots")
2327
maven("https://maven.gegy.dev/releases")
28+
29+
maven("https://maven.logix.dev/snapshots")
30+
maven("https://nexus.prsm.wtf/repository/maven-public/maven-repo/releases/")
31+
maven("https://repo.hypixel.net/repository/Hypixel/")
32+
maven("https://maven.deftu.dev/releases")
33+
34+
maven("https://maven.fabricmc.net/releases")
35+
maven("https://jitpack.io") {
36+
content { includeGroupAndSubgroups("com.github") }
37+
}
38+
maven("https://maven.bawnorton.com/releases") {
39+
content { includeGroup("com.github.bawnorton.mixinsquared") }
40+
}
41+
maven("https://maven.azureaaron.net/releases") {
42+
content { includeGroup("net.azureaaron") }
43+
}
44+
maven("https://redirector.kotlinlang.org/maven/compose-dev")
2445
}
2546

2647
loom {
@@ -34,26 +55,34 @@ loom {
3455

3556
dependencies {
3657
minecraft("com.mojang:minecraft:${property("minecraft_version")}")
37-
@Suppress("UnstableApiUsage")
38-
mappings(loom.layered {
39-
officialMojangMappings()
40-
optionalProp("${property("parchment_version")}") {
41-
parchment("org.parchmentmc.data:parchment-${property("minecraft_version")}:$it@zip")
42-
}
43-
optionalProp("${property("yalmm_version")}") {
44-
mappings("dev.lambdaurora:yalmm-mojbackward:${property("minecraft_version")}+build.$it")
58+
59+
val hasOfficialMappings = findProperty("has_official_mappings")?.toString()?.toBoolean() ?: true
60+
if (hasOfficialMappings) {
61+
@Suppress("UnstableApiUsage")
62+
mappings(loom.layered {
63+
officialMojangMappings()
64+
optionalProp("${property("parchment_version")}") {
65+
parchment("org.parchmentmc.data:parchment-${property("minecraft_version")}:$it@zip")
66+
}
67+
optionalProp("${property("yalmm_version")}") {
68+
mappings("dev.lambdaurora:yalmm-mojbackward:${property("minecraft_version")}+build.$it")
69+
}
70+
})
71+
} else {
72+
findProperty("mappings_version")?.toString()?.takeUnless { it.isBlank() }?.let {
73+
mappings(it)
4574
}
46-
})
75+
}
4776
modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}")
48-
modImplementation("org.polyfrost.oneconfig:${property("minecraft_version")}-fabric:1.0.0-alpha.181")
49-
modImplementation("org.polyfrost.oneconfig:commands:1.0.0-alpha.181")
50-
modImplementation("org.polyfrost.oneconfig:config:1.0.0-alpha.181")
51-
modImplementation("org.polyfrost.oneconfig:config-impl:1.0.0-alpha.181")
52-
modImplementation("org.polyfrost.oneconfig:events:1.0.0-alpha.181")
53-
modImplementation("org.polyfrost.oneconfig:internal:1.0.0-alpha.181")
54-
modImplementation("org.polyfrost.oneconfig:ui:1.0.0-alpha.181")
55-
modImplementation("org.polyfrost.oneconfig:utils:1.0.0-alpha.181")
56-
modImplementation("org.polyfrost.oneconfig:hud:1.0.0-alpha.181")
77+
modImplementation("org.polyfrost.oneconfig:${property("minecraft_version")}-fabric:1.0.0-alpha.192")
78+
implementation("org.polyfrost.oneconfig:commands:1.0.0-alpha.192")
79+
implementation("org.polyfrost.oneconfig:config:1.0.0-alpha.192")
80+
implementation("org.polyfrost.oneconfig:config-impl:1.0.0-alpha.192")
81+
implementation("org.polyfrost.oneconfig:events:1.0.0-alpha.192")
82+
implementation("org.polyfrost.oneconfig:internal:1.0.0-alpha.192")
83+
implementation("org.polyfrost.oneconfig:ui:1.0.0-alpha.192")
84+
implementation("org.polyfrost.oneconfig:utils:1.0.0-alpha.192")
85+
implementation("org.polyfrost.oneconfig:hud:1.0.0-alpha.192")
5786
}
5887

5988
bloom {
@@ -78,18 +107,31 @@ tasks.processResources {
78107
}
79108
}
80109

110+
val javaVersionStr = findProperty("java_version")?.toString() ?: "21"
111+
val javaVersionInt = javaVersionStr.toInt()
112+
113+
val kotlinJvmTarget = when(javaVersionInt) {
114+
21 -> JvmTarget.JVM_21
115+
22 -> JvmTarget.JVM_22
116+
23 -> JvmTarget.JVM_23
117+
24 -> JvmTarget.JVM_24
118+
25 -> JvmTarget.JVM_25
119+
else -> JvmTarget.JVM_21
120+
}
121+
81122
tasks.withType<JavaCompile>().configureEach {
82-
options.release.set(21)
123+
options.release.set(javaVersionInt)
83124
}
84125

85126
tasks.withType<KotlinCompile>().configureEach {
86-
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
127+
compilerOptions.jvmTarget.set(kotlinJvmTarget)
87128
}
88129

89130
java {
90131
withSourcesJar()
91-
sourceCompatibility = JavaVersion.VERSION_21
92-
targetCompatibility = JavaVersion.VERSION_21
132+
toolchain {
133+
languageVersion.set(JavaLanguageVersion.of(javaVersionInt))
134+
}
93135
}
94136

95137
tasks.jar {

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ org.gradle.daemon=true
33
org.gradle.parallel=true
44
org.gradle.configureoncommand=true
55
org.gradle.parallel.threads=4
6-
org.gradle.jvmargs=-Xmx2G
6+
org.gradle.jvmargs=-Xmx4G
77
loom.ignoreDependencyLoomVersionValidation=true
88

99
# Mod information
1010
mod.name=DamageTint
1111
mod.id=damagetint
12-
mod.version=3.4.0-alpha.1
12+
mod.version=3.4.1-alpha.1
1313
mod.group=org.polyfrost
1414

1515
# Loom settings, [VERSIONED] means to be overridden in each version's gradle.properties
16-
loom_version=1.14-SNAPSHOT
17-
loader_version=0.18.4
16+
loomx.loom_version=1.16-SNAPSHOT
17+
loader_version=0.19.2
1818
minecraft_version=[VERSIONED]
1919
parchment_version=[VERSIONED]
2020
yalmm_version=[VERSIONED]

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

settings.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ pluginManagement {
1111
maven("https://maven.architectury.dev")
1212
maven("https://repo.polyfrost.org/releases")
1313
maven("https://repo.polyfrost.org/snapshots")
14+
maven("https://maven.kikugie.dev/releases") { name = "KikuGie Releases" }
15+
maven("https://maven.kikugie.dev/snapshots") { name = "KikuGie Snapshots" }
1416
}
1517
}
1618

1719
plugins {
18-
id("dev.kikugie.stonecutter") version "0.7.10"
20+
id("dev.kikugie.stonecutter") version "0.9.4"
21+
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
22+
id("dev.kikugie.loom-back-compat") version "0.3"
1923
}
2024

2125
stonecutter {
2226
create(rootProject) {
23-
versions("1.21.1", "1.21.4", "1.21.8", "1.21.10")
27+
versions("1.21.1", "1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11", "26.1")
2428

2529
vcsVersion = "1.21.10" // primary
2630
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
package org.polyfrost.damagetint.client;
2-
3-
import dev.deftu.omnicore.api.client.commands.OmniClientCommands;
4-
import org.polyfrost.damagetint.DamageTintConstants;
52
import org.polyfrost.oneconfig.api.event.v1.EventManager;
63
import org.polyfrost.oneconfig.api.event.v1.events.InitializationEvent;
7-
import org.polyfrost.oneconfig.utils.v1.dsl.ScreensKt;
84
import org.slf4j.Logger;
95
import org.slf4j.LoggerFactory;
106

11-
127
public class DamageTintClient {
8+
139
public static final DamageTintClient INSTANCE = new DamageTintClient();
1410

1511
public final Logger LOGGER = LoggerFactory.getLogger("DamageTint");
1612

1713
public void initialize() {
1814
DamageTintConfig.INSTANCE.preload();
19-
OmniClientCommands.register(OmniClientCommands.literal(DamageTintConstants.ID).executes(ctx -> ctx.getSource().openScreen(ScreensKt.createScreen(DamageTintConfig.INSTANCE))));
2015
EventManager.register(InitializationEvent.class, () -> DamageTintConfig.updateOverlayColor(DamageTintConfig.color));
2116
}
2217
}
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package org.polyfrost.damagetint.client;
22

3-
import dev.deftu.omnicore.api.client.OmniClient;
4-
import dev.deftu.omnicore.api.client.OmniClientRuntime;
5-
import dev.deftu.omnicore.api.color.OmniColor;
3+
import net.minecraft.client.Minecraft;
64
import net.minecraft.client.renderer.texture.OverlayTexture;
5+
import org.polyfrost.compose.render.PolyColor;
76
import org.polyfrost.damagetint.DamageTintConstants;
87
import org.polyfrost.damagetint.client.utils.OverlayModifier;
98
import org.polyfrost.oneconfig.api.config.v1.Config;
10-
import org.polyfrost.oneconfig.api.config.v1.annotations.Button;
119
import org.polyfrost.oneconfig.api.config.v1.annotations.Color;
1210
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch;
13-
import org.polyfrost.polyui.color.ColorUtils;
14-
import org.polyfrost.polyui.color.PolyColor;
1511

1612
public class DamageTintConfig extends Config {
1713

@@ -23,35 +19,29 @@ public class DamageTintConfig extends Config {
2319
private static final int defaultColor = 1291780096;
2420

2521
@Color(title = "Damage Tint Color")
26-
public static PolyColor color = ColorUtils.toColor(defaultColor);
27-
28-
@Button(title = "Reset Damage Tint", text = "Reset Color")
29-
private void resetColor() {
30-
color = ColorUtils.asMutable(ColorUtils.toColor(defaultColor));
31-
save();
32-
}
22+
public static PolyColor color = new PolyColor(defaultColor);
3323

3424
@Switch(title = "Fade Out Damage Tint")
3525
public static boolean fade = false;
3626

3727
public DamageTintConfig() {
3828
super("damagetint.json", "/assets/damagetint/damagetint_dark.svg", DamageTintConstants.NAME, Category.QOL);
29+
addCallback("color", (() -> {
30+
updateOverlayColor(color);
31+
}));
3932
save();
4033
}
4134

4235
public static void updateOverlayColor(PolyColor newColor) {
43-
OmniClientRuntime.runOnMain(() -> {
44-
int r = newColor.red();
45-
int g = newColor.green();
46-
int b = newColor.blue();
36+
Minecraft.getInstance().execute(() -> {
37+
int r = newColor.getRed();
38+
int g = newColor.getGreen();
39+
int b = newColor.getBlue();
4740
// Alpha is flipped for some reason, so 0 is fully opaque and 255 is fully transparent... Why, Mojang? Other developer note: 😭😭😭😭😭
48-
int a = 255 - newColor.alpha();
49-
50-
OmniColor color = new OmniColor(r, g, b, a);
51-
DamageTintClient.INSTANCE.LOGGER.info("updateOverlayColor called");
41+
int a = 255 - newColor.getAlpha();
5242

53-
OverlayTexture overlayTexture = OmniClient.get().gameRenderer.overlayTexture();
54-
((OverlayModifier)overlayTexture).damageTint$setOverlayColor(color);
43+
OverlayTexture overlayTexture = Minecraft.getInstance().gameRenderer.overlayTexture();
44+
((OverlayModifier)overlayTexture).damageTint$setOverlayColor(a, r, g, b);
5545
});
5646
}
5747
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.polyfrost.damagetint.client.utils;
22

3-
import dev.deftu.omnicore.api.color.OmniColor;
4-
53
public interface OverlayModifier {
6-
void damageTint$setOverlayColor(OmniColor color);
4+
void damageTint$setOverlayColor(int a, int r, int g, int b);
75
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.polyfrost.damagetint.mixin.client;
2+
3+
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
4+
//? if >=1.21.4 {
5+
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
6+
//?}
7+
import net.minecraft.client.renderer.texture.OverlayTexture;
8+
import net.minecraft.world.entity.LivingEntity;
9+
import org.polyfrost.damagetint.client.DamageTintConfig;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.Unique;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
16+
17+
//? if >=1.21.4 {
18+
import java.util.Map;
19+
import java.util.WeakHashMap;
20+
//?}
21+
22+
@Mixin(LivingEntityRenderer.class)
23+
public class Mixin_LivingEntityRenderer {
24+
25+
//? if >=1.21.4 {
26+
@Unique
27+
private static final Map<Object, Integer> damageTint$hurtTimeMap = java.util.Collections.synchronizedMap(new WeakHashMap<>());
28+
@Unique
29+
private static final Map<Object, Integer> damageTint$deathTimeMap = java.util.Collections.synchronizedMap(new WeakHashMap<>());
30+
31+
@Inject(method = "extractRenderState(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/client/renderer/entity/state/LivingEntityRenderState;F)V", at = @At("HEAD"))
32+
private void onExtractRenderState(LivingEntity entity, LivingEntityRenderState state, float f, CallbackInfo ci) {
33+
damageTint$hurtTimeMap.put(state, entity.hurtTime);
34+
damageTint$deathTimeMap.put(state, entity.deathTime);
35+
}
36+
37+
@Inject(method = "getOverlayCoords", at = @At("HEAD"), cancellable = true)
38+
private static void onGetOverlayCoords(LivingEntityRenderState state, float f, CallbackInfoReturnable<Integer> cir) {
39+
if (DamageTintConfig.fade && DamageTintConfig.enabled) {
40+
Integer hurtTimeObj = damageTint$hurtTimeMap.get(state);
41+
Integer deathTimeObj = damageTint$deathTimeMap.get(state);
42+
int hurtTime = hurtTimeObj != null ? hurtTimeObj : 0;
43+
int deathTime = deathTimeObj != null ? deathTimeObj : 0;
44+
45+
if (hurtTime > 0) {
46+
int row = Math.round((1.0f - (float) hurtTime / 10.0f) * 7.0f);
47+
cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(f), row));
48+
} else if (deathTime > 0) {
49+
cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(f), 0));
50+
}
51+
}
52+
}
53+
//?} else {
54+
/*// 1.21.1 has an entirely different method sig/approach
55+
@Inject(method = "getOverlayCoords", at = @At("HEAD"), cancellable = true)
56+
private static void onGetOverlayCoords(LivingEntity entity, float f, CallbackInfoReturnable<Integer> cir) {
57+
if (DamageTintConfig.fade && DamageTintConfig.enabled) {
58+
int hurtTime = entity.hurtTime;
59+
int deathTime = entity.deathTime;
60+
61+
if (hurtTime > 0) {
62+
int row = Math.round((1.0f - (float) hurtTime / 10.0f) * 7.0f);
63+
cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(f), row));
64+
} else if (deathTime > 0) {
65+
cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(f), 0));
66+
}
67+
}
68+
}
69+
*///?}
70+
}

0 commit comments

Comments
 (0)