Skip to content

Commit

Permalink
Fuse a bunch of WorldEdit development modules into 1, NeoForged port
Browse files Browse the repository at this point in the history
  • Loading branch information
Drullkus committed Dec 17, 2023
1 parent f5f4fec commit 68ce366
Show file tree
Hide file tree
Showing 833 changed files with 99,676 additions and 263 deletions.
79 changes: 79 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.57'
id 'antlr'
}

version = mod_version
Expand Down Expand Up @@ -72,6 +73,12 @@ runs {
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
maven {
name 'EngineHub Repository'
url 'https://maven.enginehub.org/repo/'
}
}

dependencies {
// Specify the version of Minecraft to use.
Expand All @@ -82,6 +89,29 @@ dependencies {
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
implementation "net.neoforged:neoforge:${neo_version}"

implementation("net.kyori:text-api:${TEXT}")
implementation("net.kyori:text-serializer-gson:${TEXT}")
implementation("net.kyori:text-serializer-legacy:${TEXT}")
implementation("net.kyori:text-serializer-plain:${TEXT}")
implementation "com.sk89q.lib:jlibnoise:1.0.0"
implementation "org.enginehub.piston:core:${PISTON}"
implementation "org.enginehub.piston.core-ap:runtime:${PISTON}"
implementation "org.enginehub.piston:default-impl:${PISTON}"
implementation "org.yaml:snakeyaml:2.0"
implementation("org.enginehub.piston.core-ap:annotations:${PISTON}")
implementation("org.enginehub.piston.core-ap:processor:${PISTON}")
annotationProcessor("org.enginehub.piston.core-ap:annotations:${PISTON}")
annotationProcessor("org.enginehub.piston.core-ap:processor:${PISTON}")
implementation ("com.sk89q:jchronic:0.2.4a") {
exclude group: "junit", module: "junit"
}
compileOnly("com.google.auto.value:auto-value-annotations:${AUTO_VALUE}")
annotationProcessor("com.google.auto.value:auto-value:${AUTO_VALUE}")
antlr("org.antlr:antlr4:4.9.1")
implementation("org.antlr:antlr4-runtime:4.9.1")
compileOnly("de.schlichtherle:truezip:6.8.4")
implementation("org.mozilla:rhino-runtime:1.7.13")

// Example mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
Expand Down Expand Up @@ -123,6 +153,55 @@ tasks.withType(ProcessResources).configureEach {
}
}

tasks.named('generateGrammarSource', AntlrTask) {
def pkg = 'com.sk89q.worldedit.antlr'
outputDirectory = file("build/generated-src/antlr/main/${pkg.replace('.', '/')}")
arguments = [
'-visitor', '-package', pkg,
'-Xexact-output-dir'
]
}

def altConfigFiles = { String artifactType ->
def deps = configurations.shade.incoming.dependencies.findAll { it instanceof ModuleDependency }
.collect { dependency ->
def depCopy = dependency.copy()
depCopy.artifact {
name = dependency.name
type = artifactType
extension = 'jar'
classifier = artifactType
}
depCopy
}

files(configurations.detachedConfiguration(deps.toArray(new Dependency[0]))
.resolvedConfiguration.lenientConfiguration.artifacts.findAll { it.classifier == artifactType }
.collect { zipTree(it.file) })
}

tasks.register('sourcesJar', Jar) {
from {
altConfigFiles('sources')
}
archiveClassifier = 'sources'
}

tasks.named('sourcesJar') {
mustRunAfter 'generateGrammarSource'
}

plugins.withId('idea') {
idea {
module {
sourceDirs += files('src/main/antlr')
sourceDirs += files('build/generated-src/antlr/main')
generatedSourceDirs += files('build/generated-src/antlr/main')
}
}
}


// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
Expand Down
14 changes: 10 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ org.gradle.debug=false
## Environment Properties

# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.20.2
minecraft_version=1.20.4
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.2,1.21)
minecraft_version_range=[1.20.4,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.2.86
#neo_version=20.4.42-beta
neo_version=20.4.0-beta
# The Neo version range can use any version of Neo as bounds or match the loader version range
neo_version_range=[20.2,)
neo_version_range=[20.5,)
# The loader version range can only use the major version of Neo/FML as bounds
loader_version_range=[1,)

Expand All @@ -39,3 +40,8 @@ mod_authors=YourNameHere, OtherNameHere
mod_description=Example mod description.\nNewline characters can be used and will be replaced properly.
# Pack version - this changes each minecraft release, in general.
pack_format_number=18


PISTON=0.5.7
AUTO_VALUE=1.9
TEXT=3.0.4
237 changes: 237 additions & 0 deletions src/main/antlr/com/sk89q/worldedit/antlr/Expression.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
grammar Expression;

// Lexer tokens:

PLUS : '+' ;
MINUS : '-' ;
TIMES : '*' ;
DIVIDE : '/' ;
MODULO : '%' ;
POWER : '^' | '**' ;
LEFT_SHIFT : '<<' ;
RIGHT_SHIFT : '>>' ;
ASSIGN : '=' ;
COMPLEMENT : '~' ;

PLUS_ASSIGN : '+=' ;
MINUS_ASSIGN : '-=' ;
TIMES_ASSIGN : '*=' ;
DIVIDE_ASSIGN : '/=' ;
MODULO_ASSIGN : '%=' ;
POWER_ASSIGN : '^=' ;

EQUAL : '==' ;
NOT_EQUAL : '!=' ;
NEAR : '~=' ;
LESS_THAN : '<' ;
LESS_THAN_OR_EQUAL : '<=' ;
GREATER_THAN : '>' ;
GREATER_THAN_OR_EQUAL : '>=' ;
// SC = "Short Circuit"
// Non-SC variants not currently implemented.
AND_SC : '&&' ;
OR_SC : '||' ;

INCREMENT : '++' ;
DECREMENT : '--' ;

COMMA : ',' ;
OPEN_PAREN : '(' ;
CLOSE_PAREN : ')' ;
OPEN_BRACKET : '{' ;
CLOSE_BRACKET : '}' ;
SEMI_COLON : ';' ;
QUESTION_MARK : '?' ;
COLON : ':' ;
EXCLAMATION_MARK : '!' ;

IF : 'if' ;
ELSE : 'else' ;
WHILE : 'while' ;
DO : 'do' ;
FOR : 'for' ;
BREAK : 'break' ;
CONTINUE : 'continue' ;
RETURN : 'return' ;
SWITCH : 'switch' ;
CASE : 'case' ;
DEFAULT : 'default' ;

fragment DIGIT : [0-9] ;
fragment SIGN : [+-] ;
fragment EXP_CHAR : [eE] ;
fragment EXPONENT : EXP_CHAR SIGN? DIGIT+ ;
fragment DECIMAL : '.' DIGIT+ ;

// All numbers are treated the same. No int/dec divide.
NUMBER : ( DIGIT+ DECIMAL? | DECIMAL ) EXPONENT? ;

ID : [A-Za-z] [0-9A-Za-z_]* ;

WS : [ \t\r\n\u000C]+ -> skip ;

// Parser rules:

/**
* All statements parseable from the input. Forces consumption of EOF token.
*/
allStatements : statements EOF ;

statements : statement+ ;

statement
: ( block
| ifStatement
| whileStatement
| doStatement
| forStatement
| simpleForStatement
| breakStatement
| continueStatement
| returnStatement
| switchStatement
| expressionStatement
| emptyStatement
) SEMI_COLON?
;

block : '{' statements '}' ;

ifStatement : IF '(' condition=expression ')' trueBranch=statement ( ELSE falseBranch=statement )? ;

whileStatement : WHILE '(' condition=expression ')' body=statement ;

doStatement : DO body=statement WHILE '(' condition=expression ')' ;

// C-Style for loop
forStatement
: FOR '(' init=expression ';' condition=expression ';' update=expression ')' body=statement ;

// Range for loop
simpleForStatement
: FOR '(' counter=ID ASSIGN first=expression ',' last=expression ')' body=statement ;

breakStatement : BREAK ;

continueStatement : CONTINUE ;

returnStatement : RETURN value=expression ;

switchStatement : SWITCH '(' target=expression ')' '{' (labels+=switchLabel ':' bodies+=statements )+ '}' ;

switchLabel
: CASE constant=constantExpression # Case
| DEFAULT # Default
;

expressionStatement : expression ;

emptyStatement: SEMI_COLON ;

expression : assignmentExpression ;

assignmentExpression
: conditionalExpression
| assignment
;

assignment
: target=ID assignmentOperator source=expression
;

assignmentOperator
: ASSIGN
| POWER_ASSIGN
| TIMES_ASSIGN
| DIVIDE_ASSIGN
| MODULO_ASSIGN
| PLUS_ASSIGN
| MINUS_ASSIGN
;

conditionalExpression
: conditionalOrExpression # CEFallthrough
| condition=conditionalOrExpression QUESTION_MARK
trueBranch=expression COLON falseBranch=conditionalExpression # TernaryExpr
;

conditionalOrExpression
: conditionalAndExpression # COFallthrough
| left=conditionalOrExpression OR_SC right=conditionalAndExpression # ConditionalOrExpr
;

conditionalAndExpression
: equalityExpression # CAFallthrough
| left=conditionalAndExpression AND_SC right=equalityExpression # ConditionalAndExpr
;

equalityExpression
: relationalExpression # EqFallthrough
| left=equalityExpression
op=
( EQUAL
| NOT_EQUAL
| NEAR
) right=relationalExpression # EqualityExpr
;

relationalExpression
: shiftExpression # ReFallthrough
| left=relationalExpression
op=
( LESS_THAN
| GREATER_THAN
| LESS_THAN_OR_EQUAL
| GREATER_THAN_OR_EQUAL
) right=shiftExpression # RelationalExpr
;

shiftExpression
: additiveExpression # ShFallthrough
| left=shiftExpression op=( LEFT_SHIFT | RIGHT_SHIFT ) right=additiveExpression # ShiftExpr
;

additiveExpression
: multiplicativeExpression # AdFallthrough
| left=additiveExpression op=( PLUS | MINUS ) right=multiplicativeExpression # AddExpr
;

multiplicativeExpression
: powerExpression # MuFallthrough
| left=multiplicativeExpression
op=
( TIMES
| DIVIDE
| MODULO
) right=powerExpression # MultiplicativeExpr
;

powerExpression
: unaryExpression # PwFallthrough
| left=powerExpression POWER right=unaryExpression # PowerExpr
;

unaryExpression
: op=( INCREMENT | DECREMENT ) target=ID # PreCrementExpr
| op=( PLUS | MINUS ) expr=unaryExpression # PlusMinusExpr
| postfixExpression # UaFallthrough
| COMPLEMENT expr=unaryExpression # ComplementExpr
| EXCLAMATION_MARK expr=unaryExpression # NotExpr
;

postfixExpression
: unprioritizedExpression # PoFallthrough
| target=ID op=( INCREMENT | DECREMENT) # PostCrementExpr
| expr=postfixExpression op=EXCLAMATION_MARK # PostfixExpr
;

unprioritizedExpression
: functionCall # FunctionCallExpr
| constantExpression # ConstantExpr
| source=ID # IdExpr
| '(' expression ')' # WrappedExpr
;

constantExpression : NUMBER ;

functionCall : name=ID '(' (args+=expression ( ',' args+=expression )*)? ')' ;
Loading

0 comments on commit 68ce366

Please sign in to comment.