Skip to content

Commit 119ca57

Browse files
committed
checkpoint
1 parent f001611 commit 119ca57

16 files changed

Lines changed: 1140 additions & 874 deletions

examples/overworld-noise-settings/surface-rules/badlands.mms

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ SkyTerracotta := SurfaceRule {
1212
If (AboveSurface) Block stone
1313
}
1414

15-
NonHoleOrangeTerracotta := SurfaceRule { If (!Hole) Block orange_terracotta }
15+
NonHoleOrangeTerracotta := SurfaceRule { If (Not(Hole)) Block orange_terracotta }
1616

1717
TerracottaBands := SurfaceRule {
18-
If (StoneDepth Floor 0 sub 0)
18+
If (StoneDepth Floor 0 Sub 0)
1919
Sequence [
20-
If (YAbove Absolute(74) 1 add)
20+
If (YAbove 74 1 Add)
2121
Sequence [
22-
If (or (
23-
Noise minecraft:surface [-0.909, -0.5454]
24-
Noise minecraft:surface [-0.1818, 0.1818]
25-
Noise minecraft:surface [0.5454, 0.909]
22+
If (Or (
23+
Noise minecraft:surface [-0.909 -0.5454]
24+
Noise minecraft:surface [-0.1818 0.1818]
25+
Noise minecraft:surface [0.5454 0.909]
2626
))
2727
Block minecraft:terracotta
2828

@@ -31,43 +31,43 @@ TerracottaBands := SurfaceRule {
3131
]
3232
}
3333

34-
WhiteTerracotta := SurfaceRule { If (AboveWater -6 -1 add) Block white_terracotta }
35-
OrangeTerracotta := SurfaceRule { If (YAbove Absolute(63) 0 sub ) Block orange_terracotta }
34+
WhiteTerracotta := SurfaceRule { If (AboveWater -6 -1 Add) Block white_terracotta }
35+
OrangeTerracotta := SurfaceRule { If (YAbove 63 0 Sub ) Block orange_terracotta }
3636
StoneAndGravel := SurfaceRule {
3737
Sequence [
38-
If (StoneDepth Ceiling 0 sub 0) Block stone
38+
If (StoneDepth Ceiling 0 Sub 0) Block stone
3939
Block Gravel
4040
]
4141
}
4242

4343
SurfaceSands := SurfaceRule {
44-
If (AboveWater -1 0 sub) Sequence [
45-
If (StoneDepth Ceiling 0 sub 0) Block minecraft:red_sandstone
44+
If (AboveWater -1 0 Sub) Sequence [
45+
If (StoneDepth Ceiling 0 Sub 0) Block minecraft:red_sandstone
4646
Block minecraft:red_sand
4747
]
4848
}
4949

5050
OrangeTerracottaEdge := SurfaceRule {
51-
If ( and (
52-
YAbove Absolute(63) 0 sub
53-
!YAbove Absolute(74) 1 add
51+
If ( And (
52+
YAbove 63 0 Sub
53+
Not(YAbove 74 1 Add)
5454
) ) Block minecraft:orange_terracotta
5555
}
5656

5757
Badlands := SurfaceRule {
5858
If (InBadlands) Sequence [
59-
If (YAbove Absolute(63) 0 sub) Sequence [
59+
If (YAbove 63 0 Sub) Sequence [
6060
SkyTerracotta
6161
TerracottaBands
6262
SurfaceSands
6363
NonHoleOrangeTerracotta
6464
WhiteTerracotta
6565
StoneAndGravel
6666
]
67-
If (YAbove Absolute(63) -1 add) Sequence [
67+
If (YAbove 63 -1 Add) Sequence [
6868
OrangeTerracottaEdge
6969
Bandlands
7070
]
71-
If (StoneDepth Floor 0 add 0) WhiteTerracotta
71+
If (StoneDepth Floor 0 Add 0) WhiteTerracotta
7272
]
7373
}

grammar/Lang_Lexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Colon: ':';
1616
SemiColon: ';';
1717
Amp: '&';
1818
DoubleAmp: '&&';
19+
Tilde: '~';
20+
Dash: '-';
1921

2022
Int: '-'? [0-9]+;
2123
Float: ('-'? [0-9]+ '.' [0-9]+);

grammar/Main_Lexer.g4

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ Keyword_AboveWater: 'AboveWater';
2929
Keyword_YAbove: 'YAbove';
3030
Keyword_Floor: 'Floor';
3131
Keyword_Ceiling: 'Ceiling';
32+
33+
Keyword_Not: 'Not';
3234
Keyword_And: 'And';
3335
Keyword_Or: 'Or';
36+
3437
Keyword_Add: 'Add';
3538
Keyword_Sub: 'Sub';
3639
///

grammar/SurfaceRules_Parser.g4

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ surfaceRule_Reference: resourceReference;
1919
surfaceConditionDefinition: Keyword_SurfaceCondition NL* CurlyOpen NL* surfaceCondition NL* CurlyClose;
2020

2121
surfaceCondition:
22-
Bang?
23-
(surfaceCondition_AboveSurface
22+
surfaceCondition_AboveSurface
2423
| surfaceCondition_Biome
2524
| surfaceCondition_Hole
2625
| surfaceCondition_Noise
@@ -32,12 +31,14 @@ surfaceCondition:
3231
| surfaceCondition_YAbove
3332
| surfaceCondition_Reference
3433
| surfaceCondition_And
35-
| surfaceCondition_Or);
34+
| surfaceCondition_Or
35+
| surfaceCondition_Not;
3636

3737
surfaceCondition_Reference: resourceReference;
3838

3939
surfaceCondition_And: Keyword_And NL* RoundOpen NL* (surfaceCondition NL*)* surfaceCondition NL* RoundClose;
4040
surfaceCondition_Or: Keyword_Or NL* RoundOpen NL* (surfaceCondition NL*)* surfaceCondition NL* RoundClose;
41+
surfaceCondition_Not: Keyword_Not NL* RoundOpen NL* surfaceCondition NL* RoundClose;
4142

4243

4344
surfaceCondition_AboveSurface: Keyword_AboveSurface;

grammar/VerticalAnchor_Parser.g4

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Lang_Parser;
77

88
verticalAnchorDefinition: Keyword_Anchor CurlyOpen verticalAnchor CurlyClose;
99
verticalAnchor: verticalAnchor_Absolute | verticalAnchor_AboveBottom | verticalAnchor_BelowTop | verticalAnchor_Reference;
10-
verticalAnchor_Absolute: Keyword_Absolute RoundOpen Int RoundClose;
11-
verticalAnchor_AboveBottom: Keyword_AboveBottom RoundOpen Int RoundClose;
12-
verticalAnchor_BelowTop: Keyword_BelowTop RoundOpen Int RoundClose;
10+
verticalAnchor_Absolute: Int;
11+
verticalAnchor_AboveBottom: Tilde Int;
12+
verticalAnchor_BelowTop: Tilde Dash Int;
1313
verticalAnchor_Reference: resourceReference;

lang/constructs/worldgen/surface_rules/Condition_Not.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,41 @@ package surface_rules
22

33
import (
44
"encoding/json"
5+
"reflect"
56

7+
"github.com/antlr4-go/antlr/v4"
8+
"github.com/minecraftmetascript/mms/lang/grammar"
69
"github.com/minecraftmetascript/mms/lang/traversal"
710
"github.com/minecraftmetascript/mms/lib"
811
)
912

13+
func init() {
14+
traversal.ConstructRegistry.Register(
15+
reflect.TypeFor[grammar.SurfaceCondition_NotContext](),
16+
func(ctx antlr.ParserRuleContext, currentNamespace string, scope *traversal.Scope) traversal.Construct {
17+
not := ctx.(*grammar.SurfaceCondition_NotContext)
18+
if not.SurfaceCondition() == nil {
19+
loc := traversal.RuleLocation(ctx, scope.CurrentFile)
20+
*scope.Diagnostics = append(*scope.Diagnostics, traversal.Diagnostic{
21+
Message: "Expected a surface condition",
22+
Where: loc,
23+
Severity: traversal.SeverityError,
24+
Source: "semantic",
25+
File: scope.CurrentFile,
26+
})
27+
return nil
28+
}
29+
return InvertCondition(
30+
traversal.ConstructRegistry.Construct(
31+
not.SurfaceCondition(),
32+
currentNamespace,
33+
scope,
34+
),
35+
)
36+
},
37+
)
38+
}
39+
1040
type NotCondition struct {
1141
traversal.Construct
1242
Invert traversal.Construct

lang/constructs/worldgen/surface_rules/Rule_If.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@ func init() {
1616
reflect.TypeFor[grammar.SurfaceRule_ConditionContext](),
1717
func(ctx_ antlr.ParserRuleContext, ns string, scope *traversal.Scope) traversal.Construct {
1818
ctx := ctx_.(*grammar.SurfaceRule_ConditionContext)
19-
out := &IfRule{
19+
out := &IfRule{
2020
Negate: false,
2121
scope: scope,
2222
}
2323

2424
var condition traversal.Construct
2525

2626
if cond := ctx.SurfaceCondition(); cond != nil {
27-
out.Negate = cond.Bang() != nil
2827
condition = traversal.ConstructRegistry.Construct(cond, ns, scope)
2928
} else {
3029
if scope != nil && scope.Diagnostics != nil {
3130
loc := traversal.RuleLocation(ctx, scope.CurrentFile)
3231
*scope.Diagnostics = append(*scope.Diagnostics, traversal.Diagnostic{
33-
Message: "missing surface condition in if rule",
32+
Message: "Expected a surface condition",
3433
Where: loc,
3534
Severity: traversal.SeverityError,
3635
Source: "semantic",

0 commit comments

Comments
 (0)