aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-26 10:11:23 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-26 10:12:18 +0200
commit041da7c7d179df01c4048a81ddf40a9f13c3ce77 (patch)
tree6e6933320c8e96a22bfe433b1e33b184948b8fbd /src/main/java/moe
parentc264ca9e8f9f2b0aed457753c43bb4e25edb0ef1 (diff)
downloadfirmament-041da7c7d179df01c4048a81ddf40a9f13c3ce77.tar.gz
firmament-041da7c7d179df01c4048a81ddf40a9f13c3ce77.tar.bz2
firmament-041da7c7d179df01c4048a81ddf40a9f13c3ce77.zip
Add fuel durability bar
Diffstat (limited to 'src/main/java/moe')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/CustomDurabilityBarPatch.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomDurabilityBarPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomDurabilityBarPatch.java
new file mode 100644
index 0000000..f396ce6
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/mixins/CustomDurabilityBarPatch.java
@@ -0,0 +1,58 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.mixins;
+
+import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
+import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
+import com.llamalad7.mixinextras.sugar.Share;
+import com.llamalad7.mixinextras.sugar.ref.LocalRef;
+import moe.nea.firmament.util.DurabilityBarEvent;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.item.ItemStack;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+
+@Mixin(DrawContext.class)
+public class CustomDurabilityBarPatch {
+ @WrapOperation(
+ method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V",
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isItemBarVisible()Z")
+ )
+ private boolean onIsItemBarVisible(
+ ItemStack instance, Operation<Boolean> original,
+ @Share("barOverride") LocalRef<DurabilityBarEvent.DurabilityBar> barOverride
+ ) {
+ if (original.call(instance))
+ return true;
+ DurabilityBarEvent event = new DurabilityBarEvent(instance);
+ DurabilityBarEvent.Companion.publish(event);
+ barOverride.set(event.getBarOverride());
+ return barOverride.get() != null;
+ }
+
+ @WrapOperation(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V",
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItemBarStep()I"))
+ private int overrideItemStep(
+ ItemStack instance, Operation<Integer> original,
+ @Share("barOverride") LocalRef<DurabilityBarEvent.DurabilityBar> barOverride
+ ) {
+ if (barOverride.get() != null)
+ return Math.round(barOverride.get().getPercentage() * 13);
+ return original.call(instance);
+ }
+
+ @WrapOperation(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V",
+ at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItemBarColor()I"))
+ private int overrideItemColor(
+ ItemStack instance, Operation<Integer> original,
+ @Share("barOverride") LocalRef<DurabilityBarEvent.DurabilityBar> barOverride
+ ) {
+ if (barOverride.get() != null)
+ return barOverride.get().getColor().getColor();
+ return original.call(instance);
+ }
+}