Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide durability bar for all items #1

Merged
merged 2 commits into from
Apr 27, 2024
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
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ base {
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
// WARN: When changing this you might also have to change the value in
// duradisplay.mixins.json
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
Expand Down Expand Up @@ -129,6 +131,14 @@ tasks.withType(ProcessResources).configureEach {
}
}

// Required for mixins
repositories {
maven {
url = 'https://repo.spongepowered.org/repository/maven-public/'
}
}


// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
Expand Down
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pluginManagement {
mavenLocal()
gradlePluginPortal()
maven { url = 'https://maven.neoforged.net/releases' }
maven {
name = "Mixin"
url "https://repo.spongepowered.org/repository/maven-public/"
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/leclowndu93150/duradisplay/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int x

String formattedPercentage = String.format("%.0f%%", durabilityPercentage);

String string = formattedPercentage;
int stringWidth = font.width(string);
int stringWidth = font.width(formattedPercentage);
int x = ((xPosition + 8) * 2 + 1 + stringWidth / 2 - stringWidth);
int y = (yPosition * 2) + 18;

Expand All @@ -56,7 +55,7 @@ public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int x
poseStack.scale(0.5F, 0.5F, 0.5F);
poseStack.translate(0.0D, 0.0D, 750.0F);
MultiBufferSource.BufferSource multibuffersource$buffersource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
font.drawInBatch(string, x, y, color, true, poseStack.last().pose(), multibuffersource$buffersource, Font.DisplayMode.NORMAL, 0, 15728880, false);
font.drawInBatch(formattedPercentage, x, y, color, true, poseStack.last().pose(), multibuffersource$buffersource, Font.DisplayMode.NORMAL, 0, 15728880, false);
multibuffersource$buffersource.endBatch();
poseStack.popPose();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.leclowndu93150.duradisplay.mixins;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.client.gui.GuiGraphics;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(value = GuiGraphics.class)
public abstract class GuiGraphicsMixin {
@ModifyExpressionValue(
method = "Lnet/minecraft/client/gui/GuiGraphics;renderItemDecorations(Lnet/minecraft/client/gui/Font;Lnet/minecraft/world/item/ItemStack;IILjava/lang/String;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/item/ItemStack;isBarVisible()Z"
)
)
private boolean disableBarInGui(boolean barVisible) {
return false;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ license="${mod_license}"
# The modid of the mod
modId="${mod_id}" #mandatory

# Location of the mixin config file
[[mixins]]
config = "${mod_id}.mixins.json"

# The version number of the mod
version="${mod_version}" #mandatory

Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/duradisplay.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.leclowndu93150.duradisplay.mixins",
"refmap": "mixins.duradisplay.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_17",
"mixins": [
"GuiGraphicsMixin"
]
}
Loading