Skip to content

Commit

Permalink
Add 1.20.5 support; use better injection points
Browse files Browse the repository at this point in the history
  • Loading branch information
NebelNidas committed Jun 13, 2024
1 parent 92c7f05 commit 6534ce9
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: "temurin"
cache: gradle

Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: "temurin"
cache: gradle

Expand All @@ -37,8 +37,8 @@ jobs:
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
files: build/libs/!(*-@(dev|sources)).jar
name: 0.3.6 for MC 1.17 to MC 1.20.4
version: 0.3.6+1.17-1.20
name: 0.3.6 for MC 1.17 to MC 1.20.6
version: 0.3.6+1.17-1.20.5
version-type: release
loaders: |
fabric
Expand All @@ -58,6 +58,8 @@ jobs:
1.20.2
1.20.3
1.20.4
1.20.5
1.20.6
dependencies: |
cloth-config | depends
modmenu | recommends
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ dependencies {
include api(project(path: ':microdurability-1.19', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.19.4', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.20', configuration: 'namedElements'))
include api(project(path: ':microdurability-1.20.5', configuration: 'namedElements'))

modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version_1_20}"
modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version_1_20}") {
modRuntimeOnly "com.terraformersmc:modmenu:${project.modmenu_version_1_20_5}"
modRuntimeOnly("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version_1_20_5}") {
exclude(group: 'net.fabricmc.fabric-api')
}

minecraft "com.mojang:minecraft:${minecraft_version_1_20}"
mappings "net.fabricmc:yarn:${project.yarn_mappings_1_20}:v2"
minecraft "com.mojang:minecraft:${minecraft_version_1_20_5}"
mappings "net.fabricmc:yarn:${project.yarn_mappings_1_20_5}:v2"
}


Expand Down
14 changes: 14 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ cloth_config_version_1_19_4 = 10.1.117
minecraft_version_1_20 = 1.20.1
yarn_mappings_1_20 = 1.20.1+build.10
cloth_config_version_1_20 = 11.1.118
# 1.20.5
minecraft_version_1_20_5 = 1.20.6
yarn_mappings_1_20_5 = 1.20.6+build.3
cloth_config_version_1_20_5 = 14.0.126

# Dev-Env Mods
use_third_party_mods = true
Expand Down Expand Up @@ -83,3 +87,13 @@ 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
# 1.20.5
fabric_api_version_1_20_5 = 0.100.0+1.20.6
modmenu_version_1_20_5 = 10.0.0-beta.1
sodium_version_1_20_5 = mc1.20.6-0.5.8
lithium_version_1_20_5 = mc1.20.6-0.12.3
ferritecore_version_1_20_5 = 6.1.1-fabric
threadtweak_version_1_20_5 = 0.1.3+mc1.20.6
fadeless_version_1_20_5 = 1.0.1
raised_version_1_20_5 = Fabric-24w10a-3.1.3
# double_hotbar_version_1_20_5 =
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,13 @@ public class InGameHudMixin117 {
@Shadow
private int ticks;

@Inject(
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/hud/InGameHud;renderStatusBars(Lnet/minecraft/client/util/math/MatrixStack;)V"
),
method = "render"
)
private void renderArmorArea(MatrixStack matrices, float delta, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(matrices, ticks, delta);
@Inject(method = "renderHotbar", at = @At("HEAD"))
private void renderArmorArea(float delta, MatrixStack matrices, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(matrices, ticks);
}

@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) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(matrices, ticks, delta);
@Inject(method = "renderCrosshair", at = @At("HEAD"))
private void renderHeldItemExclamationMark(MatrixStack matrices, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(matrices, ticks);
}
}
41 changes: 41 additions & 0 deletions microdurability-1.20.5/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
base {
archivesName = archivesName.get() + '-compat-1.20.5'
}

dependencies {
api project(path: ':microdurability-1.20', configuration: 'namedElements')

minecraft "com.mojang:minecraft:${project.minecraft_version_1_20_5}"
mappings "net.fabricmc:yarn:${project.yarn_mappings_1_20_5}:v2"

// Other mods
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version_1_20_5}"
modImplementation("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version_1_20_5}") {
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_5}"

modRuntimeOnly "maven.modrinth:sodium:${project.sodium_version_1_20_5}"
modRuntimeOnly "maven.modrinth:lithium:${project.lithium_version_1_20_5}"
modRuntimeOnly "maven.modrinth:ferrite-core:${project.ferritecore_version_1_20_5}"
modRuntimeOnly "maven.modrinth:threadtweak:${project.threadtweak_version_1_20_5}"
modRuntimeOnly "maven.modrinth:fadeless:${project.fadeless_version_1_20_5}"

// Comment out the following dependencies to check vanilla compatibility
modRuntimeOnly "maven.modrinth:raised:${project.raised_version_1_20_5}"
// modRuntimeOnly "maven.modrinth:double-hotbar:${project.double_hotbar_version_1_20_5}"
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 21
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.reviversmc.microdurability;

import java.util.function.Supplier;

import com.github.reviversmc.microdurability.mccompat.McVersionCompatInitializer;
import com.github.reviversmc.microdurability.mccompat.McVersionHelper;

public class MicroDurability1205 extends McVersionCompatInitializer {
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.20.5", McVersionHelper.INFINITY);

@Override
public boolean isCompatible() {
return IS_COMPATIBLE.get();
}

@Override
protected void initialize() {
MicroDurability.renderer = new Renderer1205();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.github.reviversmc.microdurability;

import java.util.List;

import com.github.reviversmc.microdurability.mccompat.McVersionMixinProvider;

public class MixinProvider1205 extends McVersionMixinProvider {
@Override
public List<String> getMixins() {
if (MicroDurability1205.IS_COMPATIBLE.get()) {
return List.of("InGameHudMixin1205");
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.reviversmc.microdurability;

public class Renderer1205 extends Renderer120 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.MicroDurability;

@Mixin(InGameHud.class)
public class InGameHudMixin1205 {
@Shadow
private int ticks;

@Inject(method = "renderHotbar", at = @At("HEAD"))
private void renderArmorArea(DrawContext context, float delta, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(context, ticks);
}

@Inject(method = "renderCrosshair", at = @At("HEAD"))
private void renderHeldItemExclamationMark(DrawContext context, float delta, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(context, ticks);
}
}
32 changes: 32 additions & 0 deletions microdurability-1.20.5/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"schemaVersion": 1,
"id": "microdurability-compat-1-20-5",
"version": "${version}",
"name": "microDurability 1.20.5 Compat",
"license": "MPL-2.0",
"environment": "client",
"entrypoints": {
"microdurability": [
"com.github.reviversmc.microdurability.MicroDurability1205"
],
"modmenu": [
"com.github.reviversmc.microdurability.integration.ModMenuIntegration"
]
},
"mixins": [
"microdurability1205.mixins.json"
],
"depends": {
"fabricloader": ">=0.12.9",
"minecraft": ">=1.20.5",
"microdurability-compat-1-20": "*"
},
"custom": {
"modmenu": {
"badges": ["library"],
"parent": {
"id": "microdurability"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"required": true,
"package": "com.github.reviversmc.microdurability.mixin",
"compatibilityLevel": "JAVA_21",
"plugin": "com.github.reviversmc.microdurability.MixinProvider1205",
"injectors": {
"defaultRequire": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.reviversmc.microdurability.mccompat.McVersionHelper;

public class MicroDurability120 extends McVersionCompatInitializer {
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.20", McVersionHelper.INFINITY);
static final Supplier<Boolean> IS_COMPATIBLE = () -> McVersionHelper.isWithin("1.20", "1.20.4");

@Override
public boolean isCompatible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,13 @@ 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) {
MicroDurability.renderer.renderArmorArea(context, ticks, delta);
@Inject(method = "renderHotbar", at = @At("HEAD"))
private void renderArmorArea(float delta, DrawContext context, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderArmorArea(context, ticks);
}

@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) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(context, ticks, delta);
@Inject(method = "renderCrosshair", at = @At("HEAD"))
private void renderHeldItemExclamationMark(DrawContext context, CallbackInfo callbackInfo) {
MicroDurability.renderer.renderHeldItemLowDurabilityWarning(context, ticks);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static boolean shouldWarn(ItemStack stack) {
return damageAbsoluteValueEnough && damagePercentageEnough;
}

public void renderHeldItemLowDurabilityWarning(Object context, int tick, float delta) {
public void renderHeldItemLowDurabilityWarning(Object context, int tick) {
if (!MicroDurability.config.lowDurabilityWarning.displayWarningForTools
|| mc.options.hudHidden
|| !isTimeToShowWarning(tick)) {
Expand All @@ -92,7 +92,7 @@ public void renderHeldItemLowDurabilityWarning(Object context, int tick, float d
}
}

public void renderArmorArea(Object context, int tick, float delta) {
public void renderArmorArea(Object context, int tick) {
if (mc.options.hudHidden) {
return;
}
Expand All @@ -101,15 +101,15 @@ public void renderArmorArea(Object context, int tick, float delta) {
int scaledHeight = mc.getWindow().getScaledHeight();

int x = scaledWidth/2 - 7;
int y = scaledHeight - 30 - MicroDurability.config.armorBars.yOffset;
int y = scaledHeight - 30 - getDoubleHotbarOffset() - MicroDurability.config.armorBars.yOffset;
if (mc.player.experienceLevel > 0) y -= 6;

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());
renderArmorBars(context, x, y - getRaisedOffset());
}
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ include 'microdurability-1.17'
include 'microdurability-1.19'
include 'microdurability-1.19.4'
include 'microdurability-1.20'
include 'microdurability-1.20.5'

0 comments on commit 6534ce9

Please sign in to comment.