aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/init
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-11-01 23:00:53 +0100
committerLinnea Gräf <nea@nea.moe>2024-11-01 23:00:53 +0100
commit8b410fbdf2cffb3ceaa51bbea150f5165848bc37 (patch)
treee4b4ec4ba24a7edbefa45b7deb2503b74214ee02 /src/main/java/moe/nea/firmament/init
parent653454e290a1bb6142e2bb40947239c2e450820b (diff)
downloadFirmament-8b410fbdf2cffb3ceaa51bbea150f5165848bc37.tar.gz
Firmament-8b410fbdf2cffb3ceaa51bbea150f5165848bc37.tar.bz2
Firmament-8b410fbdf2cffb3ceaa51bbea150f5165848bc37.zip
Add tint override to texture packs
Diffstat (limited to 'src/main/java/moe/nea/firmament/init')
-rw-r--r--src/main/java/moe/nea/firmament/init/EarlyRiser.java1
-rw-r--r--src/main/java/moe/nea/firmament/init/ItemColorsSodiumRiser.java64
2 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/firmament/init/EarlyRiser.java b/src/main/java/moe/nea/firmament/init/EarlyRiser.java
index 5eab563..9734e94 100644
--- a/src/main/java/moe/nea/firmament/init/EarlyRiser.java
+++ b/src/main/java/moe/nea/firmament/init/EarlyRiser.java
@@ -7,5 +7,6 @@ public class EarlyRiser implements Runnable {
new ClientPlayerRiser().addTinkerers();
new HandledScreenRiser().addTinkerers();
new SectionBuilderRiser().addTinkerers();
+ new ItemColorsSodiumRiser().addTinkerers();
}
}
diff --git a/src/main/java/moe/nea/firmament/init/ItemColorsSodiumRiser.java b/src/main/java/moe/nea/firmament/init/ItemColorsSodiumRiser.java
new file mode 100644
index 0000000..80ee9aa
--- /dev/null
+++ b/src/main/java/moe/nea/firmament/init/ItemColorsSodiumRiser.java
@@ -0,0 +1,64 @@
+package moe.nea.firmament.init;
+
+import me.shedaniel.mm.api.ClassTinkerers;
+import moe.nea.firmament.util.ErrorUtil;
+import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.client.color.item.ItemColorProvider;
+import net.minecraft.client.color.item.ItemColors;
+import net.minecraft.item.ItemStack;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.InsnNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.VarInsnNode;
+
+public class ItemColorsSodiumRiser extends RiserUtils {
+ @IntermediaryName(ItemColors.class)
+ String ItemColors;
+ @IntermediaryName(ItemColorProvider.class)
+ String ItemColorProvider;
+ @IntermediaryName(ItemStack.class)
+ String ItemStack;
+ String getColorProvider = "sodium$getColorProvider";
+ Type getColorProviderDesc = Type.getMethodType(getTypeForClassName(ItemColorProvider),
+ getTypeForClassName(ItemStack));
+
+ @Override
+ public void addTinkerers() {
+ ClassTinkerers.addTransformation(ItemColors, this::addSodiumOverride, true);
+ }
+
+ private void addSodiumOverride(ClassNode classNode) {
+ var node = findMethod(classNode, getColorProvider, getColorProviderDesc);
+ if (node == null) {
+ if (!FabricLoader.getInstance().isModLoaded("sodium"))
+ ErrorUtil.INSTANCE.softError("Sodium is present, but sodium color override could not be injected.");
+ return;
+ }
+ var p = node.instructions.getFirst();
+ while (p != null) {
+ if (p.getOpcode() == Opcodes.ARETURN) {
+ node.instructions.insertBefore(
+ p,
+ mkOverrideSodiumCall()
+ );
+ }
+ p = p.getNext();
+ }
+ }
+
+ private InsnList mkOverrideSodiumCall() {
+ var insnList = new InsnList();
+ insnList.add(new VarInsnNode(Opcodes.ALOAD, 0));
+ insnList.add(new InsnNode(Opcodes.SWAP));
+ insnList.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
+ getTypeForClassName(ItemColors).getInternalName(),
+ "overrideSodium_firmament",
+ Type.getMethodType(getTypeForClassName(ItemColorProvider),
+ getTypeForClassName(ItemColorProvider)).getDescriptor(),
+ false));
+ return insnList;
+ }
+}