diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java index 64fe9dd512..080985e2a3 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/movement/ClickTP.java @@ -11,8 +11,11 @@ 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; @@ -20,7 +23,10 @@ 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(); @@ -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; @@ -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)); + } }