Skip to content

Commit

Permalink
Fix fastuse when item is in offhand (MeteorDevelopment#4019)
Browse files Browse the repository at this point in the history
  • Loading branch information
19MisterX98 authored Aug 29, 2023
1 parent e066654 commit 0b32e28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -66,6 +70,9 @@ public abstract class MinecraftClientMixin implements IMinecraftClient {
@Nullable
public ClientPlayerInteractionManager interactionManager;

@Shadow
private int itemUseCooldown;

@Inject(method = "<init>", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
MeteorClient.INSTANCE.onInitializeClient();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0b32e28

Please sign in to comment.