This commit is contained in:
parent
bc7dc8d5c2
commit
2539e98a44
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@ -10,7 +10,7 @@ pipeline {
|
||||
}
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh './gradlew build typedoc'
|
||||
sh './gradlew build typedoc eslint'
|
||||
}
|
||||
post {
|
||||
success {
|
||||
|
149
build.gradle
149
build.gradle
@ -3,65 +3,6 @@ plugins {
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0'
|
||||
}
|
||||
|
||||
def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c')
|
||||
|
||||
class JNIPlatform {
|
||||
String name
|
||||
String[] cmakeArgs
|
||||
String libExtension
|
||||
|
||||
JNIPlatform(String name, String libExtension, File rootDir) {
|
||||
this.name = name
|
||||
this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
|
||||
this.libExtension = libExtension
|
||||
}
|
||||
}
|
||||
|
||||
JNIPlatform[] jniPlatforms = [
|
||||
new JNIPlatform("linux-x86_64", ".so", rootDir),
|
||||
new JNIPlatform("linux-x86", ".so", rootDir),
|
||||
new JNIPlatform("linux-armhf", ".so", rootDir),
|
||||
new JNIPlatform("linux-arm64", ".so", rootDir),
|
||||
new JNIPlatform("windows-x86_64", ".dll", rootDir),
|
||||
new JNIPlatform("windows-x86", ".dll", rootDir)
|
||||
]
|
||||
|
||||
task cleanJNI {}
|
||||
task compileJNI {}
|
||||
|
||||
for (JNIPlatform platform : jniPlatforms) {
|
||||
def buildDir = new File(cDir, "build-${platform.name}")
|
||||
if (!buildDir.exists()) {
|
||||
buildDir.mkdir()
|
||||
}
|
||||
|
||||
tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) {
|
||||
workingDir buildDir
|
||||
|
||||
executable 'cmake'
|
||||
args platform.cmakeArgs + ['..']
|
||||
}
|
||||
|
||||
tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) {
|
||||
workingDir buildDir
|
||||
|
||||
executable 'make'
|
||||
|
||||
dependsOn tasks.getByName("cmake-${platform.name}")
|
||||
}
|
||||
|
||||
compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
|
||||
|
||||
tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) {
|
||||
delete buildDir.absolutePath
|
||||
}
|
||||
|
||||
cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
|
||||
}
|
||||
|
||||
clean.dependsOn cleanJNI
|
||||
processResources.dependsOn compileJNI
|
||||
|
||||
compileJava {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
@ -82,72 +23,8 @@ dependencies {
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
|
||||
}
|
||||
|
||||
def typescriptOut = new File(buildDir, 'generated/typescript')
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
resources {
|
||||
srcDir typescriptOut
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def typescriptRoot = 'src/main/js'
|
||||
def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
|
||||
|
||||
task typescript(group: 'build') {
|
||||
inputs.dir typescriptRootFile
|
||||
outputs.dir typescriptOut
|
||||
|
||||
doFirst {
|
||||
project.delete {
|
||||
delete typescriptOut
|
||||
}
|
||||
typescriptOut.mkdirs()
|
||||
|
||||
project.exec {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'build', '--'
|
||||
args '--outDir', new File(typescriptOut, 'scriptcraft').absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task eslint(group: 'verification', type: Exec) {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'eslint'
|
||||
}
|
||||
|
||||
processResources.dependsOn typescript
|
||||
|
||||
def typedocOut = new File(buildDir, 'typedoc')
|
||||
|
||||
task typedoc(group: 'documentation') {
|
||||
inputs.dir typescriptRootFile
|
||||
outputs.dir typedocOut
|
||||
|
||||
doFirst {
|
||||
project.delete {
|
||||
delete typedocOut
|
||||
}
|
||||
typedocOut.mkdirs()
|
||||
|
||||
project.exec {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'typedoc', '--'
|
||||
args '--out', typedocOut.absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
apply from: './typescript.build.gradle'
|
||||
apply from: './jni.build.gradle'
|
||||
|
||||
processResources {
|
||||
inputs.property 'version', mod_version
|
||||
@ -161,20 +38,6 @@ processResources {
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude 'fabric.mod.json'
|
||||
}
|
||||
|
||||
for (JNIPlatform platform : jniPlatforms) {
|
||||
def buildDir = new File(cDir, "build-${platform.name}")
|
||||
if (!buildDir.exists()) {
|
||||
buildDir.mkdir()
|
||||
}
|
||||
|
||||
def file = new File(buildDir, 'libscriptcraft' + platform.libExtension)
|
||||
inputs.files file
|
||||
|
||||
from(file.absolutePath) {
|
||||
into new File('natives', platform.name).path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
@ -192,16 +55,8 @@ task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
task typedocJar(type: Jar) {
|
||||
classifier 'typedoc'
|
||||
from typedocOut
|
||||
}
|
||||
|
||||
typedocJar.dependsOn typedoc
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
archives typedocJar
|
||||
}
|
||||
|
||||
jar {
|
||||
|
74
jni.build.gradle
Normal file
74
jni.build.gradle
Normal file
@ -0,0 +1,74 @@
|
||||
def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c')
|
||||
|
||||
class JNIPlatform {
|
||||
String name
|
||||
String[] cmakeArgs
|
||||
String libExtension
|
||||
|
||||
JNIPlatform(String name, String libExtension, File rootDir) {
|
||||
this.name = name
|
||||
this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
|
||||
this.libExtension = libExtension
|
||||
}
|
||||
}
|
||||
|
||||
JNIPlatform[] jniPlatforms = [
|
||||
new JNIPlatform("linux-x86_64", ".so", rootDir),
|
||||
new JNIPlatform("linux-x86", ".so", rootDir),
|
||||
new JNIPlatform("linux-armhf", ".so", rootDir),
|
||||
new JNIPlatform("linux-arm64", ".so", rootDir),
|
||||
new JNIPlatform("windows-x86_64", ".dll", rootDir),
|
||||
new JNIPlatform("windows-x86", ".dll", rootDir)
|
||||
]
|
||||
|
||||
task cleanJNI {}
|
||||
task compileJNI {}
|
||||
|
||||
for (JNIPlatform platform : jniPlatforms) {
|
||||
def buildDir = new File(cDir, "build-${platform.name}")
|
||||
if (!buildDir.exists()) {
|
||||
buildDir.mkdir()
|
||||
}
|
||||
|
||||
tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) {
|
||||
workingDir buildDir
|
||||
|
||||
executable 'cmake'
|
||||
args platform.cmakeArgs + ['..']
|
||||
}
|
||||
|
||||
tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) {
|
||||
workingDir buildDir
|
||||
|
||||
executable 'make'
|
||||
|
||||
dependsOn tasks.getByName("cmake-${platform.name}")
|
||||
}
|
||||
|
||||
compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
|
||||
|
||||
tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) {
|
||||
delete buildDir.absolutePath
|
||||
}
|
||||
|
||||
cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
|
||||
}
|
||||
|
||||
clean.dependsOn cleanJNI
|
||||
processResources.dependsOn compileJNI
|
||||
|
||||
processResources {
|
||||
for (JNIPlatform platform : jniPlatforms) {
|
||||
def buildDir = new File(cDir, "build-${platform.name}")
|
||||
if (!buildDir.exists()) {
|
||||
buildDir.mkdir()
|
||||
}
|
||||
|
||||
def file = new File(buildDir, 'libscriptcraft' + platform.libExtension)
|
||||
inputs.files file
|
||||
|
||||
from(file.absolutePath) {
|
||||
into new File('natives', platform.name).path
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"tsconfigRootDir": ".",
|
||||
"project": ["./tsconfig.json"]
|
||||
"project": ["./tsconfig.json"],
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
@ -24,6 +25,19 @@
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"quotes": ["error", "single"],
|
||||
"eol-last": ["error", "always"]
|
||||
"eol-last": ["error", "always"],
|
||||
"no-eq-null": "error",
|
||||
"no-unneeded-ternary": "error",
|
||||
"block-spacing": "error",
|
||||
"camelcase": "error",
|
||||
"comma-dangle": ["error", "never"],
|
||||
"func-call-spacing": ["error", "never"],
|
||||
"function-call-argument-newline": ["error", "never"],
|
||||
"implicit-arrow-linebreak": ["error", "beside"],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"no-trailing-spaces": "error",
|
||||
"no-lonely-if": "error",
|
||||
"no-var": "error",
|
||||
"prefer-arrow-callback": "error"
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
"typescript": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint --ignore-path .gitignore src",
|
||||
"eslint": "eslint --ignore-path .gitignore \"src/**/*\"",
|
||||
"build": "tsc",
|
||||
"typedoc": "typedoc"
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ export class CustomBlockEntity {
|
||||
* Mark Dirty
|
||||
*/
|
||||
markDirty(): void {
|
||||
if (this.getWorld() != null) {
|
||||
if (this.getWorld() !== null) {
|
||||
useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export class DamageSource {
|
||||
*/
|
||||
private static build(bridge: string, value: BridgeValueType): DamageSource {
|
||||
const obj = useBridge(bridge, value) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new DamageSource(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -73,9 +73,6 @@ export class Entity {
|
||||
* @internal
|
||||
*/
|
||||
constructor(object: JavaObject | Entity) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object instanceof Entity) {
|
||||
this.javaObject = object.javaObject;
|
||||
} else {
|
||||
@ -89,7 +86,7 @@ export class Entity {
|
||||
*/
|
||||
getEntityWorld(): World {
|
||||
const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new World(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -102,7 +99,7 @@ export class Entity {
|
||||
*/
|
||||
getID(): Identifier {
|
||||
const obj = useBridge('Entity.getID', this.javaObject) as string;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -185,7 +182,7 @@ export class Entity {
|
||||
*/
|
||||
getPosition(): Pos {
|
||||
const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[];
|
||||
if (pos != null && pos.length === 3) {
|
||||
if (pos !== null && pos.length === 3) {
|
||||
return new Pos(pos[0], pos[1], pos[2]);
|
||||
} else {
|
||||
return null;
|
||||
@ -206,7 +203,7 @@ export class Entity {
|
||||
*/
|
||||
toTag(): CompoundTag {
|
||||
const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -27,7 +27,7 @@ export class ItemStack {
|
||||
*/
|
||||
static create(item: Identifier, count?: number): ItemStack {
|
||||
const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -40,7 +40,7 @@ export class ItemStack {
|
||||
*/
|
||||
getItem(): Identifier {
|
||||
const obj = useBridge('ItemStack.getItem', this.javaObject) as string;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -101,7 +101,7 @@ export class ItemStack {
|
||||
*/
|
||||
getTag(): CompoundTag {
|
||||
const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -122,7 +122,7 @@ export class ItemStack {
|
||||
*/
|
||||
toTag(): CompoundTag {
|
||||
const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -136,7 +136,7 @@ export class ItemStack {
|
||||
*/
|
||||
static fromTag(tag: CompoundTag): ItemStack {
|
||||
const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -322,5 +322,5 @@ addBridge('CustomItem.onUseOnBlock', (id: string, world: JavaObject, x: number,
|
||||
});
|
||||
|
||||
addBridge('CustomItem.onUseOnEntity', (id: string, player: JavaObject, target: JavaObject, hand: keyof typeof Hand): boolean => {
|
||||
return ItemRegistry.INSTANCE.get(new Identifier(id)).onUseOnEntity(new PlayerEntity(player), new LivingEntity(target), Hand[hand]) === ActionResult.SUCCESS ? true : false;
|
||||
return ItemRegistry.INSTANCE.get(new Identifier(id)).onUseOnEntity(new PlayerEntity(player), new LivingEntity(target), Hand[hand]) === ActionResult.SUCCESS;
|
||||
});
|
||||
|
@ -86,7 +86,7 @@ export class CompoundTag {
|
||||
set(key: string, value: number, numberType: NumberType): void;
|
||||
set(key: string, value: Exclude<TagType, number>): void;
|
||||
set(key: string, value: TagType, numberType?: NumberType): void {
|
||||
useBridge('CompoundTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE);
|
||||
useBridge('CompoundTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType !== null ? numberType : NumberType.DOUBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ export class CompoundTag {
|
||||
*/
|
||||
static create(): CompoundTag {
|
||||
const obj = useBridge('CompoundTag.create') as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -148,7 +148,7 @@ export class ListTag {
|
||||
set(key: number, value: number, numberType: NumberType): void;
|
||||
set(key: number, value: Exclude<TagType, number>): void;
|
||||
set(key: number, value: TagType, numberType?: NumberType): void {
|
||||
useBridge('ListTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE);
|
||||
useBridge('ListTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType !== null ? numberType : NumberType.DOUBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -165,7 +165,7 @@ export class ListTag {
|
||||
*/
|
||||
static create(): ListTag {
|
||||
const obj = useBridge('ListTag.create') as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new ListTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -36,7 +36,7 @@ export class World {
|
||||
*/
|
||||
getBlockState(pos: Pos): BlockState {
|
||||
const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new BlockState(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -50,7 +50,7 @@ export class World {
|
||||
*/
|
||||
spawnEntity(id: Identifier, pos: Pos): Entity {
|
||||
const obj = useBridge('World.spawnEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new Entity(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -64,7 +64,7 @@ export class World {
|
||||
*/
|
||||
getCustomBlockEntity(pos: Pos): CustomBlockEntity {
|
||||
const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return BlockRegistry.INSTANCE.getCustomBlockEntity(obj);
|
||||
} else {
|
||||
return null;
|
||||
@ -78,7 +78,7 @@ export class World {
|
||||
*/
|
||||
getBlockEntity(pos: Pos): Identifier {
|
||||
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
|
||||
if (obj != null) {
|
||||
if (obj !== null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
73
typescript.build.gradle
Normal file
73
typescript.build.gradle
Normal file
@ -0,0 +1,73 @@
|
||||
def typescriptOut = new File(buildDir, 'generated/typescript')
|
||||
|
||||
def typescriptRoot = 'src/main/js'
|
||||
def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
|
||||
|
||||
task typescript(group: 'build') {
|
||||
inputs.dir typescriptRootFile
|
||||
outputs.dir typescriptOut
|
||||
|
||||
doFirst {
|
||||
project.delete {
|
||||
delete typescriptOut
|
||||
}
|
||||
typescriptOut.mkdirs()
|
||||
|
||||
project.exec {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'build', '--'
|
||||
args '--outDir', new File(typescriptOut, 'scriptcraft').absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task eslint(group: 'verification', type: Exec) {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'eslint'
|
||||
}
|
||||
|
||||
processResources.dependsOn typescript
|
||||
|
||||
def typedocOut = new File(buildDir, 'typedoc')
|
||||
|
||||
task typedoc(group: 'documentation') {
|
||||
inputs.dir typescriptRootFile
|
||||
outputs.dir typedocOut
|
||||
|
||||
doFirst {
|
||||
project.delete {
|
||||
delete typedocOut
|
||||
}
|
||||
typedocOut.mkdirs()
|
||||
|
||||
project.exec {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'typedoc', '--'
|
||||
args '--out', typedocOut.absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
from typescriptOut.absolutePath
|
||||
}
|
||||
|
||||
task typedocJar(type: Jar) {
|
||||
classifier 'typedoc'
|
||||
from typedocOut
|
||||
}
|
||||
|
||||
typedocJar.dependsOn typedoc
|
||||
|
||||
artifacts {
|
||||
archives typedocJar
|
||||
}
|
Reference in New Issue
Block a user