Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help me resolve this issue #300

Open
Akash47007 opened this issue Dec 27, 2024 · 0 comments
Open

Help me resolve this issue #300

Akash47007 opened this issue Dec 27, 2024 · 0 comments

Comments

@Akash47007
Copy link

Akash47007 commented Dec 27, 2024

`
package com.example.autoaim;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket;
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket.Mode;

@Environment(EnvType.CLIENT)
public class AutoAimMod implements ClientModInitializer {

    private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
    private static final double AIM_RANGE = 10.0; // Adjustable range for auto-aim

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (CLIENT.player != null && CLIENT.options.useKey.isPressed()) { // Trigger auto-aim when "use" key is pressed
                LivingEntity target = getNearestEntity();
                if (target != null) {
                    aimAt(target);
                    triggerCriticalHit();
                }
            }
        });
    }

    private LivingEntity getNearestEntity() {
        if (CLIENT.world == null || CLIENT.player == null) {
            return null;
        }

        return CLIENT.world.getEntities().stream()
                .filter(entity -> entity instanceof LivingEntity && entity != CLIENT.player)
                .map(entity -> (LivingEntity) entity)
                .filter(entity -> entity.isAlive() && CLIENT.player.squaredDistanceTo(entity) <= AIM_RANGE * AIM_RANGE)
                .min((e1, e2) -> {
                    double dist1 = CLIENT.player.squaredDistanceTo(e1);
                    double dist2 = CLIENT.player.squaredDistanceTo(e2);
                    return Double.compare(dist1, dist2);
                })
                .orElse(null);
    }

    private void aimAt(LivingEntity target) {
        Vec3d playerPos = CLIENT.player.getPos();
        Vec3d targetPos = target.getEyePos();
        Vec3d direction = targetPos.subtract(playerPos).normalize();

        double pitch = -Math.toDegrees(Math.asin(direction.y));
        double yaw = Math.toDegrees(Math.atan2(direction.z, direction.x)) - 90.0;

        CLIENT.player.setYaw((float) yaw);
        CLIENT.player.setPitch((float) pitch);
    }

    private void triggerCriticalHit() {
        if (CLIENT.player != null && CLIENT.player.isOnGround()) {
            CLIENT.getNetworkHandler().sendPacket(new ClientCommandC2SPacket(CLIENT.player, Mode.START_FALL_FLYING));
        }
    }
}

`

I tried all the steps that I could find but the error is that net.minecraft.client.MinecraftClient does not exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant