Skip to content

Commit

Permalink
Fixed text color replacement not working properly in some cases or in…
Browse files Browse the repository at this point in the history
… some shades of grey like the default ones
  • Loading branch information
Buuz135 committed Nov 20, 2024
1 parent d383153 commit 78d1954
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ gradle-app.setting

# Common working directory
run/
runs/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'

group = 'com.buuz135'
version = '1.20.1-1.2.2'
version = '1.20.1-1.2.3'


java {
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/buuz135/darkmodeeverywhere/mixins/FontMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

import com.buuz135.darkmodeeverywhere.ClientProxy;
import com.buuz135.darkmodeeverywhere.ShaderConfig;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.util.FastColor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;


@Mixin(Font.class)
public class FontMixin {

@ModifyArg(method = "drawInternal(Lnet/minecraft/util/FormattedCharSequence;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/client/gui/Font$DisplayMode;II)I", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Font;adjustColor(I)I"), index = 0)
public int drawInternalA(int color) {
return modifyColor(color);
}

private int modifyColor(int color){
if (color == 0) return color;
@Inject(method = "adjustColor", at = @At(value = "HEAD", target = "Lnet/minecraft/client/gui/Font;adjustColor(I)I"), cancellable = true)
private static void adjustColorA(int color, CallbackInfoReturnable<Integer> cir) {
if (ClientProxy.SELECTED_SHADER_VALUE != null && Minecraft.getInstance().screen != null) {
int threshold = 65;
ShaderConfig.ShaderValue shaderValue = ClientProxy.SELECTED_SHADER_VALUE;
if (shaderValue.darkColorReplacement == -1) return color;
if (FastColor.ARGB32.red(color) < threshold && FastColor.ARGB32.green(color) < threshold && FastColor.ARGB32.blue(color) < threshold){
return shaderValue.darkColorReplacement;
if (shaderValue.darkColorReplacement == -1) return;
if (ChatFormatting.GRAY.getColor().equals(color) || ChatFormatting.DARK_GRAY.getColor().equals(color)) {
cir.setReturnValue(0xFF000000 | shaderValue.darkColorReplacement);
return;
}
if (FastColor.ARGB32.red(color) < threshold && FastColor.ARGB32.green(color) < threshold && FastColor.ARGB32.blue(color) < threshold){
cir.setReturnValue(0xFF000000 | shaderValue.darkColorReplacement);
return;
}
}
return color;
}
}

0 comments on commit 78d1954

Please sign in to comment.