Skip to content

Commit

Permalink
Compat MeteorClient (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed Sep 9, 2022
1 parent 660fff6 commit 8368f68
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package top.hendrixshen.tweakmyclient.compat.meteor;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MeteorHelper {
private static Method isNoSlowMethod;
private static Object noSlowInstance;

static {
try {
Class<?> meteorModules = Class.forName("meteordevelopment.meteorclient.systems.modules.Modules");
Method getMeteorModulesMethod = meteorModules.getDeclaredMethod("get");
getMeteorModulesMethod.setAccessible(true);
Object meteorModulesInstance = getMeteorModulesMethod.invoke(null);
Method getModuleMethod = meteorModules.getDeclaredMethod("get", Class.class);
Class<?> noSlowClass = Class.forName("meteordevelopment.meteorclient.systems.modules.movement.NoSlow");
getModuleMethod.setAccessible(true);
MeteorHelper.noSlowInstance = getModuleMethod.invoke(meteorModulesInstance, noSlowClass);
MeteorHelper.isNoSlowMethod = noSlowClass.getDeclaredMethod("items");
MeteorHelper.isNoSlowMethod.setAccessible(true);
} catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
}

public static boolean isNoSlowdownHackEnable() {
if (MeteorHelper.noSlowInstance != null) {
try {
return (boolean) MeteorHelper.isNoSlowMethod.invoke(MeteorHelper.noSlowInstance);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package top.hendrixshen.tweakmyclient.compat.meteor.mixin;

import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import top.hendrixshen.magiclib.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.dependency.annotation.Dependency;
import top.hendrixshen.tweakmyclient.compat.meteor.MeteorHelper;
import top.hendrixshen.tweakmyclient.compat.wurst.WurstHelper;
import top.hendrixshen.tweakmyclient.config.Configs;
import top.hendrixshen.tweakmyclient.util.mixin.MixinType;
import top.hendrixshen.tweakmyclient.util.mixin.annotation.MagicAttack;
import top.hendrixshen.tweakmyclient.util.mixin.annotation.MagicInterruption;

@MagicInterruption(targets = "meteordevelopment.meteorclient.mixin.ClientPlayerEntityMixin")
@Dependencies(and = @Dependency(value = "meteor-client"))
@Mixin(value = LocalPlayer.class, priority = 1100)
public abstract class MixinLocalPlayer extends LivingEntity {
@Shadow
private boolean startedUsingItem;

protected MixinLocalPlayer(EntityType<? extends LivingEntity> entityType, Level level) {
super(entityType, level);
}

@MagicAttack(
type = MixinType.REDIRECT,
name = "wurstIsUsingItem",
owner = "class_1309",
method = "method_6007",
desc = "()V"
)
private boolean tmc$getUsingItemState(LocalPlayer instance) {
if (Configs.disableSlowdown || MeteorHelper.isNoSlowdownHackEnable()) {
return false;
}
return this.startedUsingItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import top.hendrixshen.magiclib.dependency.annotation.Dependency;
import top.hendrixshen.tweakmyclient.config.Configs;

@Dependencies(not = @Dependency(value = "wurst"))
@Dependencies(
not = {
@Dependency(value = "meteor-client"),
@Dependency(value = "wurst")
}
)
@Mixin(LocalPlayer.class)
public abstract class MixinLocalPlayer extends LivingEntity {
@Shadow
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"mixins": [
"${mod_id}.mixins.json",
"${mod_id}-compat-meteor.mixins.json",
"${mod_id}-compat-wurst.mixins.json"
],
"depends": {
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/tweakmyclient-compat-meteor.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "top.hendrixshen.tweakmyclient.compat.meteor.mixin",
"plugin": "top.hendrixshen.tweakmyclient.compat.CompatMixinPlugin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"MixinLocalPlayer"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 8368f68

Please sign in to comment.