Skip to content

Commit

Permalink
play sounds when waxing sign and when interacting with it
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkam246 committed Dec 23, 2023
1 parent 21eb18f commit a40db91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/block/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/particle"
"github.com/df-mc/dragonfly/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
"image/color"
"strings"
Expand Down Expand Up @@ -119,10 +120,13 @@ func (s Sign) Wax(cube.Pos, mgl64.Vec3) (world.Block, bool) {
}

// Activate ...
func (s Sign) Activate(pos cube.Pos, _ cube.Face, _ *world.World, user item.User, _ *item.UseContext) bool {
func (s Sign) Activate(pos cube.Pos, _ cube.Face, w *world.World, user item.User, _ *item.UseContext) bool {
if editor, ok := user.(SignEditor); ok && !s.Waxed {
editor.OpenSign(pos, s.EditingFrontSide(pos, user.Position()))
}
if s.Waxed {
w.PlaySound(pos.Vec3(), sound.WaxedInteractFail{})
}
return true
}

Expand Down
2 changes: 2 additions & 0 deletions server/item/honeycomb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package item
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
)

Expand All @@ -15,6 +16,7 @@ func (Honeycomb) UseOnBlock(pos cube.Pos, _ cube.Face, _ mgl64.Vec3, w *world.Wo
if wa, ok := w.Block(pos).(waxable); ok {
if res, ok := wa.Wax(pos, user.Position()); ok {
w.SetBlock(pos, res, nil)
w.PlaySound(pos.Vec3(), sound.WaxOn{})
ctx.SubtractFromCount(1)
return true
}
Expand Down
7 changes: 7 additions & 0 deletions server/session/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ func (s *Session) playSound(pos mgl64.Vec3, t world.Sound, disableRelative bool)
Position: vec64To32(pos),
})
return
case sound.WaxOn:
s.writePacket(&packet.LevelEvent{
EventType: packet.LevelEventWaxOn,
Position: vec64To32(pos),
})
case sound.WaxedInteractFail:
pk.SoundType = packet.SoundEventWaxedSignInteractFail
case sound.Pop:
s.writePacket(&packet.LevelEvent{
EventType: packet.LevelEventSoundInfinityArrowPickup,
Expand Down
6 changes: 6 additions & 0 deletions server/world/sound/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ type ComposterReady struct{ sound }
// LecternBookPlace is a sound played when a book is placed in a lectern.
type LecternBookPlace struct{ sound }

// WaxOn is a sound played when a sign is waxed.
type WaxOn struct{ sound }

// WaxedInteractFail is a sound played when a player tries to interact with a waxed sign.
type WaxedInteractFail struct{ sound }

// sound implements the world.Sound interface.
type sound struct{}

Expand Down

0 comments on commit a40db91

Please sign in to comment.