Skip to content

Commit

Permalink
Fix Aqua Acrobatics in a tricky way
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Jan 8, 2024
1 parent 83a8695 commit e3539e6
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Also check [The Fugue Plane](https://forgottenrealms.fandom.com/wiki/Fugue_Plane
* Lag Goggles
* Snow! Real Magic
* Botania Tweaks
* Aqua Acrobatics

## Note
Add ! to start of the file name to fix Lag Goggles.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mappings_version=39-1.12
mod_id=fugue
mod_name=Fugue
mod_main_class=Fugue
mod_version=0.2.0
mod_version=0.3.0
mod_base_package=com.cleanroommc.fugue
mod_authors=kappa_maintainer
mod_description=A mod that patch dead mods for Cleanroom
9 changes: 8 additions & 1 deletion src/main/java/com/cleanroommc/FugueLoadingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import zone.rong.mixinbooter.IEarlyMixinLoader;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@IFMLLoadingPlugin.MCVersion("1.12.2")
public class FugueLoadingPlugin implements IFMLLoadingPlugin {
public class FugueLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader {
static {
Launch.classLoader.addTransformerExclusionFilter("com.github.terminatornl.laggoggles.");
Launch.classLoader.addTransformerExclusionFilter("quaternary.botaniatweaks.");
Expand Down Expand Up @@ -44,4 +47,8 @@ public String getAccessTransformerClass() {
return null;
}

@Override
public List<String> getMixinConfigs() {
return Collections.singletonList("fugue.mixin.aquaacrobatics.json");
}
}
80 changes: 80 additions & 0 deletions src/main/java/com/cleanroommc/PostApplyMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.cleanroommc;

import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class PostApplyMixinPlugin implements IMixinConfigPlugin {
private static boolean hit = false;
@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
if (hit || !targetClassName.equals("net.minecraft.client.renderer.BlockFluidRenderer")) {
return;
}
for (MethodNode methodNode : targetClass.methods) {
if (methodNode != null) {
InsnList insnList = methodNode.instructions;
if (insnList != null)
for (AbstractInsnNode abstractInsnNode : insnList) {
if (abstractInsnNode instanceof MethodInsnNode methodInsnNode) {
if (methodInsnNode.owner.startsWith("org/spongepowered/asm/synthetic/args/Args$")) {
if (methodInsnNode.name.equals("of")) {
methodInsnNode.owner = "com/cleanroommc/helper/ArgsHelper";
methodInsnNode.desc = "(FFFF)Lcom/cleanroommc/helper/ArgsHelper;";
}
if (methodInsnNode.name.startsWith("$")) {
int index = Integer.parseInt(methodInsnNode.name.substring(1));
if (index < 6) {
insnList.insertBefore(methodInsnNode, new InsnNode(Opcodes.ICONST_0 + index));
} else {
insnList.insertBefore(methodInsnNode, new LdcInsnNode(index));
}
insnList.insert(methodInsnNode, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F"));
insnList.insert(methodInsnNode, new TypeInsnNode(Opcodes.CHECKCAST, "java/lang/Float"));
methodInsnNode.owner = "com/cleanroommc/helper/ArgsHelper";
methodInsnNode.desc = "(I)Ljava/lang/Object;";
methodInsnNode.name = "get";
hit = true;
}
}
}
}
}
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/cleanroommc/helper/ArgsHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cleanroommc.helper;

import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

public class ArgsHelper extends Args {
private Object[] args;
/**
* Ctor.
*
* @param values argument values
*/
protected ArgsHelper(Object[] values) {
super(values);
args = values;
}

@Override
public <T> void set(int index, T value) {
args[index] = value;
}

@Override
public void setAll(Object... values) {
args = values;
}

@Override
public int size() {
return this.args.length;
}

@Override
@SuppressWarnings("unchecked")
public <T> T get(int index) {
return (T)this.args[index];
}

public static ArgsHelper of(float a, float b, float c, float d) {
return new ArgsHelper(new Object[]{a,b,c,d});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cleanroommc;
package com.cleanroommc.helper;

import scala.tools.asm.Opcodes;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cleanroommc.mixin.aquaacrobatics;

import net.minecraft.client.renderer.BlockFluidRenderer;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = BlockFluidRenderer.class, priority = 0)
public class BlockFluidRendererMixin {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Function;

@Mixin(value = Colorspaces.class, remap = false)
@SuppressWarnings("unchecked")
public class ColorspacesMixin {
@Shadow private static Table<Colorspace, Colorspace, Function<float[], float[]>> conversionTable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public byte[] transform(String s, String s1, byte[] bytes) {
return null;
}

if (!s1.equals("com.enderio.core.common.transform.EnderCoreTransformer") || hit)
if (hit || !s1.equals("com.enderio.core.common.transform.EnderCoreTransformer"))
{
return bytes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.cleanroommc.transformer;

import com.cleanroommc.Fugue;
import com.cleanroommc.HookHelper;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
Expand All @@ -18,7 +16,7 @@ public byte[] transform(String s, String s1, byte[] bytes) {
return null;
}

if (!s1.equals("com.github.terminatornl.laggoggles.tickcentral.Initializer") || hit)
if (hit || !s1.equals("com.github.terminatornl.laggoggles.tickcentral.Initializer"))
{
return bytes;
}
Expand All @@ -43,7 +41,7 @@ public byte[] transform(String s, String s1, byte[] bytes) {
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 10));
toInsert.add(new VarInsnNode(Opcodes.ILOAD, 6));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/cleanroommc/HookHelper", "isInterface", "(I)Z"));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/cleanroommc/helper/HookHelper", "isInterface", "(I)Z"));
toInsert.add(new FieldInsnNode(Opcodes.PUTFIELD, "org/objectweb/asm/tree/MethodInsnNode", "itf", "Z"));
instructions.insert(fieldInsnNode, toInsert);
modified = true;
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/fugue.mixin.aquaacrobatics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"package": "com.cleanroommc.mixin.aquaacrobatics",
"compatibilityLevel": "JAVA_8",
"refmap": "fugue.mixin.refmap.json",
"plugin": "com.cleanroommc.PostApplyMixinPlugin",
"mixins": [
"BlockFluidRendererMixin"
],
"client": [
],
"minVersion": "0.8"
}

0 comments on commit e3539e6

Please sign in to comment.