diff --git a/Jenkinsfile b/Jenkinsfile index 5fc656e..7edd445 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,8 @@ pipeline { agent { - dockerfile true + dockerfile { + args '-v /data/maven:/data/maven' + } } stages { stage('Setup') { diff --git a/build.gradle b/build.gradle index e647c78..986ab48 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'fabric-loom' version '0.2.7-SNAPSHOT' - id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'maven-publish' } compileJava { @@ -62,27 +62,20 @@ jar { from 'LICENSE' } -if (project.hasProperty('curseforge.api_key')) { - curseforge { - apiKey = project.getProperty('curseforge.api_key') - project { - id = project.curseforge_id - changelog = 'A changelog can be found at https://gitea.thebrokenrail.com/TheBrokenRail/ScriptCraft/src/branch/master/CHANGELOG.md' - releaseType = 'release' - addGameVersion project.simple_minecraft_version - addGameVersion 'Fabric' - mainArtifact(remapJar) { - displayName = "ScriptCraft v${mod_version} for ${project.minecraft_version}" +publishing { + publications { + mavenJava(MavenPublication) { + artifact(remapJar) { + builtBy remapJar } - afterEvaluate { - uploadTask.dependsOn('remapJar') - } - relations { - requiredDependency 'fabric-api' + artifact(typescriptAPI) { + builtBy typescriptAPI } } - options { - forgeGradleIntegration = false + } + repositories { + maven { + url '/data/maven' } } } \ No newline at end of file diff --git a/examples/typescript/.gitignore b/examples/typescript/.gitignore new file mode 100644 index 0000000..3174d3b --- /dev/null +++ b/examples/typescript/.gitignore @@ -0,0 +1,28 @@ +# gradle + +.gradle/ +build/ +out/ +classes/ + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +bin/ +.classpath +.project + +# fabric + +run/ + +remappedSrc/ + +libs/ \ No newline at end of file diff --git a/examples/typescript/build.gradle b/examples/typescript/build.gradle new file mode 100644 index 0000000..5d66155 --- /dev/null +++ b/examples/typescript/build.gradle @@ -0,0 +1,68 @@ +plugins { + id 'fabric-loom' version '0.2.7-SNAPSHOT' +} + +compileJava { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +archivesBaseName = project.archives_base_name +def mod_version = project.mod_version as Object +version = "${mod_version}+${project.minecraft_version}" +group = project.maven_group as Object + +minecraft { +} + +repositories { + flatDir { + dirs 'libs' + } +} + +dependencies { + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" + + modImplementation name: 'scriptcraft' +} + +apply from: './typescript.build.gradle' + +processResources { + inputs.property 'version', mod_version + + from(sourceSets.main.resources.srcDirs) { + include 'fabric.mod.json' + expand 'version': mod_version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'fabric.mod.json' + } +} + +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' +} + +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. +task sourcesJar(type: Jar, dependsOn: classes) { + classifier 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives sourcesJar +} + +jar { + from 'LICENSE' +} diff --git a/examples/typescript/gradle b/examples/typescript/gradle new file mode 120000 index 0000000..1ce6c4c --- /dev/null +++ b/examples/typescript/gradle @@ -0,0 +1 @@ +../../gradle \ No newline at end of file diff --git a/examples/typescript/gradle.properties b/examples/typescript/gradle.properties new file mode 100644 index 0000000..7fe1471 --- /dev/null +++ b/examples/typescript/gradle.properties @@ -0,0 +1,13 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs = -Xmx1G + +# Fabric Properties + # check these on https://fabricmc.net/use + minecraft_version = 1.15.2 + yarn_build = 15 + fabric_loader_version = 0.8.2+build.194 + +# Mod Properties + mod_version = 1.0.0 + maven_group = com.thebrokenrail + archives_base_name = scriptcraft-typescript-example diff --git a/examples/typescript/gradlew b/examples/typescript/gradlew new file mode 120000 index 0000000..343e0d2 --- /dev/null +++ b/examples/typescript/gradlew @@ -0,0 +1 @@ +../../gradlew \ No newline at end of file diff --git a/examples/typescript/gradlew.bat b/examples/typescript/gradlew.bat new file mode 120000 index 0000000..cb5a946 --- /dev/null +++ b/examples/typescript/gradlew.bat @@ -0,0 +1 @@ +../../gradlew.bat \ No newline at end of file diff --git a/examples/typescript/scripts/setup.sh b/examples/typescript/scripts/setup.sh new file mode 100644 index 0000000..a68ac13 --- /dev/null +++ b/examples/typescript/scripts/setup.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +SCRIPTCRAFT_BRANCH='master' + +if [ -d ../libs ]; then + rm -rf ../libs +fi +mkdir ../libs + +curl -L -o ../libs/scriptcraft.jar "https://jenkins.thebrokenrail.com/job/ScriptCraft/job/${SCRIPTCRAFT_BRANCH}/lastSuccessfulBuild/artifact/build/libs/scriptcraft-1.0.0-SNAPSHOT.jar" +curl -L -o ../libs/scriptcraft-api.tar.gz "https://jenkins.thebrokenrail.com/job/ScriptCraft/job/${SCRIPTCRAFT_BRANCH}/lastSuccessfulBuild/artifact/build/distributions/scriptcraft-1.0.0-SNAPSHOT-api.tar.gz" + +cd ../src/main/ts +npm install \ No newline at end of file diff --git a/examples/typescript/settings.gradle b/examples/typescript/settings.gradle new file mode 120000 index 0000000..19fe1e9 --- /dev/null +++ b/examples/typescript/settings.gradle @@ -0,0 +1 @@ +../../settings.gradle \ No newline at end of file diff --git a/examples/typescript/src/main/java/com/thebrokenrail/scriptcraft/example/TypeScriptExample.java b/examples/typescript/src/main/java/com/thebrokenrail/scriptcraft/example/TypeScriptExample.java new file mode 100644 index 0000000..ff4005c --- /dev/null +++ b/examples/typescript/src/main/java/com/thebrokenrail/scriptcraft/example/TypeScriptExample.java @@ -0,0 +1,15 @@ +package com.thebrokenrail.scriptcraft.example; + +import com.thebrokenrail.scriptcraft.core.ScriptCraftEntrypoint; + +public class TypeScriptExample implements ScriptCraftEntrypoint { + @Override + public String getModID() { + return "modid"; + } + + @Override + public String getModIndex() { + return "index.js"; + } +} \ No newline at end of file diff --git a/examples/typescript/src/main/resources/assets b/examples/typescript/src/main/resources/assets new file mode 120000 index 0000000..90bacbe --- /dev/null +++ b/examples/typescript/src/main/resources/assets @@ -0,0 +1 @@ +../../../../../src/main/resources/assets \ No newline at end of file diff --git a/examples/typescript/src/main/resources/fabric.mod.json b/examples/typescript/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..70a24ce --- /dev/null +++ b/examples/typescript/src/main/resources/fabric.mod.json @@ -0,0 +1,28 @@ +{ + "schemaVersion": 1, + "id": "modid", + "version": "${version}", + "name": "ScriptCraft TypeScript Example", + "description": "TypeScript Example for ScriptCraft", + "authors": [ + "TheBrokenRail" + ], + "contact": { + "homepage": "https://thebrokenrail.com/", + "sources": "https://gitea.thebrokenrail.com/TheBrokenRail/ScriptCraft.git", + "issues": "https://gitea.thebrokenrail.com/TheBrokenRail/ScriptCraft/issues" + }, + "license": "MIT", + "icon": "assets/scriptcraft/icon.png", + "environment": "*", + "entrypoints": { + "scriptcraft": [ + "com.thebrokenrail.scriptcraft.example.TypeScriptExample" + ] + }, + "depends": { + "fabricloader": ">=0.7.4", + "minecraft": "1.15.x", + "scriptcraft": "*" + } +} diff --git a/examples/typescript/src/main/ts/.gitignore b/examples/typescript/src/main/ts/.gitignore new file mode 100644 index 0000000..426ba21 --- /dev/null +++ b/examples/typescript/src/main/ts/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +package-lock.json +scriptcraft/ +lib/ \ No newline at end of file diff --git a/examples/typescript/src/main/ts/package.json b/examples/typescript/src/main/ts/package.json new file mode 100644 index 0000000..26b28e7 --- /dev/null +++ b/examples/typescript/src/main/ts/package.json @@ -0,0 +1,11 @@ +{ + "devDependencies": { + "typescript": "latest" + }, + "dependencies": { + "scriptcraft-api": "file:../../../libs/scriptcraft-api.tar.gz" + }, + "scripts": { + "build": "tsc" + } +} diff --git a/examples/typescript/src/main/ts/src/modid/index.ts b/examples/typescript/src/main/ts/src/modid/index.ts new file mode 100644 index 0000000..f804dc7 --- /dev/null +++ b/examples/typescript/src/main/ts/src/modid/index.ts @@ -0,0 +1,73 @@ +import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft'; + +console.log('hello'); + +class MyBlockEntity extends CustomBlockEntity { + ticks = 0; + + toTag(tag: CompoundTag): CompoundTag { + tag.set('MyTicks', this.ticks, NumberType.INT); + return tag; + } + + fromTag(tag: CompoundTag): void { + const obj = tag.get('MyTicks'); + if (typeof obj === 'number') { + this.ticks = obj; + } else { + this.ticks = 0; + } + } + + tick(): void { + this.ticks++; + this.markDirty(); + } +} + +class MyBlock extends CustomBlockWithEntity { + constructor() { + super(new BlockSettings('STONE', 'IRON')); + } + + onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult { + const entity = world.getCustomBlockEntity(blockPos); + if (entity instanceof MyBlockEntity) { + console.log('Ticks: ' + entity.ticks); + } + world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone'))); + return ActionResult.SUCCESS; + } + + createBlockEntity(): CustomBlockEntity { + return new MyBlockEntity(); + } +} + +Registry.register(Registry.BLOCK, new Identifier('test', 'my_block'), new MyBlock()); +Registry.register(Registry.ITEM, new Identifier('test', 'my_block'), new BlockItem(new Identifier('test', 'my_block'), new ItemSettings())); + +class MyItem extends CustomItem { + constructor() { + super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128)); + } + + onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult { + console.log('Item Use: Normal'); + return ActionResult.SUCCESS; + } + + onUseOnBlock(world: World, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult { + console.log('Item Use: Block ' + blockPos.toString()); + world.spawnEntity(new Identifier('minecraft:cow'), blockPos.offset(side).add(new Pos(0.5, 0, 0.5))).toString(); + return ActionResult.SUCCESS; + } + + onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult { + console.log('Item Use: Entity ' + target.toTag().toString()); + console.log('Health: ' + target.toTag().get('Health').toString()); + return ActionResult.SUCCESS; + } +} + +Registry.register(Registry.ITEM, new Identifier('test', 'my_item'), new MyItem()); diff --git a/examples/typescript/src/main/ts/tsconfig.json b/examples/typescript/src/main/ts/tsconfig.json new file mode 100644 index 0000000..62236d9 --- /dev/null +++ b/examples/typescript/src/main/ts/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "noImplicitAny": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "lib": ["es2020"], + "module": "es2020", + "target": "es2020", + "typeRoots": ["node_modules/scriptcraft-api/types"], + "rootDir": "src", + "baseUrl": "src", + "paths": { + "minecraft": ["../node_modules/scriptcraft-api/lib/minecraft/index.d.ts"] + }, + "outDir": "lib/ts" + }, + "include": [ + "src/**/*.ts" + ] +} \ No newline at end of file diff --git a/examples/typescript/typescript.build.gradle b/examples/typescript/typescript.build.gradle new file mode 100644 index 0000000..0e75ac6 --- /dev/null +++ b/examples/typescript/typescript.build.gradle @@ -0,0 +1,29 @@ +def typescriptRoot = 'src/main/ts' +def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot) + +def typescriptOut = new File(typescriptRootFile, 'lib/ts') + +task typescript(group: 'typescript', type: Exec) { + inputs.dir typescriptRootFile + outputs.dirs typescriptOut + + workingDir typescriptRootFile + + executable 'npm' + + args 'run', 'build' + + doFirst { + project.delete { + delete typescriptOut + } + } +} + +processResources.dependsOn typescript + +processResources { + from(typescriptOut.absolutePath) { + into 'scriptcraft' + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 6390000..5db7540 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,6 @@ org.gradle.jvmargs = -Xmx1G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version = 1.15.2 - curseforge_id = TBD - simple_minecraft_version = 1.15.2 yarn_build = 15 fabric_loader_version = 0.8.2+build.194 diff --git a/src/main/ts/package.json b/src/main/ts/package.json index 57c3795..700e105 100644 --- a/src/main/ts/package.json +++ b/src/main/ts/package.json @@ -1,7 +1,6 @@ { "name": "minecraft", "version" : "1.0.0-SNAPSHOT", - "types": "lib/minecraft/index.d.ts", "devDependencies": { "@typescript-eslint/eslint-plugin": "latest", "@typescript-eslint/parser": "latest",