Skip to content

Commit 2458a64

Browse files
committed
fixup! server/block: Add ProjectileHitter interface
1 parent b8aff17 commit 2458a64

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

server/entity/projectile.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,22 @@ func (lt *ProjectileBehaviour) tickMovement(e *Ent, tx *world.Tx) (*Movement, tr
297297
if !mgl64.FloatEqual(end.Sub(pos).LenSqr(), 0) {
298298
if hit, ok = trace.Perform(pos, end, tx, e.H().Type().BBox(e).Grow(1.0), lt.ignores(e)); ok {
299299
if r, ok := hit.(trace.BlockResult); ok {
300-
// Undo the gravity because the velocity as a result of gravity
301-
// at the point of collision should be 0.
302-
vel[1] = (vel[1] + lt.mc.Gravity) / (1 - lt.mc.Drag)
303-
x, y, z := vel.Mul(lt.conf.BlockCollisionVelocityMultiplier).Elem()
304-
// Calculate multipliers for all coordinates: 1 for the ones that
305-
// weren't on the same axis as the one collided with, -1 for the one
306-
// that was on that axis to deflect the projectile.
307-
mx, my, mz := hit.Face().Axis().Vec3().Mul(-2).Add(mgl64.Vec3{1, 1, 1}).Elem()
308-
309-
vel = mgl64.Vec3{x * mx, y * my, z * mz}
300+
resultPos := r.BlockPosition()
301+
if h, ok := tx.Block(resultPos).(block.ProjectileHitter); ok {
302+
h.ProjectileHit(resultPos, tx, e, r.Face())
303+
}
304+
// Check that the block hit was not set to air by a block.ProjectileHitter.
305+
if _, ok := tx.Block(resultPos).(block.Air); !ok {
306+
// Undo the gravity because the velocity as a result of gravity
307+
// at the point of collision should be 0.
308+
vel[1] = (vel[1] + lt.mc.Gravity) / (1 - lt.mc.Drag)
309+
x, y, z := vel.Mul(lt.conf.BlockCollisionVelocityMultiplier).Elem()
310+
// Calculate multipliers for all coordinates: 1 for the ones that
311+
// weren't on the same axis as the one collided with, -1 for the one
312+
// that was on that axis to deflect the projectile.
313+
mx, my, mz := hit.Face().Axis().Vec3().Mul(-2).Add(mgl64.Vec3{1, 1, 1}).Elem()
310314

311-
if h, ok := tx.Block(r.BlockPosition()).(block.ProjectileHitter); ok {
312-
h.ProjectileHit(r.BlockPosition(), tx, e, r.Face())
315+
vel = mgl64.Vec3{x * mx, y * my, z * mz}
313316
}
314317
} else {
315318
vel = zeroVec3

0 commit comments

Comments
 (0)