diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientAccessor.java index 9a878dddef..cdc94cc8fd 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientAccessor.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientAccessor.java @@ -36,12 +36,6 @@ static int getFps() { @Accessor("networkProxy") Proxy getProxy(); - @Accessor("itemUseCooldown") - void setItemUseCooldown(int itemUseCooldown); - - @Accessor("itemUseCooldown") - int getItemUseCooldown(); - @Accessor("resourceReloadLogger") ResourceReloadLogger getResourceReloadLogger(); diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java index 46363df5e9..7f2f15c401 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/MinecraftClientMixin.java @@ -18,6 +18,7 @@ import meteordevelopment.meteorclient.mixininterface.IMinecraftClient; import meteordevelopment.meteorclient.systems.config.Config; import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.player.FastUse; import meteordevelopment.meteorclient.systems.modules.render.UnfocusedCPU; import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.misc.MeteorStarscript; @@ -30,6 +31,8 @@ import net.minecraft.client.option.GameOptions; import net.minecraft.client.util.Window; import net.minecraft.client.world.ClientWorld; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; import net.minecraft.util.hit.HitResult; import net.minecraft.util.profiler.Profiler; import org.jetbrains.annotations.Nullable; @@ -42,6 +45,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.concurrent.CompletableFuture; @@ -66,6 +70,9 @@ public abstract class MinecraftClientMixin implements IMinecraftClient { @Nullable public ClientPlayerInteractionManager interactionManager; + @Shadow + private int itemUseCooldown; + @Inject(method = "", at = @At("TAIL")) private void onInit(CallbackInfo info) { MeteorClient.INSTANCE.onInitializeClient(); @@ -114,6 +121,14 @@ private void onSetScreen(Screen screen, CallbackInfo info) { if (event.isCancelled()) info.cancel(); } + @Inject(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isItemEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z"), locals = LocalCapture.CAPTURE_FAILHARD) + private void onDoItemUseHand(CallbackInfo ci, Hand[] var1, int var2, int var3, Hand hand, ItemStack itemStack) { + FastUse fastUse = Modules.get().get(FastUse.class); + if (fastUse.isActive()) { + itemUseCooldown = fastUse.getItemUseCooldown(itemStack); + } + } + @ModifyExpressionValue(method = "doItemUse", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;crosshairTarget:Lnet/minecraft/util/hit/HitResult;", ordinal = 1)) private HitResult doItemUseMinecraftClientCrosshairTargetProxy(HitResult original) { return MeteorClient.EVENT_BUS.post(ItemUseCrosshairTargetEvent.get(original)).target; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/FastUse.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/FastUse.java index f3cf17ab38..0a17c7d48a 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/player/FastUse.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/player/FastUse.java @@ -5,12 +5,9 @@ package meteordevelopment.meteorclient.systems.modules.player; -import meteordevelopment.meteorclient.events.world.TickEvent; -import meteordevelopment.meteorclient.mixin.MinecraftClientAccessor; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Categories; import meteordevelopment.meteorclient.systems.modules.Module; -import meteordevelopment.orbit.EventHandler; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -60,15 +57,11 @@ public FastUse() { super(Categories.Player, "fast-use", "Allows you to use items at very high speeds."); } - @EventHandler - private void onTick(TickEvent.Post event) { - int cooldownTicks = Math.min(((MinecraftClientAccessor) mc).getItemUseCooldown(), cooldown.get()); - if (mode.get() == Mode.All || shouldWorkSome()) ((MinecraftClientAccessor) mc).setItemUseCooldown(cooldownTicks); - } - - private boolean shouldWorkSome() { - if (shouldWorkSome(mc.player.getMainHandStack())) return true; - return shouldWorkSome(mc.player.getOffHandStack()); + public int getItemUseCooldown(ItemStack itemStack) { + if (mode.get() == Mode.All || shouldWorkSome(itemStack)) { + return cooldown.get(); + } + return 4; //default cooldown } private boolean shouldWorkSome(ItemStack itemStack) {