Skip to content

Commit

Permalink
server/block: Add ProjectileHitter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JustTalDevelops authored and DaPigGuy committed Aug 17, 2022
1 parent 7276cdc commit 2708cc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ type EntityInsider interface {
EntityInside(pos cube.Pos, tx *world.Tx, e world.Entity)
}

// ProjectileHitter represents a block that handles being hit by a projectile.
type ProjectileHitter interface {
// ProjectileHit is called when a projectile hits the block.
ProjectileHit(pos cube.Pos, tx *world.Tx, e world.Entity, face cube.Face)
}

// Frictional represents a block that may have a custom friction value. Friction is used for entity drag when the
// entity is on ground. If a block does not implement this interface, it should be assumed that its friction is 0.6.
type Frictional interface {
Expand Down
3 changes: 3 additions & 0 deletions server/entity/projectile.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (lt *ProjectileBehaviour) Tick(e *Ent, tx *world.Tx) *Movement {
if t, ok := tx.Block(bpos).(block.TNT); ok && e.OnFireDuration() > 0 {
t.Ignite(bpos, tx, nil)
}
if h, ok := tx.Block(bpos).(block.ProjectileHitter); ok {
h.ProjectileHit(bpos, tx, e, r.Face())
}
if lt.conf.SurviveBlockCollision {
lt.hitBlockSurviving(e, r, m, tx)
return m
Expand Down

0 comments on commit 2708cc8

Please sign in to comment.