diff --git a/build.gradle b/build.gradle index 83772c6..f928675 100644 --- a/build.gradle +++ b/build.gradle @@ -55,14 +55,14 @@ subprojects { } repositories { - if (project.use_third_party_mods == 'true') { - maven { - name = 'Modrinth' - url = 'https://api.modrinth.com/maven' - content { - includeGroup 'maven.modrinth' - } + maven { + name = 'Modrinth' + url = 'https://api.modrinth.com/maven' + content { + includeGroup 'maven.modrinth' } + } + if (project.use_third_party_mods == 'true') { maven { url = 'https://cursemaven.com' content { @@ -132,4 +132,8 @@ subprojects { } } } + + build.doFirst { + use_third_party_mods = 'false' + } } diff --git a/gradle.properties b/gradle.properties index bc2a0a4..a62ab6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -29,6 +29,10 @@ cloth_config_version_1_19 = 8.3.115 minecraft_version_1_19_4 = 1.19.4 yarn_mappings_1_19_4 = 1.19.4+build.2 cloth_config_version_1_19_4 = 10.1.117 +# 1.20 +minecraft_version_1_20 = 1.20.1 +yarn_mappings_1_20 = 1.20.1+build.10 +cloth_config_version_1_20 = 11.1.118 # Dev-Env Mods use_third_party_mods = true @@ -43,7 +47,8 @@ starlight_version_1_17 = Starlight 1.0.0 1.17.x ferritecore_version_1_17 = 3.0.3 smoothboot_version_1_17 = 1.16.5-1.6.0 no_fade_version_1_17 = 3355800 -raised_version_1_17 = Fabric-1.17.1-1.1.2 +raised_version_1_17 = Fabric-1.17.1-3.1.3 +double_hotbar_version_1_17 = 1.1.0-mc1.17.1-fabric # 1.19 fabric_api_version_1_19 = 0.76.1+1.19.2 modmenu_version_1_19 = 4.2.0-beta.2 @@ -55,6 +60,8 @@ starlight_version_1_19 = 1.1.1+1.19 ferritecore_version_1_19 = 5.0.3-fabric smoothboot_version_1_19 = 3821513 no_fade_version_1_19 = 3550935 +raised_version_1_19 = Fabric-1.19.2-3.1.3 +double_hotbar_version_1_19 = 4034709 # 1.19.4 fabric_api_version_1_19_4 = 0.87.2+1.19.4 modmenu_version_1_19_4 = 6.3.1 @@ -64,3 +71,15 @@ starlight_version_1_19_4 = 1.1.1+1.19 ferritecore_version_1_19_4 = 5.2.0-fabric smoothboot_version_1_19_4 = 4441240 no_fade_version_1_19_4 = 3550935 +raised_version_1_19_4 = Fabric-1.19.4-3.1.3 +double_hotbar_version_1_19_4 = 1.3.1-mc1.19.4-fabric +# 1.20 +fabric_api_version_1_20 = 0.92.1+1.20.1 +modmenu_version_1_20 = 7.2.2 +sodium_version_1_20 = mc1.20.1-0.5.8 +lithium_version_1_20 = mc1.20.1-0.11.2 +ferritecore_version_1_20 = 6.0.1-fabric +threadtweak_version_1_20 = 0.1.1+mc1.20.2 +fadeless_version_1_20 = 1.0.1 +raised_version_1_20 = Fabric-1.20.2-3.1.3 +double_hotbar_version_1_20 = 1.3.1-mc1.20.1-fabric diff --git a/microdurability-1.17/build.gradle b/microdurability-1.17/build.gradle index b86ba84..41941a6 100644 --- a/microdurability-1.17/build.gradle +++ b/microdurability-1.17/build.gradle @@ -25,6 +25,10 @@ dependencies { modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_17}" modRuntimeOnly "maven.modrinth:smoothboot-fabric:${project.smoothboot_version_1_17}" modRuntimeOnly "curse.maven:no-fade-452768:${project.no_fade_version_1_17}" + + // Comment out the following dependencies to check vanilla compatibility + modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_17}" + modRuntimeOnly "maven.modrinth:double-hotbar:${project.double_hotbar_version_1_17}" } } diff --git a/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/Renderer117.java b/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/Renderer117.java index 8d75805..cdcf8f4 100644 --- a/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/Renderer117.java +++ b/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/Renderer117.java @@ -2,15 +2,20 @@ import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; public class Renderer117 extends RendererBase { + private static final DrawableHelper drawableHelper = new DrawableHelper() {}; + @Override protected void disableRenderSystems() { RenderSystem.disableDepthTest(); @@ -25,6 +30,13 @@ protected void enableRenderSystems() { RenderSystem.enableDepthTest(); } + @Override + protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) { + RenderSystem.setShaderTexture(0, texture); + drawableHelper.drawTexture((MatrixStack) context, x, y, u, v, width, height); + RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE); + } + @Override protected Iterable getHandItems(ClientPlayerEntity player) { return player.getItemsHand(); diff --git a/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin117.java b/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin117.java index 231b9bb..055495a 100644 --- a/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin117.java +++ b/microdurability-1.17/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin117.java @@ -1,6 +1,7 @@ package com.github.reviversmc.microdurability.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -12,6 +13,9 @@ @Mixin(InGameHud.class) public class InGameHudMixin117 { + @Shadow + private int ticks; + @Inject( at = @At( value = "INVOKE", @@ -19,7 +23,18 @@ public class InGameHudMixin117 { ), method = "render" ) - public void renderMicroDurability(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { - MicroDurability117.renderer.onHudRender(matrices, delta); + private void renderArmorArea(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability117.renderer.renderArmorArea(matrices, ticks, delta); + } + + @Inject( + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V" + ), + method = "render" + ) + private void renderHeldItemExclamationMark(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability117.renderer.renderHeldItemLowDurabilityWarning(matrices, ticks, delta); } } diff --git a/microdurability-1.17/src/main/resources/fabric.mod.json b/microdurability-1.17/src/main/resources/fabric.mod.json index 773ad00..da3e429 100644 --- a/microdurability-1.17/src/main/resources/fabric.mod.json +++ b/microdurability-1.17/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ "com.github.reviversmc.microdurability.MicroDurability117" ], "modmenu": [ - "com.github.reviversmc.microdurability.ModMenuIntegration" + "com.github.reviversmc.microdurability.integration.ModMenuIntegration" ] }, "mixins": [ diff --git a/microdurability-1.19.4/build.gradle b/microdurability-1.19.4/build.gradle index aa83cb2..36cf42a 100644 --- a/microdurability-1.19.4/build.gradle +++ b/microdurability-1.19.4/build.gradle @@ -23,6 +23,10 @@ dependencies { modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_19_4}" modRuntimeOnly "curse.maven:smooth-boot-415758:${project.smoothboot_version_1_19_4}" modRuntimeOnly "curse.maven:no-fade-452768:${project.no_fade_version_1_19_4}" + + // Comment out the following dependencies to check vanilla compatibility + modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_19_4}" + modRuntimeOnly "maven.modrinth:double-hotbar:${project.double_hotbar_version_1_19_4}" } } diff --git a/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/Renderer1194.java b/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/Renderer1194.java index c63405c..8ad28a7 100644 --- a/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/Renderer1194.java +++ b/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/Renderer1194.java @@ -2,13 +2,16 @@ import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; public class Renderer1194 extends RendererBase { @Override @@ -23,6 +26,13 @@ protected void enableRenderSystems() { RenderSystem.enableDepthTest(); } + @Override + protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) { + RenderSystem.setShaderTexture(0, texture); + DrawableHelper.drawTexture((MatrixStack) context, x, y, u, v, width, height); + RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE); + } + @Override protected Iterable getHandItems(ClientPlayerEntity player) { return player.getHandItems(); diff --git a/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin1194.java b/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin1194.java index 6cd6794..ae1d3b2 100644 --- a/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin1194.java +++ b/microdurability-1.19.4/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin1194.java @@ -1,6 +1,7 @@ package com.github.reviversmc.microdurability.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -12,6 +13,9 @@ @Mixin(InGameHud.class) public class InGameHudMixin1194 { + @Shadow + private int ticks; + @Inject( at = @At( value = "INVOKE", @@ -19,7 +23,18 @@ public class InGameHudMixin1194 { ), method = "render" ) - public void renderMicroDurability(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { - MicroDurability1194.renderer.onHudRender(matrices, delta); + private void renderArmorArea(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability1194.renderer.renderArmorArea(matrices, ticks, delta); + } + + @Inject( + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V" + ), + method = "render" + ) + private void renderHeldItemExclamationMark(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability1194.renderer.renderHeldItemLowDurabilityWarning(matrices, ticks, delta); } } diff --git a/microdurability-1.19.4/src/main/resources/fabric.mod.json b/microdurability-1.19.4/src/main/resources/fabric.mod.json index 62737c9..01e3c85 100644 --- a/microdurability-1.19.4/src/main/resources/fabric.mod.json +++ b/microdurability-1.19.4/src/main/resources/fabric.mod.json @@ -24,14 +24,14 @@ "com.github.reviversmc.microdurability.MicroDurability1194" ], "modmenu": [ - "com.github.reviversmc.microdurability.ModMenuIntegration" + "com.github.reviversmc.microdurability.integration.ModMenuIntegration" ] }, "mixins": [ "microdurability.mixins.json" ], "depends": { - "minecraft": ">=1.19.4-", + "minecraft": ">=1.19.4- <1.20", "microdurability-core": "*" } } diff --git a/microdurability-1.19/build.gradle b/microdurability-1.19/build.gradle index e74c5e9..2bc5e37 100644 --- a/microdurability-1.19/build.gradle +++ b/microdurability-1.19/build.gradle @@ -25,6 +25,10 @@ dependencies { modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_19}" modRuntimeOnly "curse.maven:smooth-boot-415758:${project.smoothboot_version_1_19}" modRuntimeOnly "curse.maven:no-fade-452768:${project.no_fade_version_1_19}" + + // Comment out the following dependencies to check vanilla compatibility + modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_19}" + // modRuntimeOnly "curse.maven:double-hotbar-554026:${project.double_hotbar_version_1_19}" // 404s because 3rd-party-sharing is disabled } } diff --git a/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/Renderer119.java b/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/Renderer119.java index 69ac0d7..06a8d9b 100644 --- a/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/Renderer119.java +++ b/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/Renderer119.java @@ -2,15 +2,20 @@ import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; public class Renderer119 extends RendererBase { + private static final DrawableHelper drawableHelper = new DrawableHelper() {}; + @Override protected void disableRenderSystems() { RenderSystem.disableDepthTest(); @@ -23,6 +28,13 @@ protected void enableRenderSystems() { RenderSystem.enableDepthTest(); } + @Override + protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) { + RenderSystem.setShaderTexture(0, texture); + drawableHelper.drawTexture((MatrixStack) context, x, y, u, v, width, height); + RenderSystem.setShaderTexture(0, DrawableHelper.GUI_ICONS_TEXTURE); + } + @Override protected Iterable getHandItems(ClientPlayerEntity player) { return player.getHandItems(); diff --git a/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin119.java b/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin119.java index 2ea35cf..920db7a 100644 --- a/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin119.java +++ b/microdurability-1.19/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin119.java @@ -1,6 +1,7 @@ package com.github.reviversmc.microdurability.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -12,6 +13,9 @@ @Mixin(InGameHud.class) public class InGameHudMixin119 { + @Shadow + private int ticks; + @Inject( at = @At( value = "INVOKE", @@ -19,7 +23,18 @@ public class InGameHudMixin119 { ), method = "render" ) - public void renderMicroDurability(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { - MicroDurability119.renderer.onHudRender(matrices, delta); + private void renderArmorArea(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability119.renderer.renderArmorArea(matrices, ticks, delta); + } + + @Inject( + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V" + ), + method = "render" + ) + private void renderHeldItemExclamationMark(MatrixStack matrices, float delta, CallbackInfo callbackInfo) { + MicroDurability119.renderer.renderHeldItemLowDurabilityWarning(matrices, ticks, delta); } } diff --git a/microdurability-1.19/src/main/resources/fabric.mod.json b/microdurability-1.19/src/main/resources/fabric.mod.json index 06e3425..c1df835 100644 --- a/microdurability-1.19/src/main/resources/fabric.mod.json +++ b/microdurability-1.19/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ "com.github.reviversmc.microdurability.MicroDurability119" ], "modmenu": [ - "com.github.reviversmc.microdurability.ModMenuIntegration" + "com.github.reviversmc.microdurability.integration.ModMenuIntegration" ] }, "mixins": [ diff --git a/microdurability-1.20/build.gradle b/microdurability-1.20/build.gradle new file mode 100644 index 0000000..5550143 --- /dev/null +++ b/microdurability-1.20/build.gradle @@ -0,0 +1,39 @@ +version += '+1.20' + +dependencies { + include implementation(project(path: ':microdurability-core', configuration: 'namedElements')) + + minecraft "com.mojang:minecraft:${project.minecraft_version_1_20}" + mappings "net.fabricmc:yarn:${project.yarn_mappings_1_20}:v2" + + // Other mods + modImplementation "com.terraformersmc:modmenu:${project.modmenu_version_1_20}" + modImplementation("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version_1_20}") { + exclude(group: 'net.fabricmc.fabric-api') + } + + + if (project.use_third_party_mods == 'true') { + // Use full Fabric API bundle while debugging, since transitive deps aren't always declared correctly + modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version_1_20}" + + modRuntimeOnly "maven.modrinth:sodium:${project.sodium_version_1_20}" + modRuntimeOnly "maven.modrinth:lithium:${project.lithium_version_1_20}" + modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_20}" + modRuntimeOnly "maven.modrinth:threadtweak:${project.threadtweak_version_1_20}" + modRuntimeOnly "maven.modrinth:fadeless:${project.fadeless_version_1_20}" + + // Comment out the following dependencies to check vanilla compatibility + modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_20}" + modRuntimeOnly "maven.modrinth:double-hotbar:${project.double_hotbar_version_1_20}" + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +tasks.withType(JavaCompile).configureEach { + it.options.release = 17 +} diff --git a/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/MicroDurability120.java b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/MicroDurability120.java new file mode 100644 index 0000000..1ecfac1 --- /dev/null +++ b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/MicroDurability120.java @@ -0,0 +1,12 @@ +package com.github.reviversmc.microdurability; + +import net.fabricmc.api.ModInitializer; + +public class MicroDurability120 implements ModInitializer { + public static RendererBase renderer; + + @Override + public void onInitialize() { + renderer = new Renderer120(); + } +} diff --git a/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/Renderer120.java b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/Renderer120.java new file mode 100644 index 0000000..7f96e79 --- /dev/null +++ b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/Renderer120.java @@ -0,0 +1,49 @@ +package com.github.reviversmc.microdurability; + +import com.mojang.blaze3d.systems.RenderSystem; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; + +public class Renderer120 extends RendererBase { + @Override + protected void disableRenderSystems() { + RenderSystem.disableDepthTest(); + RenderSystem.disableBlend(); + } + + @Override + protected void enableRenderSystems() { + RenderSystem.enableBlend(); + RenderSystem.enableDepthTest(); + } + + @Override + protected void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height) { + ((DrawContext) context).drawTexture(texture, x, y, u, v, width, height); + } + + @Override + protected Iterable getHandItems(ClientPlayerEntity player) { + return player.getHandItems(); + } + + @Override + @SuppressWarnings("checkstyle:SingleSpaceSeparator") + protected void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha) { + RenderSystem.setShader(GameRenderer::getPositionColorProgram); + buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + buffer.vertex(x, y, 0.0D).color(red, green, blue, alpha).next(); + buffer.vertex(x, y + height, 0.0D).color(red, green, blue, alpha).next(); + buffer.vertex(x + width, y + height, 0.0D).color(red, green, blue, alpha).next(); + buffer.vertex(x + width, y, 0.0D).color(red, green, blue, alpha).next(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); + } +} diff --git a/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin120.java b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin120.java new file mode 100644 index 0000000..307f0d2 --- /dev/null +++ b/microdurability-1.20/src/main/java/com/github/reviversmc/microdurability/mixin/InGameHudMixin120.java @@ -0,0 +1,40 @@ +package com.github.reviversmc.microdurability.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.InGameHud; + +import com.github.reviversmc.microdurability.MicroDurability120; + +@Mixin(InGameHud.class) +public class InGameHudMixin120 { + @Shadow + private int ticks; + + @Inject( + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;renderStatusBars(Lnet/minecraft/client/gui/DrawContext;)V" + ), + method = "render" + ) + private void renderArmorArea(DrawContext context, float delta, CallbackInfo callbackInfo) { + MicroDurability120.renderer.renderArmorArea(context, ticks, delta); + } + + @Inject( + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;renderCrosshair(Lnet/minecraft/client/gui/DrawContext;)V" + ), + method = "render" + ) + private void renderHeldItemExclamationMark(DrawContext context, float delta, CallbackInfo callbackInfo) { + MicroDurability120.renderer.renderHeldItemLowDurabilityWarning(context, ticks, delta); + } +} diff --git a/microdurability-1.20/src/main/resources/fabric.mod.json b/microdurability-1.20/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..b3cc278 --- /dev/null +++ b/microdurability-1.20/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "microdurability", + "version": "${version}", + "name": "microDurability", + "description": "A very minimal durability viewer", + "authors": [ + "NebelNidas", + "dzwdz" + ], + "contributors": [ + "BlockBuilder57" + ], + "contact": { + "homepage": "https://www.curseforge.com/minecraft/mc-mods/microdurability", + "sources": "https://github.com/ReviversMC/microDurability", + "issues": "https://github.com/ReviversMC/microDurability/issues" + }, + "icon": "assets/microdurability/icon.png", + "license": "MPL-2.0", + "environment": "client", + "entrypoints": { + "main": [ + "com.github.reviversmc.microdurability.MicroDurability120" + ], + "modmenu": [ + "com.github.reviversmc.microdurability.integration.ModMenuIntegration" + ] + }, + "mixins": [ + "microdurability.mixins.json" + ], + "depends": { + "minecraft": ">=1.20-", + "microdurability-core": "*" + } +} diff --git a/microdurability-1.20/src/main/resources/microdurability.mixins.json b/microdurability-1.20/src/main/resources/microdurability.mixins.json new file mode 100644 index 0000000..68da4c5 --- /dev/null +++ b/microdurability-1.20/src/main/resources/microdurability.mixins.json @@ -0,0 +1,11 @@ +{ + "required": true, + "package": "com.github.reviversmc.microdurability.mixin", + "compatibilityLevel": "JAVA_17", + "client": [ + "InGameHudMixin120" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/MicroDurability.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/MicroDurability.java index 49ef513..c09f176 100644 --- a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/MicroDurability.java +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/MicroDurability.java @@ -3,12 +3,15 @@ import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; import net.fabricmc.api.ModInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.item.ItemStack; public class MicroDurability implements ModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger("MicroDurability"); public static ModConfig config; @Override @@ -22,8 +25,7 @@ public static boolean shouldWarn(ItemStack stack) { return false; } - if (config.lowDurabilityWarning.onlyOnMendingItems - && EnchantmentHelper.getLevel(Enchantments.MENDING, stack) <= 0) { + if (config.lowDurabilityWarning.onlyOnMendingItems && EnchantmentHelper.getLevel(Enchantments.MENDING, stack) <= 0) { return false; } diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModConfig.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModConfig.java index 0867eb5..79d1e67 100644 --- a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModConfig.java +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModConfig.java @@ -15,6 +15,9 @@ public static class ArmorBars { public boolean displayArmorBars = true; public boolean displayBarsForUndamagedArmor = true; + @ConfigEntry.BoundedDiscrete(min = -30, max = 50) + public int yOffset = 0; + @Comment("If an armor piece is undamaged, its bar will have the defined custom color.") @ConfigEntry.Gui.Tooltip public boolean useCustomBarColorForUndamagedArmor = false; diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/RendererBase.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/RendererBase.java index 3926418..18cf3f0 100644 --- a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/RendererBase.java +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/RendererBase.java @@ -1,86 +1,116 @@ package com.github.reviversmc.microdurability; -import com.mojang.blaze3d.systems.RenderSystem; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; -public abstract class RendererBase extends DrawableHelper { - protected static final Identifier TEX = new Identifier("microdurability", "textures/gui/icons.png"); +import com.github.reviversmc.microdurability.integration.DoubleHotbarCompat; +import com.github.reviversmc.microdurability.integration.RaisedCompat; + +public abstract class RendererBase { + private static final Identifier microdurabilityTexture = new Identifier("microdurability", "textures/gui/icons.png"); + private static final boolean doubleHotbarLoaded = FabricLoader.getInstance().isModLoaded("double_hotbar"); + private static boolean raisedLoaded = FabricLoader.getInstance().isModLoaded("raised"); private final MinecraftClient mc; - private float time = 0; protected RendererBase() { mc = MinecraftClient.getInstance(); + + if (!raisedLoaded) { + return; + } + } + + private int getRaisedOffset() { + if (!raisedLoaded) { + return 0; + } + + return RaisedCompat.getHotbarOffset(); + } + + private int getDoubleHotbarOffset() { + if (!doubleHotbarLoaded) { + return 0; + } + + return DoubleHotbarCompat.getHotbarHeight(); + } + + private boolean isTimeToShowWarning(int tick) { + if (MicroDurability.config.lowDurabilityWarning.blinkTime < 0.001) { + return true; + } + + return tick % (MicroDurability.config.lowDurabilityWarning.blinkTime * 40f) + > (MicroDurability.config.lowDurabilityWarning.blinkTime * 20f); } - public void onHudRender(MatrixStack matrixStack, float delta) { + public void renderHeldItemLowDurabilityWarning(Object context, int tick, float delta) { + if (!MicroDurability.config.lowDurabilityWarning.displayWarningForTools || !isTimeToShowWarning(tick)) { + return; + } + int scaledWidth = mc.getWindow().getScaledWidth(); int scaledHeight = mc.getWindow().getScaledHeight(); - time = (time + delta) % (MicroDurability.config.lowDurabilityWarning.blinkTime * 40f); - - // Render held item low durability warning - if (MicroDurability.config.lowDurabilityWarning.displayWarningForTools) { - for (ItemStack item : getHandItems(mc.player)) { - if (MicroDurability.shouldWarn(item)) { - if (MicroDurability.config.lowDurabilityWarning.blinkTime > 0 - && time < MicroDurability.config.lowDurabilityWarning.blinkTime * 20f) { - break; - } - - renderWarning(matrixStack, scaledWidth/2 - 2, scaledHeight/2 - 18); // TODO: This doesn't align with the crosshair at some resolutions - break; - } + + for (ItemStack item : getHandItems(mc.player)) { + if (!MicroDurability.shouldWarn(item)) { + continue; } + + // TODO: This doesn't align with the crosshair at some resolutions + int warningX = scaledWidth/2 - 2; + int warningY = scaledHeight/2 - 18; + + renderWarning(context, warningX, warningY); + break; } + } + + public void renderArmorArea(Object context, int tick, float delta) { + int scaledWidth = mc.getWindow().getScaledWidth(); + int scaledHeight = mc.getWindow().getScaledHeight(); int x = scaledWidth/2 - 7; - int y = scaledHeight - 30; + int y = scaledHeight - 30 - MicroDurability.config.armorBars.yOffset; if (mc.player.experienceLevel > 0) y -= 6; - if (FabricLoader.getInstance().getObjectShare().get("raised:distance") instanceof Integer distance) { - y -= distance; + boolean renderedWarning = MicroDurability.config.lowDurabilityWarning.displayWarningForArmor + && isTimeToShowWarning(tick) + && renderArmorLowDurabilityWarning(context, x+5, y-12); + + if (!renderedWarning && MicroDurability.config.armorBars.displayArmorBars) { + renderArmorBars(context, x, y - getRaisedOffset() - getDoubleHotbarOffset()); } + } - boolean canRenderArmorBar = true; - - // Render armor low durability warning - if (MicroDurability.config.lowDurabilityWarning.displayWarningForArmor) { - for (ItemStack armorPiece : mc.player.getArmorItems()) { - if (MicroDurability.shouldWarn(armorPiece)) { - if (MicroDurability.config.lowDurabilityWarning.blinkTime > 0 - && time < MicroDurability.config.lowDurabilityWarning.blinkTime * 20f) { - break; - } - - renderWarning(matrixStack, x+5, y-12); - canRenderArmorBar = false; - break; - } + public boolean renderArmorLowDurabilityWarning(Object context, int x, int y) { + for (ItemStack armorPiece : mc.player.getArmorItems()) { + if (!MicroDurability.shouldWarn(armorPiece)) { + continue; } + + renderWarning(context, x, y); + return true; } - // Render the armor durability - if (!canRenderArmorBar) return; + return false; + } - if (MicroDurability.config.armorBars.displayArmorBars) { - for (ItemStack armorPiece : mc.player.getArmorItems()) { - renderBar(armorPiece, x, y -= 3); - } + private void renderArmorBars(Object context, int x, int y) { + for (ItemStack armorPiece : mc.player.getArmorItems()) { + renderBar(armorPiece, x, y -= 3); } } - private void renderWarning(MatrixStack matrixStack, int x, int y) { - RenderSystem.setShaderTexture(0, TEX); - drawTexture(matrixStack, x, y, 0, 0, 3, 11); - RenderSystem.setShaderTexture(0, GUI_ICONS_TEXTURE); + private void renderWarning(Object context, int x, int y) { + drawWarningTexture(microdurabilityTexture, context, x, y, 0, 0, 3, 11); } private void renderBar(ItemStack stack, int x, int y) { @@ -118,6 +148,7 @@ private void renderBar(ItemStack stack, int x, int y) { protected abstract void enableRenderSystems(); protected abstract void disableRenderSystems(); + protected abstract void drawWarningTexture(Identifier texture, Object context, int x, int y, int u, int v, int width, int height); protected abstract Iterable getHandItems(ClientPlayerEntity e); protected abstract void renderGuiQuad(BufferBuilder buffer, int x, int y, int width, int height, int red, int green, int blue, int alpha); } diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/DoubleHotbarCompat.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/DoubleHotbarCompat.java new file mode 100644 index 0000000..68d810a --- /dev/null +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/DoubleHotbarCompat.java @@ -0,0 +1,134 @@ +package com.github.reviversmc.microdurability.integration; + +import java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Supplier; + +import com.github.reviversmc.microdurability.MicroDurability; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.Version; +import net.fabricmc.loader.api.VersionParsingException; + +public class DoubleHotbarCompat { + private static final Version INSTALLED_VERSION; + private static final Version V_1_1_0; + private static final Version V_1_2_0; + private static final Version V_1_3_1; + private static final Map configFieldErrored = new LinkedHashMap<>(); + private static boolean fatalError = false; + private static Supplier shiftSupplier; + + static { + INSTALLED_VERSION = FabricLoader.getInstance() + .getModContainer("double_hotbar") + .orElseThrow() + .getMetadata() + .getVersion(); + + try { + V_1_1_0 = Version.parse("1.1.0"); + V_1_2_0 = Version.parse("1.2.0"); + V_1_3_1 = Version.parse("1.3.0"); + } catch (VersionParsingException e) { + throw new RuntimeException(e); + } + } + + public static int getHotbarHeight() { + if (fatalError) { + return 0; + } else if (shiftSupplier == null) { + init(); + return getHotbarHeight(); + } + + return shiftSupplier.get(); + } + + private static void init() { + try { + Class config = Class.forName("com.sidezbros.double_hotbar.DHModConfig"); + Object configInstance = config.getDeclaredField("INSTANCE").get(null); + + Field secondBar = null; + Field shift = null; + Field disabled = null; + + if (INSTALLED_VERSION.compareTo(V_1_1_0) >= 0) { + try { + secondBar = config.getDeclaredField("displayDoubleHotbar"); + secondBar.setAccessible(true); + } catch (Throwable e) { + configFieldError("displayDoubleHotbar"); + } + } + + if (INSTALLED_VERSION.compareTo(V_1_2_0) >= 0) { + try { + shift = config.getDeclaredField("shift"); + shift.setAccessible(true); + } catch (Throwable e) { + configFieldError("shift"); + } + } + + if (INSTALLED_VERSION.compareTo(V_1_3_1) >= 0) { + try { + disabled = config.getDeclaredField("disableMod"); + disabled.setAccessible(true); + } catch (Throwable e) { + configFieldError("disableMod"); + } + } + + final Field finalSecondBar = secondBar; + final Field finalShift = shift; + final Field finalDisabled = disabled; + + shiftSupplier = () -> { + int height = 0; + + try { + if (finalSecondBar != null && !finalSecondBar.getBoolean(configInstance)) { + return height; + } + } catch (Throwable e) { + configFieldError("displayDoubleHotbar"); + } + + try { + if (finalDisabled != null && finalDisabled.getBoolean(configInstance)) { + return height; + } + } catch (Throwable e) { + configFieldError("disableMod"); + } + + try { + height += finalShift == null ? 21 : finalShift.getInt(configInstance); + } catch (Throwable e) { + configFieldError("shift"); + } + + return height; + }; + } catch (Throwable e) { + error("Failed to read the \"double_hotbar\" mod's config. Compatibility will be disabled."); + fatalError = true; + } + } + + private static void configFieldError(String fieldName) { + if (configFieldErrored.getOrDefault(fieldName, false)) { + return; + } + + error("Failed to read the \"double_hotbar\" mod's \"" + fieldName + "\" config value. This could lead to the armor durability bars being positioned at an incorrect height."); + configFieldErrored.put(fieldName, true); + } + + private static void error(String message) { + MicroDurability.LOGGER.error(message); + } +} diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModMenuIntegration.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/ModMenuIntegration.java similarity index 80% rename from microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModMenuIntegration.java rename to microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/ModMenuIntegration.java index 5bb84a6..61e3528 100644 --- a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/ModMenuIntegration.java +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/ModMenuIntegration.java @@ -1,4 +1,4 @@ -package com.github.reviversmc.microdurability; +package com.github.reviversmc.microdurability.integration; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; @@ -6,6 +6,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import com.github.reviversmc.microdurability.ModConfig; + @Environment(EnvType.CLIENT) public class ModMenuIntegration implements ModMenuApi { @Override diff --git a/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/RaisedCompat.java b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/RaisedCompat.java new file mode 100644 index 0000000..d8acbcd --- /dev/null +++ b/microdurability-core/src/main/java/com/github/reviversmc/microdurability/integration/RaisedCompat.java @@ -0,0 +1,35 @@ +package com.github.reviversmc.microdurability.integration; + +import net.fabricmc.loader.api.FabricLoader; + +import com.github.reviversmc.microdurability.MicroDurability; + +public class RaisedCompat { + private static String raisedHotbarOffsetObjectShareId; + private static boolean error = false; + + public static int getHotbarOffset() { + if (error) { + return 0; + } else if (raisedHotbarOffsetObjectShareId == null) { + init(); + return getHotbarOffset(); + } + + return (int) FabricLoader.getInstance().getObjectShare().get(raisedHotbarOffsetObjectShareId); + } + + private static void init() { + String oldId = "raised:distance"; + String newId = "raised:hud"; + + if (FabricLoader.getInstance().getObjectShare().get(oldId) instanceof Integer) { + raisedHotbarOffsetObjectShareId = oldId; + } else if (FabricLoader.getInstance().getObjectShare().get(newId) instanceof Integer) { + raisedHotbarOffsetObjectShareId = newId; + } else { + MicroDurability.LOGGER.error("Failed to find the \"raised\" mod's hotbar offset value in Fabric Loader's object share. Compatibility will be disabled."); + error = true; + } + } +} diff --git a/microdurability-core/src/main/resources/assets/microdurability/lang/en_us.json b/microdurability-core/src/main/resources/assets/microdurability/lang/en_us.json index ced1c76..54a5f86 100644 --- a/microdurability-core/src/main/resources/assets/microdurability/lang/en_us.json +++ b/microdurability-core/src/main/resources/assets/microdurability/lang/en_us.json @@ -4,6 +4,7 @@ "text.autoconfig.microdurability.category.armorBars": "Armor Bars", "text.autoconfig.microdurability.option.armorBars.displayArmorBars": "Display armor bars", "text.autoconfig.microdurability.option.armorBars.displayBarsForUndamagedArmor": "Display bars for undamaged armor", + "text.autoconfig.microdurability.option.armorBars.yOffset": "Additional vertical offset", "text.autoconfig.microdurability.option.armorBars.useCustomBarColorForUndamagedArmor": "Use custom bar color for undamaged armor", "text.autoconfig.microdurability.option.armorBars.useCustomBarColorForUndamagedArmor.@Tooltip": "If an armor piece is undamaged, its bar will have the defined custom color.", "text.autoconfig.microdurability.option.armorBars.customBarColorForUndamagedArmor": "Custom bar color for undamaged armor (#ARGB format)", diff --git a/settings.gradle b/settings.gradle index 79b4f2d..863723d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,3 +19,4 @@ include 'microdurability-core' include 'microdurability-1.17' include 'microdurability-1.19' include 'microdurability-1.19.4' +include 'microdurability-1.20'