Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ plugins {
stonecutter {
create(rootProject) {
// See https://stonecutter.kikugie.dev/wiki/start/#choosing-minecraft-versions
versions("26.1", "26.1.1", "26.1.2")
vcsVersion = "26.1.2"
versions("26.1", "26.1.1", "26.1.2", "26.2")
vcsVersion = "26.2"
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/sh/ndy/ToggleNametagsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public void onInitializeClient() {
// TODO: prettify
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
dispatcher.register(ClientCommands.literal("ntconfig").executes(context -> {
context.getSource().getClient().schedule(() -> c.setScreen(new ConfigScreen(null, null)));
//? if < 26.2 {
// context.getSource().getClient().schedule(() -> c.setScreen(new ConfigScreen(null, null)));
//?} else
context.getSource().getClient().schedule(() -> c.setScreenAndShow(new ConfigScreen(null, null)));

return 1;
}));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/sh/ndy/config/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Options {
public boolean renderSelfNametag = false;
public boolean renderBossbar = true;
private double nametagOpacity = 1 * Constants.NAMETAG_OPACITY_MULTIPLIER;
private boolean nametagBackgroundEnabled = true;
private boolean renderNametagTextShadow = false;

public boolean getRenderNametags() {
Expand Down Expand Up @@ -43,6 +44,14 @@ public void setNametagOpacity(float newOpacity) {
this.nametagOpacity = (Math.floor(newOpacity * 100.0) / 100.0) * Constants.NAMETAG_OPACITY_MULTIPLIER;
}

public boolean getNametagBackgroundEnabled() {
return this.nametagBackgroundEnabled;
}

public void setNametagBackgroundEnabled(boolean enabled) {
this.nametagBackgroundEnabled = enabled;
}

public boolean getRenderNametagTextShadow() {
return this.renderNametagTextShadow;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
package sh.ndy.mixin.client;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
//? if < 26.2 {
/* import com.llamalad7.mixinextras.injector.ModifyExpressionValue; */
//?}
import net.minecraft.client.renderer.feature.NameTagFeatureRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import sh.ndy.config.Config;


@Mixin(NameTagFeatureRenderer.Storage.class)
//? if < 26.2 {
/* @Mixin(NameTagFeatureRenderer.Storage.class) */
//?} else {
@Mixin(NameTagFeatureRenderer.class)
//?}
public class MixinNametagsBackgroundOpacity {
@ModifyExpressionValue(method = "add",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/state/OptionsRenderState;getBackgroundOpacity(F)F"))
private float submitLabel(float original) {
//? if < 26.2 {
/* @Unique private static final String TARGET = "Lnet/minecraft/client/renderer/state/OptionsRenderState;getBackgroundOpacity(F)F"; */
//?} else
@Unique private static final String TARGET = "Lnet/minecraft/client/gui/Font;prepareText(Lnet/minecraft/util/FormattedCharSequence;FFIZZI)Lnet/minecraft/client/gui/Font$PreparedText;";

//? if < 26.2 {
/* @ModifyExpressionValue(
method = "add",
at = @At(
value = "INVOKE",
target = TARGET
)
)
private float changeOpacity(float original) {
return (float) Config.getOptions().getNametagOpacity();
}
}
*///?} else {
@ModifyArg(
method = "prepareText",
at = @At(
value = "INVOKE",
target = TARGET
),
index = 6
)
private static int disableNametag(int originalColor) {
if (!Config.getOptions().getNametagBackgroundEnabled()) {
return 0;
}
return originalColor;
}
//?}
}
24 changes: 21 additions & 3 deletions src/main/java/sh/ndy/mixin/client/MixinNametagsTextShadow.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@

@Mixin(NameTagFeatureRenderer.class)
public class MixinNametagsTextShadow {
@Unique
private final String TEXT_RENDERER_TARGET =
//? if < 26.2 {
/* @Unique private static final String TARGET =
"Lnet/minecraft/client/gui/Font;drawInBatch(Lnet/minecraft/network/chat/Component;FFIZLorg/joml/Matrix4fc;Lnet/minecraft/client/renderer/MultiBufferSource;Lnet/minecraft/client/gui/Font$DisplayMode;II)V";
*///?} else {
@Unique private static final String TARGET =
"Lnet/minecraft/client/gui/Font;prepareText(Lnet/minecraft/util/FormattedCharSequence;FFIZZI)Lnet/minecraft/client/gui/Font$PreparedText;";
//?}

private static final NametagsTextShadowListener listener = new NametagsTextShadowListener();

@ModifyArg(method = "renderTranslucent", at = @At(value = "INVOKE", target = TEXT_RENDERER_TARGET))
//? if < 26.2 {
/*
@ModifyArg(method = "renderTranslucent", at = @At(value = "INVOKE", target = TARGET))
private boolean render(boolean original) {
return listener.handleMixin();
}
*/
//?} else {
@ModifyArg(method = "prepareText",
at = @At(value = "INVOKE", target = TARGET),
index = 4
)
private static boolean render(boolean drawShadow) {
return listener.handleMixin();
}
//?}

}
23 changes: 21 additions & 2 deletions src/main/java/sh/ndy/screens/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ private Component getRenderNametagShadowText() {
"Show nametag text shadow: " + (Config.getOptions().getRenderNametagTextShadow() ? "§aYes" : "§cNo"));
}

private Component getEnableNametagBackground() {
return Component.nullToEmpty("Show nametag background: " + (Config.getOptions().getNametagBackgroundEnabled() ? "§aYes" : "§cNo"));
}

protected void init() {
GridLayout grid = new GridLayout();
grid.defaultCellSetting().padding(4, 4, 4, 2);
Expand Down Expand Up @@ -104,6 +108,13 @@ protected void applyValue() {
}
};

Button renderNametagBackground = Button.builder(getEnableNametagBackground(), (btn) -> {
Config.getOptions().setNametagBackgroundEnabled(!Config.getOptions().getNametagBackgroundEnabled());
Config.saveConfig();
btn.setFocused(false);
btn.setMessage(getEnableNametagBackground());
}).width(STANDARD_BTN_WIDTH).build();

// TODO: Find a way to remove Essential's padding around the nametags, so we don't have to disable
// this option when Essential is loaded.
if (ToggleNametagsClient.isEssentialModLoaded) {
Expand All @@ -115,7 +126,12 @@ protected void applyValue() {
adder.addChild(renderNametagsBtnWidget);
adder.addChild(renderSelfNametagsBtnWidget);
adder.addChild(renderNametagShadowBtnWidget);
adder.addChild(nametagOpacitySlider);

//? if < 26.2 {
/* adder.addChild(nametagOpacitySlider); */
//?} else
adder.addChild(renderNametagBackground);

adder.addChild(renderBossbarBtnWidget, 2);

grid.arrangeElements();
Expand All @@ -135,6 +151,9 @@ public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mo

@Override
public void onClose() {
this.minecraft.setScreen(parent);
//? if < 26.2 {
// this.minecraft.setScreen(parent);
//?} else
this.minecraft.setScreenAndShow(parent);
}
}
6 changes: 3 additions & 3 deletions src/main/resources/togglenametags.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"package": "sh.ndy.mixin.client",
"compatibilityLevel": "JAVA_17",
"client": [
"MixinNametagsBackgroundOpacity",
"MixinNametagsTextShadow",
"MixinRenderBossBar",
"MixinRenderNameTag",
"MixinRenderSelfNameTag",
"MixinNametagsTextShadow",
"MixinNametagsBackgroundOpacity"
"MixinRenderSelfNameTag"
],
"injectors": {
"defaultRequire": 1
Expand Down
2 changes: 1 addition & 1 deletion stonecutter.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
// id("me.modmuss50.mod-publish-plugin") version "1.0.+" apply false
}

stonecutter active "26.1.1"
stonecutter active "26.2"

// Make newer versions be published last
stonecutter tasks {
Expand Down
11 changes: 11 additions & 0 deletions versions/26.2/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
deps.fabric_api=0.156.0+26.2
deps.modmenu=20.0.1

# Minecraft dependency for fabric.mod.json
mod.mc_dep=>=26.2

# Release title for Modrinth and Curseforge
mod.mc_title=26.2

# Space-separated compatible versions for publishing
mod.mc_targets=26.2
Loading