Skip to content

Commit

Permalink
player/handler.go: Introduce HandleFireExtinguish (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
aabstractt authored Aug 11, 2024
1 parent 45cf3f1 commit 9c86481
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions server/player/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ type Handler interface {
// HandleSkinChange handles the player changing their skin. ctx.Cancel() may be called to cancel the skin
// change.
HandleSkinChange(ctx *event.Context, skin *skin.Skin)
// HandleFireExtinguish handles the player extinguishing a fire at a specific position. ctx.Cancel() may
// be called to cancel the fire being extinguished.
// cube.Pos can be used to see where was the fire extinguished, may be used to cancel this on specific positions.
HandleFireExtinguish(ctx *event.Context, pos cube.Pos)
// HandleStartBreak handles the player starting to break a block at the position passed. ctx.Cancel() may
// be called to stop the player from breaking the block completely.
HandleStartBreak(ctx *event.Context, pos cube.Pos)
Expand Down Expand Up @@ -152,6 +156,7 @@ func (NopHandler) HandleCommandExecution(*event.Context, cmd.Command, []string)
func (NopHandler) HandleTransfer(*event.Context, *net.UDPAddr) {}
func (NopHandler) HandleChat(*event.Context, *string) {}
func (NopHandler) HandleSkinChange(*event.Context, *skin.Skin) {}
func (NopHandler) HandleFireExtinguish(*event.Context, cube.Pos) {}
func (NopHandler) HandleStartBreak(*event.Context, cube.Pos) {}
func (NopHandler) HandleBlockBreak(*event.Context, cube.Pos, *[]item.Stack, *int) {}
func (NopHandler) HandleBlockPlace(*event.Context, cube.Pos, world.Block) {}
Expand Down
8 changes: 7 additions & 1 deletion server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,13 @@ func (p *Player) StartBreaking(pos cube.Pos, face cube.Face) {
return
}
if _, ok := w.Block(pos.Side(face)).(block.Fire); ok {
// TODO: Add a way to cancel fire extinguishing. This is currently not possible to handle.
ctx := event.C()
if p.Handler().HandleFireExtinguish(ctx, pos); ctx.Cancelled() {
// Resend the block because on client side that was extinguished
p.resendBlocks(pos, w, face)
return
}

w.SetBlock(pos.Side(face), nil, nil)
w.PlaySound(pos.Vec3(), sound.FireExtinguish{})
return
Expand Down

0 comments on commit 9c86481

Please sign in to comment.