Skip to content

Commit

Permalink
server/block: Call break handlers on breakBlock and explosions
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Jan 7, 2025
1 parent e113782 commit 7276cdc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
6 changes: 6 additions & 0 deletions server/block/break_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ func breakBlock(b world.Block, pos cube.Pos, tx *world.Tx) {
}

func breakBlockNoDrops(b world.Block, pos cube.Pos, tx *world.Tx) {
if breakable, ok := b.(Breakable); ok {
breakHandler := breakable.BreakInfo().BreakHandler
if breakHandler != nil {
breakHandler(pos, tx, nil)
}
}
tx.SetBlock(pos, nil, nil)
tx.AddParticle(pos.Vec3Centre(), particle.BlockBreak{Block: b})
}
19 changes: 4 additions & 15 deletions server/block/explosion.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,16 @@ func (c ExplosionConfig) Explode(tx *world.Tx, explosionPos mgl64.Vec3) {
if explodable, ok := bl.(Explodable); ok {
explodable.Explode(explosionPos, pos, tx, c)
} else if breakable, ok := bl.(Breakable); ok {
breakHandler := breakable.BreakInfo().BreakHandler
if breakHandler != nil {
breakHandler(pos, tx, nil)
}
tx.SetBlock(pos, nil, nil)
if c.ItemDropChance > r.Float64() {
for _, drop := range breakable.BreakInfo().Drops(item.ToolNone{}, nil) {
dropItem(tx, drop, pos.Vec3Centre())
}
}

if container, ok := bl.(Container); ok {
if cb, ok := bl.(Chest); ok {
if cb.Paired() {
pairPos := cb.pairPos(pos)
if _, pair, ok := cb.unpair(tx, pos); ok {
cb.paired = false
tx.SetBlock(pairPos, pair, nil)
}
}
}
for _, i := range container.Inventory(tx, pos).Clear() {
dropItem(tx, i, pos.Vec3())
}
}
}
}
if c.SpawnFire {
Expand Down

0 comments on commit 7276cdc

Please sign in to comment.