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

update clickTP to work in freecam #4146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.Freecam;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.RaycastContext;

public class ClickTP extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();
Expand All @@ -41,7 +47,22 @@ private void onTick(TickEvent.Post event) {
if (mc.player.isUsingItem()) return;

if (mc.options.useKey.isPressed()) {
HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);

// ensure compatibility to freecam mods which change the cameraEntity
Entity rayStart = mc.cameraEntity == null ? mc.player : mc.cameraEntity;

Vec3d startPos = rayStart.getCameraPosVec(1f/20f);
Vec3d rotationVec = rayStart.getRotationVec(1f/20f);

if(Modules.get().get(Freecam.class).isActive()){
Freecam cam=Modules.get().get(Freecam.class);
startPos=new Vec3d(cam.pos.x,cam.pos.y,cam.pos.z);
rotationVec=getRotationVector(cam.pitch, cam.yaw);
}

Vec3d endPos = startPos.add(rotationVec.x * maxDistance.get(), rotationVec.y * maxDistance.get(), rotationVec.z * maxDistance.get());
HitResult hitResult = mc.world.raycast(new RaycastContext(startPos, endPos, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, rayStart));


if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS) return;

Expand All @@ -62,4 +83,15 @@ private void onTick(TickEvent.Post event) {
}
}
}

//copied from entity.class
protected final Vec3d getRotationVector(float pitch, float yaw) {
float f = pitch * 0.017453292F;
float g = -yaw * 0.017453292F;
float h = MathHelper.cos(g);
float i = MathHelper.sin(g);
float j = MathHelper.cos(f);
float k = MathHelper.sin(f);
return new Vec3d((i * j), (-k), (h * j));
}
}