Skip to content

Commit f391c94

Browse files
committed
cleanup
1 parent 88b5151 commit f391c94

File tree

12 files changed

+1693
-630
lines changed

12 files changed

+1693
-630
lines changed

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammar/NoiseSettings.g4

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Core_Lang, BlockState, NoiseRouter, Surface;
55
noiseSettingsBlock: 'NoiseSettings' NL* '{' NL* (noiseSettingsDeclaration NL*)* NL* '}';
66

77
noiseSettingsDeclaration: declare noiseSettings;
8-
noiseSettings: 'NoiseSettings' NL* '(' NL* ')' NL* (noiseSettings_Builder NL*)*;
8+
noiseSettings: 'NoiseSettings' NL* '(' NL* NL* ')' NL* (noiseSettings_Builder NL*)*;
99

1010

1111
noiseSettings_Builder:
@@ -23,17 +23,17 @@ noiseSettings_Builder:
2323
| builder_NoiseRouter
2424
| builder_SurfaceRule
2525
;
26-
builder_NoiseSize: '.NoiseSize' '(' Int ',' Int ')';
27-
builder_NoiseRouter: '.NoiseRouter' '(' noiseRouter ')';
28-
builder_SeaLevel: '.SeaLevel' '(' Int ')';
29-
builder_DisableCreatures: '.DisableCreatures' '(' ')';
30-
builder_DisableVeins: '.DisableVeins' '(' ')';
31-
builder_DisableAquifers: '.DisableAquifers' '(' ')';
32-
builder_LegacyRandomSource: '.LegacyRandomSource' '(' ')';
33-
builder_DefaultBlock: '.DefaultBlock' '(' (blockState | resourceReference) ')';
34-
builder_DefaultFluid: '.DefaultFluid' '(' (blockState | resourceReference) ')';
35-
builder_SpawnTarget: '.SpawnTarget' '(' /* TODO: Implement */ ')';
36-
builder_MinY: '.MinY' '(' Int ')';
37-
builder_Height: '.Height' '(' Int ')';
26+
builder_NoiseSize: '.NoiseSize' '(' NL* Int NL* ',' NL* Int NL* ')';
27+
builder_NoiseRouter: '.NoiseRouter' '(' NL* noiseRouter NL* ')';
28+
builder_SeaLevel: '.SeaLevel' '(' NL* Int NL* ')';
29+
builder_DisableCreatures: '.DisableCreatures' '(' NL* NL* ')';
30+
builder_DisableVeins: '.DisableVeins' '(' NL* NL* ')';
31+
builder_DisableAquifers: '.DisableAquifers' '(' NL* NL* ')';
32+
builder_LegacyRandomSource: '.LegacyRandomSource' '(' NL* NL* ')';
33+
builder_DefaultBlock: '.DefaultBlock' '(' NL* (blockState | resourceReference) NL* ')';
34+
builder_DefaultFluid: '.DefaultFluid' '(' NL* (blockState | resourceReference) NL* ')';
35+
builder_SpawnTarget: '.SpawnTarget' '(' NL* /* TODO: Implement */ NL* ')';
36+
builder_MinY: '.MinY' '(' NL* Int NL* ')';
37+
builder_Height: '.Height' '(' NL* Int NL* ')';
3838

39-
builder_SurfaceRule: '.SurfaceRule' '(' surfaceRule ')';
39+
builder_SurfaceRule: '.SurfaceRule' '(' NL* surfaceRule NL* ')';

lang/constructs/worldgen/density_functions/DensityFn.go

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package density_functions
22

33
import (
44
"encoding/json"
5-
"fmt"
65

76
"github.com/antlr4-go/antlr/v4"
87
"github.com/minecraftmetascript/mms/lang/grammar"
@@ -38,33 +37,14 @@ func (m MathDensityFn) ExportSymbol(symbol traversal.Symbol, rootDir *lib.FileTr
3837
return exportDensityFunction(symbol, rootDir, m)
3938
}
4039

41-
func ExtractInlinedNoise(noiseCtx *grammar.NoiseDefinitionContext, currentNamespace string, scope *traversal.Scope) *traversal.Reference {
42-
noiseDef := traversal.ConstructRegistry.Construct(noiseCtx, currentNamespace, scope)
43-
noiseRef := traversal.NewReference(
44-
fmt.Sprintf("densityfn_noise_%d_%d", noiseCtx.GetStart().GetLine(), noiseCtx.GetStart().GetColumn()),
45-
"mms_inline",
46-
)
47-
noiseSymbol := traversal.NewSymbol(
48-
traversal.RuleLocation(noiseCtx, scope.CurrentFile),
49-
traversal.RuleLocation(noiseCtx, scope.CurrentFile),
50-
noiseDef,
51-
noiseRef,
52-
"Noise",
53-
)
54-
if _, ok := scope.Get(*noiseRef); !ok {
55-
if err := scope.Register(noiseSymbol); err != nil {
56-
// TODO: Improve behavior
57-
panic(err)
58-
}
59-
}
60-
return noiseRef
61-
}
62-
6340
func init() {
6441
traversal.Register(
65-
func(inlineCtx *grammar.DensityFn_InlineNoiseContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
66-
if noiseInlineCtx := inlineCtx.Noise(); noiseInlineCtx != nil {
67-
return ExtractInlinedNoise(noiseInlineCtx.NoiseDefinition().(*grammar.NoiseDefinitionContext), currentNamespace, scope)
42+
func(ctx *grammar.DensityFn_InlineNoiseContext, namespace string, scope *traversal.Scope) traversal.Construct {
43+
if noiseCtx := ctx.Noise(); noiseCtx != nil {
44+
if _, ref := traversal.ExtractInlineConstruct(noiseCtx.NoiseDefinition(), namespace, scope, "Noise"); ref != nil {
45+
return ref
46+
}
47+
6848
}
6949
return nil
7050
},
@@ -140,6 +120,7 @@ func exportDensityFunction(symbol traversal.Symbol, rootDir *lib.FileTreeLike, c
140120
return err
141121
}
142122
rootDir.
123+
MkDir("data", nil).
143124
MkDir(symbol.GetReference().GetNamespace(), nil).
144125
MkDir("worldgen", nil).
145126
MkDir("density_function", nil).

lang/constructs/worldgen/density_functions/WeirdScaledSamplerFn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func init() {
5050
continue
5151
}
5252
} else if inline := noise.NoiseDefinition(); inline != nil {
53-
ref := ExtractInlinedNoise(inline.(*grammar.NoiseDefinitionContext), currentNamespace, scope)
53+
_, ref := traversal.ExtractInlineConstruct(inline, currentNamespace, scope, "Noise")
54+
5455
if ref != nil {
5556
out.Noise = *ref
5657
} else {
57-
// TODO: Diagnose
5858
scope.DiagnoseSemanticError("Invalid inline noise definition.", noise)
5959
continue
6060
}

lang/constructs/worldgen/noise_settings/NoiseSettings.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ func getBuilder() *builder_chain.BuilderChain[NoiseSettings] {
7474
builder_chain.Builder_GetInt(ctx, func(v int) { target.Height = v }, scope, "MinY")
7575
},
7676
),
77+
builder_chain.Build(
78+
func(ctx *grammar.Builder_NoiseRouterContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
79+
if sym, _ := traversal.ExtractInlineConstruct(ctx.NoiseRouter(), namespace, scope, "NoiseRouter"); sym != nil {
80+
target.NoiseRouter = sym.GetValue()
81+
}
82+
},
83+
),
84+
builder_chain.Build(
85+
func(ctx *grammar.Builder_SurfaceRuleContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
86+
if sym, _ :=
87+
traversal.ExtractInlineConstruct(ctx.SurfaceRule(), namespace, scope, "SurfaceRule"); sym != nil {
88+
target.NoiseRouter = sym.GetValue()
89+
}
90+
},
91+
),
7792
builder_chain.Build(
7893
func(ctx *grammar.Builder_NoiseSizeContext, target *NoiseSettings, scope *traversal.Scope, namespace string) {
7994
horizontalCtx := ctx.Int(0)
@@ -169,8 +184,8 @@ func init() {
169184
chain,
170185
settings,
171186
scope,
172-
reflect.TypeFor[*grammar.Builder_NoiseRouterContext](),
173-
".NoiseRouter",
187+
reflect.TypeFor[*grammar.Builder_SurfaceRuleContext](),
188+
".SurfaceRule",
174189
)
175190
return out
176191
},

lang/grammar/MinecraftMetascript.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)