Place biome-driven water and lava springs
This commit is contained in:
parent
dd2ea56850
commit
2bfa3155f3
7 changed files with 184 additions and 6 deletions
|
|
@ -53,6 +53,19 @@ type OreTarget struct {
|
|||
} `json:"target"`
|
||||
}
|
||||
|
||||
type SpringFeatureConfig struct {
|
||||
HoleCount int `json:"hole_count"`
|
||||
RequiresBlockBelow bool `json:"requires_block_below"`
|
||||
RockCount int `json:"rock_count"`
|
||||
State BlockState `json:"state"`
|
||||
ValidBlocks []string `json:"valid_blocks"`
|
||||
}
|
||||
|
||||
type BlockState struct {
|
||||
Name string `json:"Name"`
|
||||
Properties map[string]string `json:"Properties"`
|
||||
}
|
||||
|
||||
type PlacementPlan struct {
|
||||
Count CountProvider
|
||||
RarityChance int
|
||||
|
|
@ -102,6 +115,15 @@ func (p PlacementPlan) SampleY(r RandomSource, minY, height int) int {
|
|||
triangle := span - plateau
|
||||
return lo + int(r.NextIntN(int32((triangle+1)/2))) + int(r.NextIntN(int32(triangle/2+1)))
|
||||
}
|
||||
if p.HeightDistribution == "minecraft:very_biased_to_bottom" {
|
||||
const inner = 8
|
||||
outer := span - inner + 1
|
||||
if outer <= 0 {
|
||||
return lo
|
||||
}
|
||||
bound := int(r.NextIntN(int32(outer))) + inner
|
||||
return lo + int(r.NextIntN(int32(bound)))
|
||||
}
|
||||
return lo + int(r.NextIntN(int32(span)))
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +166,21 @@ func (s *FeatureSet) Ore(name string) (OreFeatureConfig, error) {
|
|||
return config, nil
|
||||
}
|
||||
|
||||
func (s *FeatureSet) Spring(name string) (SpringFeatureConfig, error) {
|
||||
configured, ok := s.Configured[name]
|
||||
if !ok || configured.Type != "minecraft:spring_feature" {
|
||||
return SpringFeatureConfig{}, fmt.Errorf("worldgen: %s is not a spring feature", name)
|
||||
}
|
||||
var config SpringFeatureConfig
|
||||
if err := json.Unmarshal(configured.Config, &config); err != nil {
|
||||
return SpringFeatureConfig{}, fmt.Errorf("worldgen: decode %s: %w", name, err)
|
||||
}
|
||||
if config.State.Name == "" || len(config.ValidBlocks) == 0 || config.HoleCount < 0 || config.RockCount < 0 {
|
||||
return SpringFeatureConfig{}, fmt.Errorf("worldgen: invalid spring config %s", name)
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (s *FeatureSet) Placement(name string) (PlacementPlan, error) {
|
||||
placed, ok := s.Placed[name]
|
||||
if !ok {
|
||||
|
|
@ -191,7 +228,8 @@ func (s *FeatureSet) Placement(name string) (PlacementPlan, error) {
|
|||
if err != nil {
|
||||
return PlacementPlan{}, err
|
||||
}
|
||||
if value.Height.Type != "minecraft:uniform" && value.Height.Type != "minecraft:trapezoid" {
|
||||
if value.Height.Type != "minecraft:uniform" && value.Height.Type != "minecraft:trapezoid" &&
|
||||
value.Height.Type != "minecraft:very_biased_to_bottom" {
|
||||
return PlacementPlan{}, fmt.Errorf("worldgen: %s unsupported height distribution %q", name, value.Height.Type)
|
||||
}
|
||||
plan.HeightDistribution, plan.MinY, plan.MaxY = value.Height.Type, min, max
|
||||
|
|
|
|||
|
|
@ -33,4 +33,12 @@ func TestFeatureDatapackLoadsAndLinks(t *testing.T) {
|
|||
if err != nil || plan.Count.Min != 7 || plan.Count.Max != 7 || plan.MinY.AboveBottom == nil {
|
||||
t.Fatalf("diamond placement = %+v, err=%v", plan, err)
|
||||
}
|
||||
spring, err := set.Spring("minecraft:spring_water")
|
||||
if err != nil || spring.State.Name != "minecraft:water" || spring.RockCount != 4 || spring.HoleCount != 1 {
|
||||
t.Fatalf("spring water = %+v, err=%v", spring, err)
|
||||
}
|
||||
lavaPlan, err := set.Placement("minecraft:spring_lava")
|
||||
if err != nil || lavaPlan.HeightDistribution != "minecraft:very_biased_to_bottom" {
|
||||
t.Fatalf("spring lava placement = %+v, err=%v", lavaPlan, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue