From c4ec472a72924269c9a73df825d2940ffdb5d358 Mon Sep 17 00:00:00 2001 From: mems01 <70612656+mems01@users.noreply.github.com> Date: Sat, 9 Sep 2023 16:46:48 +0300 Subject: [PATCH] Made ProjectilePuncher mathematically ignore the user's own moving fireball. (#1302) --- .../modules/world/ModuleProjectilePuncher.kt | 14 +++++++++++++- .../liquidbounce/utils/entity/EntityExtensions.kt | 11 +++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleProjectilePuncher.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleProjectilePuncher.kt index 356f7dfbb04..a1a6c50511b 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleProjectilePuncher.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/ModuleProjectilePuncher.kt @@ -38,6 +38,7 @@ import net.minecraft.entity.projectile.FireballEntity import net.minecraft.entity.projectile.ShulkerBulletEntity import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket import net.minecraft.util.Hand +import net.minecraft.util.math.Vec3d /** * ProjectilePuncher module @@ -100,7 +101,18 @@ object ModuleProjectilePuncher : Module("ProjectilePuncher", Category.WORLD) { continue } - if (entity.squaredBoxedDistanceTo(player) > rangeSquared) { + val distance = entity.squaredBoxedDistanceTo(player) + + val entityPrediction = Vec3d( + entity.x - entity.prevX, entity.y - entity.prevY, entity.z - entity.prevZ + ) + + // Avoid fireball if its speed-predicted next position goes further than the normal distance. + // Useful in preventing the user from changing their own thrown fireball's direction + if (distance > rangeSquared || entity is FireballEntity && (entity.age <= 1 && entityPrediction == Vec3d.ZERO || entity.box.offset( + entityPrediction + ).squaredBoxedDistanceTo(player) > distance) + ) { continue } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/entity/EntityExtensions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/entity/EntityExtensions.kt index 08bf8c21fa9..868eeb99858 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/entity/EntityExtensions.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/entity/EntityExtensions.kt @@ -170,6 +170,17 @@ fun Entity.squaredBoxedDistanceTo(entity: Entity): Double { return xDist * xDist + yDist * yDist + zDist * zDist } +fun Box.squaredBoxedDistanceTo(entity: Entity): Double { + val eyes = entity.eyes + val pos = getNearestPoint(eyes, this) + + val xDist = pos.x - eyes.x + val yDist = pos.y - eyes.y + val zDist = pos.z - eyes.z + + return xDist * xDist + yDist * yDist + zDist * zDist +} + fun Entity.interpolateCurrentPosition(tickDelta: Float): Vec3 { return Vec3( this.lastRenderX + (this.x - this.lastRenderX) * tickDelta,