Skip to content

Commit

Permalink
server/block: Don't allow liquid removable blocks to replace liquids
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Jan 26, 2025
1 parent 4e265ee commit a6bfa63
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion server/block/lava.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// Lava is a light-emitting fluid block that causes fire damage.
type Lava struct {
empty
replaceable

// Still makes the lava not spread whenever it is updated. Still lava cannot be acquired in the game
// without world editing.
Expand All @@ -35,6 +34,16 @@ func neighboursLavaFlammable(pos cube.Pos, tx *world.Tx) bool {
return false
}

// ReplaceableBy ...
func (l Lava) ReplaceableBy(b world.Block) bool {
if _, ok := b.(LiquidRemovable); ok {
_, displacer := b.(world.LiquidDisplacer)
_, liquid := b.(world.Liquid)
return displacer || liquid
}
return true
}

// EntityInside ...
func (l Lava) EntityInside(_ cube.Pos, _ *world.Tx, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
Expand Down
5 changes: 5 additions & 0 deletions server/block/sea_pickle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (SeaPickle) canSurvive(pos cube.Pos, tx *world.Tx) bool {
if !below.Model().FaceSolid(pos.Side(cube.FaceDown), cube.FaceUp, tx) {
return false
}
if liquid, ok := tx.Liquid(pos); ok {
if _, ok = liquid.(Water); !ok || liquid.LiquidDepth() != 8 {
return false
}
}
if emitter, ok := below.(LightDiffuser); ok && emitter.LightDiffusionLevel() != 15 {
return false
}
Expand Down
11 changes: 10 additions & 1 deletion server/block/water.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
// Water is a natural fluid that generates abundantly in the world.
type Water struct {
empty
replaceable

// Still makes the water appear as if it is not flowing.
Still bool
Expand All @@ -26,6 +25,16 @@ type Water struct {
Falling bool
}

// ReplaceableBy ...
func (w Water) ReplaceableBy(b world.Block) bool {
if _, ok := b.(LiquidRemovable); ok {
_, displacer := b.(world.LiquidDisplacer)
_, liquid := b.(world.Liquid)
return displacer || liquid
}
return true
}

// EntityInside ...
func (w Water) EntityInside(_ cube.Pos, _ *world.Tx, e world.Entity) {
if fallEntity, ok := e.(fallDistanceEntity); ok {
Expand Down

0 comments on commit a6bfa63

Please sign in to comment.