From 2708cc89a236ca4a2f4948d7645f51bd005ddd28 Mon Sep 17 00:00:00 2001 From: JustTal Date: Tue, 16 Aug 2022 23:29:55 -0500 Subject: [PATCH] server/block: Add ProjectileHitter interface --- server/block/block.go | 6 ++++++ server/entity/projectile.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/server/block/block.go b/server/block/block.go index 164b02eb2..8a541eed4 100644 --- a/server/block/block.go +++ b/server/block/block.go @@ -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 { diff --git a/server/entity/projectile.go b/server/entity/projectile.go index 4b07ecd55..079fa99ae 100644 --- a/server/entity/projectile.go +++ b/server/entity/projectile.go @@ -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