Skip to content
Merged
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
6 changes: 4 additions & 2 deletions block/bounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ func (slime) Matches(b world.Block, name string) bool {
return name == "minecraft:slime"
}

func (slime) Apply(s *resolution) {
func (slime) Apply(s resolution) resolution {
if !s.groundFrictionSet {
s.GroundFriction = 0.8
s.groundFrictionSet = true
}
s.Bounce = BounceSlime
return s
}

type bed struct{}
Expand All @@ -31,6 +32,7 @@ func (bed) Matches(b world.Block, name string) bool {
return name == "minecraft:bed"
}

func (bed) Apply(s *resolution) {
func (bed) Apply(s resolution) resolution {
s.Bounce = BounceBed
return s
}
3 changes: 2 additions & 1 deletion block/climbable.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (climbableBlock) Matches(b world.Block, name string) bool {
}
}

func (climbableBlock) Apply(s *resolution) {
func (climbableBlock) Apply(s resolution) resolution {
s.Climbable = true
return s
}
3 changes: 2 additions & 1 deletion block/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func (cobweb) Matches(_ world.Block, name string) bool {
return name == "minecraft:web"
}

func (cobweb) Apply(s *resolution) {
func (cobweb) Apply(s resolution) resolution {
s.Cobweb = true
return s
}
3 changes: 2 additions & 1 deletion block/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ func (r environmentRule) Matches(_ world.Block, name string) bool {
return name == r.name
}

func (r environmentRule) Apply(s *resolution) {
func (r environmentRule) Apply(s resolution) resolution {
s.InsideMovement = r.inside
s.Traversal = r.traversal
s.Honey = r.honey
return s
}
3 changes: 2 additions & 1 deletion block/friction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ func (b frictionBlock) Matches(_ world.Block, name string) bool {
return name == b.name
}

func (b frictionBlock) Apply(s *resolution) {
func (b frictionBlock) Apply(s resolution) resolution {
if !s.groundFrictionSet {
s.GroundFriction = b.friction
s.groundFrictionSet = true
}
return s
}
3 changes: 2 additions & 1 deletion block/ground.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func (soulSand) Matches(b world.Block, name string) bool {
return name == "minecraft:soul_sand"
}

func (soulSand) Apply(s *resolution) {
func (soulSand) Apply(s resolution) resolution {
s.GroundAccelerationFrictionMultiplier *= SoulSandAccelerationFrictionMultiplier
s.SoulSpeedNeutralizesAccelerationFriction = true
return s
}
4 changes: 2 additions & 2 deletions block/semantics.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type MovementSemantics struct {
// rule contributes movement behavior for a block family.
type rule interface {
Matches(world.Block, string) bool
Apply(*resolution)
Apply(resolution) resolution
}

type resolution struct {
Expand Down Expand Up @@ -92,7 +92,7 @@ func Resolve(b world.Block, name string) MovementSemantics {
}
for _, rule := range rules {
if rule.Matches(b, name) {
rule.Apply(&result)
result = rule.Apply(result)
}
}
if !result.groundFrictionSet {
Expand Down
3 changes: 2 additions & 1 deletion block/semantics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ func (r *countingRule) Matches(world.Block, string) bool {
return true
}

func (*countingRule) Apply(s *resolution) {
func (*countingRule) Apply(s resolution) resolution {
s.GroundFriction = 0.7
s.groundFrictionSet = true
return s
}

func TestResolveVisitsEachRuleOnce(t *testing.T) {
Expand Down