@@ -350,50 +350,59 @@ func YAboveSerializer(node spec.FunctionNode) any {
350350 return out
351351}
352352
353+ func serializeListSurfaceRule (node spec.ListNode ) any {
354+ out := struct {
355+ Type string `json:"type"`
356+ Sequence []any `json:"sequence"`
357+ }{
358+ Type : "minecraft:sequence" ,
359+ Sequence : make ([]any , 0 ),
360+ }
361+
362+ for _ , val := range node .Values {
363+ if s , ok := val .(ast.Symbol ); ok && ! lib .IsNilInterface (s ) {
364+ out .Sequence = append (out .Sequence , s .ToSerializable ())
365+ }
366+ }
367+
368+ return out
369+ }
370+
371+ var SurfaceConditionRef = spec .NewReferenceSpec (ast .SymbolSurfaceCondition )
372+ var SurfaceRuleRef = spec .NewReferenceSpec (ast .SymbolSurfaceRule )
373+
353374func init () {
354375 Conditional = spec .NewConditionSpec ().
355376 SetKind (ast .SymbolSurfaceRule ).
356377 SetHelp ("Applies a rule based on a surface condition" )
357378 SurfaceConditions .Add (AboveSurface , Biome , Hole , NoiseThreshold , Steep , StoneDepth , Frozen , Water , VerticalGradient , YAbove )
358379 SurfaceRules .Add (Bandlands , Block , Conditional )
359380 ListRule := spec .NewListSpec ().
360- SetOutputFn (
361- func (node spec.ListNode ) any {
362- out := struct {
363- Type string `json:"type"`
364- Sequence []any `json:"sequence"`
365- }{
366- Type : "minecraft:sequence" ,
367- Sequence : make ([]any , 0 ),
368- }
369-
370- for _ , val := range node .Values {
371- if s , ok := val .(ast.Symbol ); ok && ! lib .IsNilInterface (s ) {
372- out .Sequence = append (out .Sequence , s .ToSerializable ())
373- }
374- }
375-
376- return out
377- }).
381+ SetOutputFn (serializeListSurfaceRule ).
382+ SetFileExporter (exporter (serializeListSurfaceRule , []string {"worldgen" , "debug" , "surface" }, "json" )).
378383 SetKind (ast .SymbolSurfaceRule ).
379384 SetHelp ("Creates a list of rules, the first valid rule will be used.s" )
380385 SurfaceRules .Add (ListRule )
381386
382387 Conditional .
383388 AddConditionOption (SurfaceConditions ).
384- AddConditionOption (spec . NewReferenceSpec ( ast . SymbolSurfaceCondition ) ).
389+ AddConditionOption (SurfaceConditionRef ).
385390 AddValueOption (SurfaceRules ).
386- AddValueOption (spec . NewReferenceSpec ( ast . SymbolSurfaceRule ) ).
391+ AddValueOption (SurfaceRuleRef ).
387392 SetOutputFn (func (n spec.ConditionalNode ) any {
388393 var val any = nil
389- if n .Value != nil && n .Value .ToSerializable () != nil {
390- val = n .Value .ToSerializable ()
394+ if ! lib .IsNilInterface (n .Value ) {
395+ if ref , ok := n .Value .(* spec.ReferenceNode ); ok {
396+ val = getSymbolValue (ref .Namespace , ref .Name )
397+ } else if ! lib .IsNilInterface (n .Value .ToSerializable ()) {
398+ val = n .Value .ToSerializable ()
399+ }
391400 }
392401 return SerializeConditional (n .Condition , val )
393402 })
394403
395404 ListRule .
396- AddValueOption (spec . NewReferenceSpec ( ast . SymbolSurfaceRule ) ).
405+ AddValueOption (SurfaceRuleRef ).
397406 AddValueOption (SurfaceRules )
398407
399408 SurfaceRuleBlock = spec .NewBlockSpec (
@@ -490,6 +499,12 @@ func SerializeConditional(cond ast.Symbol, value any) any {
490499 // There is no condition yet
491500 return mkSurfaceRuleConditional (nil , value )
492501 default :
502+ if ref , ok := c .(* spec.ReferenceNode ); ok {
503+ val := getSymbolValue (ref .Namespace , ref .Name )
504+ if val != nil {
505+ return mkSurfaceRuleConditional (val , value )
506+ }
507+ }
493508 // Atomic condition: single condition node
494509 return mkSurfaceRuleConditional (c .ToSerializable (), value )
495510 }
0 commit comments