Generate DTS Better
Some checks failed
ScriptCraft/pipeline/head There was a failure building this commit

This commit is contained in:
TheBrokenRail 2020-04-29 10:58:27 -04:00
parent 7ffcc55da5
commit 275ec8f2c6
4 changed files with 10 additions and 82 deletions

3
Jenkinsfile vendored
View File

@ -10,11 +10,12 @@ pipeline {
} }
stage('Build') { stage('Build') {
steps { steps {
sh './gradlew build typedoc eslint typescriptDist' sh './gradlew build typedoc eslint'
} }
post { post {
success { success {
archiveArtifacts artifacts: 'build/libs/*', fingerprint: true archiveArtifacts artifacts: 'build/libs/*', fingerprint: true
archiveArtifacts artifacts: 'build/distributions/*', fingerprint: true
publishHTML target: [ publishHTML target: [
allowMissing: false, allowMissing: false,

View File

@ -1,73 +0,0 @@
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());

View File

@ -10,9 +10,6 @@
"typeRoots": ["src/types"], "typeRoots": ["src/types"],
"rootDir": "src", "rootDir": "src",
"baseUrl": "src", "baseUrl": "src",
"paths": {
"minecraft": ["minecraft/index"]
},
"outDir": "lib/ts", "outDir": "lib/ts",
"declaration": true, "declaration": true,
"declarationDir": "lib/dts" "declarationDir": "lib/dts"

View File

@ -21,20 +21,23 @@ task typescript(group: 'typescript', type: Exec) {
} }
} }
task typescriptDist(group: 'typescript', type: Tar) { task apiTar(group: 'typescript', type: Tar) {
into('/types') { into('/types') {
from new File(typescriptRootFile as File, 'src/types') from new File(typescriptRootFile as File, 'src/types')
} }
into('/lib') { into('/lib') {
from dtsOut from dtsOut
} }
from new File(typescriptRootFile as File, 'package.json')
archiveName 'typescript-dist.tar.gz' classifier 'api'
destinationDir new File(buildDir, 'libs')
compression Compression.GZIP
} }
typescriptDist.dependsOn typescript apiTar.dependsOn typescript
artifacts {
archives apiTar
}
task eslint(group: 'typescript', type: Exec) { task eslint(group: 'typescript', type: Exec) {
workingDir typescriptRootFile workingDir typescriptRootFile