Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions server/block/lever.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@ type Lever struct {
Direction cube.Direction
}

// RedstoneSource ...
func (l Lever) RedstoneSource() bool {
return true
}

// WeakPower ...
func (l Lever) WeakPower(cube.Pos, cube.Face, *world.Tx, bool) int {
// RedstonePower returns maximum power while the lever is active.
func (l Lever) RedstonePower(cube.Pos, *world.Tx, cube.Face) int {
if l.Powered {
return 15
}
return 0
}

// StrongPower ...
func (l Lever) StrongPower(_ cube.Pos, face cube.Face, _ *world.Tx, _ bool) int {
if l.Powered && l.Facing == face {
// RedstoneStrongPower strongly powers the block the lever is attached to.
func (l Lever) RedstoneStrongPower(_ cube.Pos, _ *world.Tx, face cube.Face) int {
if l.Powered && l.Facing.Opposite() == face {
return 15
}
return 0
Expand Down Expand Up @@ -87,14 +82,13 @@ func (l Lever) Activate(pos cube.Pos, _ cube.Face, tx *world.Tx, _ item.User, _
} else {
tx.PlaySound(pos.Vec3Centre(), sound.PowerOff{})
}
updateDirectionalRedstone(pos, tx, l.Facing.Opposite())
return true
}

// BreakInfo ...
func (l Lever) BreakInfo() BreakInfo {
return newBreakInfo(0.5, alwaysHarvestable, nothingEffective, oneOf(Lever{})).withBreakHandler(func(pos cube.Pos, tx *world.Tx, _ item.User) {
updateDirectionalRedstone(pos, tx, l.Facing.Opposite())
tx.ScheduleRedstoneUpdate(pos)
})
}

Expand Down
23 changes: 5 additions & 18 deletions server/block/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@ func (n Note) Activate(pos cube.Pos, _ cube.Face, tx *world.Tx, _ item.User, _ *
return true
}

// RedstoneUpdate updates the note block's powered state and plays the note when it first becomes powered.
func (n Note) RedstoneUpdate(pos cube.Pos, tx *world.Tx) {
poweredFaces := n.poweredFaces(pos, tx)
powered := len(poweredFaces) > 0
// RedstonePowerUpdate updates the note block's powered state and plays the note when it first becomes powered.
func (n Note) RedstonePowerUpdate(pos cube.Pos, tx *world.Tx, power int) (world.Block, bool) {
powered := power > 0
if powered == n.Powered {
return
return n, false
}
n.Powered = powered
if powered && n.canPlay(pos, tx) {
n.playNote(pos, tx)
}
tx.SetBlock(pos, n, &world.SetOpts{DisableBlockUpdates: true})
updateAroundRedstone(pos, tx, poweredFaces...)
return n, true
}

// canPlay reports whether the block above the note block is air.
Expand All @@ -82,17 +80,6 @@ func (n Note) canPlay(pos cube.Pos, tx *world.Tx) bool {
return ok
}

func (n Note) poweredFaces(pos cube.Pos, tx *world.Tx) []cube.Face {
var faces []cube.Face
for _, face := range cube.Faces() {
adjacentPos := pos.Side(face)
if power := tx.RedstonePower(adjacentPos, face, true); power > 0 {
faces = append(faces, face)
}
}
return faces
}

// BreakInfo ...
func (n Note) BreakInfo() BreakInfo {
return newBreakInfo(0.8, alwaysHarvestable, axeEffective, oneOf(Note{}))
Expand Down
Loading