Skip to content

Commit

Permalink
Made ProjectilePuncher mathematically ignore the user's own moving fi…
Browse files Browse the repository at this point in the history
…reball. (CCBlueX#1302)
  • Loading branch information
mems01 authored Sep 9, 2023
1 parent e466938 commit c4ec472
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

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

0 comments on commit c4ec472

Please sign in to comment.