diff --git a/Dockerfile b/Dockerfile index d3375b9..76a1bf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,4 @@ RUN curl -sL https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key a apt-get update && \ apt-get install --no-install-recommends -y cmake -RUN apt-get clean - -RUN npm install -g typescript typedoc \ No newline at end of file +RUN apt-get clean \ No newline at end of file diff --git a/build.gradle b/build.gradle index 0706a03..158b149 100644 --- a/build.gradle +++ b/build.gradle @@ -92,9 +92,8 @@ sourceSets { } } -def typescriptRoot = rootProject.typescript_root as String -def resources = new File(rootProject.rootDir, 'src/main/resources') -def typescriptRootFile = new File(resources, typescriptRoot) +def typescriptRoot = 'src/main/js' +def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot) task typescript(group: 'build') { inputs.dir typescriptRootFile @@ -107,14 +106,24 @@ task typescript(group: 'build') { typescriptOut.mkdirs() project.exec { - executable 'tsc' + workingDir typescriptRootFile - args '--outDir', new File(typescriptOut, typescriptRoot).absolutePath - args '--project', typescriptRootFile.absolutePath + 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') @@ -131,8 +140,10 @@ task typedoc(group: 'documentation') { project.exec { workingDir typescriptRootFile - executable 'typedoc' + executable 'npm' + + args 'run', 'typedoc', '--' args '--out', typedocOut.absolutePath } } @@ -151,9 +162,6 @@ processResources { exclude 'fabric.mod.json' } - exclude typescriptRoot + '/**/*.ts' - exclude typescriptRoot + '/types' - for (JNIPlatform platform : jniPlatforms) { def buildDir = new File(cDir, "build-${platform.name}") if (!buildDir.exists()) { diff --git a/gradle.properties b/gradle.properties index 775419a..533a03d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,6 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs = -Xmx1G -typescript_root = scriptcraft - # Fabric Properties # check these on https://fabricmc.net/use minecraft_version = 1.15.2 diff --git a/scripts/setup.sh b/scripts/setup.sh index 2cb3844..bf239a8 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -3,4 +3,7 @@ set -e ./download-quickjs.sh -./download-jni-headers.sh \ No newline at end of file +./download-jni-headers.sh + +cd ../src/main/js +npm install \ No newline at end of file diff --git a/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockEntity.java b/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockEntity.java index f1c998b..b4defa3 100644 --- a/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockEntity.java +++ b/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockEntity.java @@ -12,22 +12,22 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable { - private static long newObjID = 0; + private static double newObjID = 0; - private final long objID; + private final double objID; public CustomBlockEntity(BlockEntityType type, Identifier id) { super(type); objID = newObjID++; - QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), (double) objID); + QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), objID); } @Override public void fromTag(CompoundTag tag) { super.fromTag(tag); - QuickJSManager.bridge("CustomBlockEntity.fromTag", (double) objID, tag); + QuickJSManager.bridge("CustomBlockEntity.fromTag", objID, tag); } @Override @@ -37,7 +37,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS @Override public CompoundTag toTag(CompoundTag tag) { - return (CompoundTag) QuickJSManager.bridge("CustomBlockEntity.toTag", (double) objID, super.toTag(tag)); + return (CompoundTag) QuickJSManager.bridge("CustomBlockEntity.toTag", objID, super.toTag(tag)); } @Override @@ -47,20 +47,20 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS @Override public void tick() { - QuickJSManager.bridge("CustomBlockEntity.tick", (double) objID); + QuickJSManager.bridge("CustomBlockEntity.tick", objID); } @Override public void setLocation(World world, BlockPos pos) { super.setLocation(world, pos); - QuickJSManager.bridge("CustomBlockEntity.setLocation", (double) objID, world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ()); + QuickJSManager.bridge("CustomBlockEntity.setLocation", objID, world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ()); } @SuppressWarnings("deprecation") @Override protected void finalize() throws Throwable { try { - QuickJSManager.bridge("CustomBlockEntity.free", (double) objID); + QuickJSManager.bridge("CustomBlockEntity.free", objID); } finally { super.finalize(); } @@ -74,7 +74,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS } } - public long getObjID() { + public double getObjID() { return objID; } } diff --git a/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockWithEntity.java b/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockWithEntity.java index 457add7..ac583c9 100644 --- a/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockWithEntity.java +++ b/src/main/java/com/thebrokenrail/scriptcraft/api/block/CustomBlockWithEntity.java @@ -1,7 +1,5 @@ package com.thebrokenrail.scriptcraft.api.block; -import com.thebrokenrail.scriptcraft.api.block.CustomBlock; -import com.thebrokenrail.scriptcraft.api.block.CustomBlockEntity; import net.minecraft.block.BlockEntityProvider; import net.minecraft.block.entity.BlockEntity; import net.minecraft.util.Identifier; diff --git a/src/main/js/.eslintrc.json b/src/main/js/.eslintrc.json new file mode 100644 index 0000000..727843d --- /dev/null +++ b/src/main/js/.eslintrc.json @@ -0,0 +1,29 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "tsconfigRootDir": ".", + "project": ["./tsconfig.json"] + }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "rules": { + "@typescript-eslint/no-extra-parens": "error", + "@typescript-eslint/semi": "error", + "curly": "error", + "@typescript-eslint/indent": ["error", 4], + "arrow-parens": ["error", "as-needed"], + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-use-before-define": "off", + "quotes": ["error", "single"], + "eol-last": ["error", "always"] + } +} \ No newline at end of file diff --git a/src/main/js/.gitignore b/src/main/js/.gitignore new file mode 100644 index 0000000..ccb2c80 --- /dev/null +++ b/src/main/js/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json \ No newline at end of file diff --git a/src/main/js/package.json b/src/main/js/package.json new file mode 100644 index 0000000..09f31b2 --- /dev/null +++ b/src/main/js/package.json @@ -0,0 +1,15 @@ +{ + "name": "scriptcraft", + "devDependencies": { + "@typescript-eslint/eslint-plugin": "latest", + "@typescript-eslint/parser": "latest", + "eslint": "latest", + "typedoc": "latest", + "typescript": "latest" + }, + "scripts": { + "eslint": "eslint --ignore-path .gitignore src", + "build": "tsc", + "typedoc": "typedoc" + } +} diff --git a/src/main/resources/scriptcraft/minecraft/block.ts b/src/main/js/src/minecraft/block.ts similarity index 90% rename from src/main/resources/scriptcraft/minecraft/block.ts rename to src/main/js/src/minecraft/block.ts index f60965e..b6e577c 100644 --- a/src/main/resources/scriptcraft/minecraft/block.ts +++ b/src/main/js/src/minecraft/block.ts @@ -89,11 +89,80 @@ export class CustomBlock { * @param hand Hand * @returns Action Result */ - onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) { + onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult { return ActionResult.PASS; } } +/** + * Custom Block Entity + */ +export class CustomBlockEntity { + /** + * World + */ + protected world: World; + /** + * Position + */ + protected pos: Pos; + + /** + * Set Location + * @param world New World + * @param pos New Position + */ + setLocation(world: World, pos: Pos): void { + this.world = world; + this.pos = pos; + } + + /** + * Save Data To Tag + * @param tag Tag + * @returns Tag + */ + toTag(tag: CompoundTag): CompoundTag { + return tag; + } + + /** + * Load Data From Tag + * @param tag Tag + */ + fromTag(tag: CompoundTag): void {} + + /** + * Runs Every Tick + */ + tick(): void {} + + /** + * Get World + * @returns World + */ + getWorld(): World { + return this.world; + } + + /** + * Get Position + * @returns Position + */ + getPos(): Pos { + return this.pos; + } + + /** + * Mark Dirty + */ + markDirty(): void { + if (this.getWorld() != null) { + useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); + } + } +} + /** * Block State */ @@ -144,75 +213,6 @@ export class BlockState { } } -/** - * Custom Block Entity - */ -export class CustomBlockEntity { - /** - * World - */ - protected world: World; - /** - * Position - */ - protected pos: Pos; - - /** - * Set Location - * @param world New World - * @param pos New Position - */ - setLocation(world: World, pos: Pos) { - this.world = world; - this.pos = pos; - } - - /** - * Save Data To Tag - * @param tag Tag - * @returns Tag - */ - toTag(tag: CompoundTag) { - return tag; - } - - /** - * Load Data From Tag - * @param tag Tag - */ - fromTag(tag: CompoundTag) {} - - /** - * Runs Every Tick - */ - tick() {} - - /** - * Get World - * @returns World - */ - getWorld() { - return this.world; - } - - /** - * Get Position - * @returns Position - */ - getPos() { - return this.pos; - } - - /** - * Mark Dirty - */ - markDirty() { - if (this.getWorld() != null) { - useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); - } - } -} - /** * {@link CustomBlock} With {@link CustomBlockEntity} */ @@ -241,7 +241,7 @@ export class BlockRegistry implements SimpleRegistry { this.#blockEntities = []; } - register(id: Identifier, obj: CustomBlock) { + register(id: Identifier, obj: CustomBlock): void { this.#blocks.set(id.toString(), obj); if (obj instanceof CustomBlockWithEntity) { useBridge('Registry.registerBlockWithEntity', id.toString(), obj.settings.createJavaObject()); @@ -271,12 +271,12 @@ export class BlockRegistry implements SimpleRegistry { return this.#blockEntities; } - createCustomBlockEntity(id: Identifier, i: number) { + createCustomBlockEntity(id: Identifier, i: number): void { const block = this.get(id) as CustomBlockWithEntity; - this.#blockEntities[this.#blockEntities.length] = (block.createBlockEntity()); + this.#blockEntities[i] = block.createBlockEntity(); } - freeCustomBlockEntity(i: number) { + freeCustomBlockEntity(i: number): void { delete this.#blockEntities[i]; } } @@ -289,10 +289,9 @@ addBridge('CustomBlockEntity.fromTag', (i: number, tag: JavaObject) => { BlockRegistry.INSTANCE.getCustomBlockEntity(i).fromTag(new CompoundTag(tag)); }); -addBridge('CustomBlockEntity.toTag', ( i: number, tag: JavaObject): JavaObject => { - return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject; - } -); +addBridge('CustomBlockEntity.toTag', (i: number, tag: JavaObject): JavaObject => { + return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject; +}); addBridge('CustomBlockEntity.tick', (i: number) => { BlockRegistry.INSTANCE.getCustomBlockEntity(i).tick(); @@ -303,7 +302,9 @@ addBridge('CustomBlockEntity.setLocation', (i: number, world: JavaObject, x: num }); addBridge('CustomBlockEntity.free', (i: number) => { + console.log('Free: ' + i); BlockRegistry.INSTANCE.freeCustomBlockEntity(i); + console.log('Free After: ' + BlockRegistry.INSTANCE.getCustomBlockEntity(i)); }); addBridge('CustomBlock.onUse', (id: string, world: JavaObject, state: JavaObject, x: number, y: number, z: number, side: keyof typeof Direction, player: JavaObject, hand: keyof typeof Hand): string => { diff --git a/src/main/resources/scriptcraft/minecraft/core.ts b/src/main/js/src/minecraft/core.ts similarity index 100% rename from src/main/resources/scriptcraft/minecraft/core.ts rename to src/main/js/src/minecraft/core.ts diff --git a/src/main/resources/scriptcraft/minecraft/entity.ts b/src/main/js/src/minecraft/entity.ts similarity index 93% rename from src/main/resources/scriptcraft/minecraft/entity.ts rename to src/main/js/src/minecraft/entity.ts index fba13e2..2ef8c9a 100644 --- a/src/main/resources/scriptcraft/minecraft/entity.ts +++ b/src/main/js/src/minecraft/entity.ts @@ -25,7 +25,7 @@ export class DamageSource { */ private static build(bridge: string, value: BridgeValueType): DamageSource { const obj = useBridge(bridge, value) as JavaObject; - if (obj) { + if (obj != null) { return new DamageSource(obj); } else { return null; @@ -89,7 +89,7 @@ export class Entity { */ getEntityWorld(): World { const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject; - if (obj) { + if (obj != null) { return new World(obj); } else { return null; @@ -102,7 +102,7 @@ export class Entity { */ getID(): Identifier { const obj = useBridge('Entity.getID', this.javaObject) as string; - if (obj) { + if (obj != null) { return new Identifier(obj); } else { return null; @@ -143,14 +143,14 @@ export class Entity { /** * Kill Entity */ - kill() { + kill(): void { useBridge('Entity.kill', this.javaObject); } /** * Remove Entity */ - remove() { + remove(): void { useBridge('Entity.remove', this.javaObject); } @@ -158,7 +158,7 @@ export class Entity { * Set Entity Fire Ticks * @param ticks Fire Ticks */ - setFireTicks(ticks: number) { + setFireTicks(ticks: number): void { useBridge('Entity.setFireTicks', this.javaObject, ticks); } @@ -175,7 +175,7 @@ export class Entity { * @param source Damage Source * @param amount Damage Amount */ - damage(source: DamageSource, amount: number) { + damage(source: DamageSource, amount: number): void { useBridge('Entity.damage', source.javaObject, amount); } @@ -185,7 +185,7 @@ export class Entity { */ getPosition(): Pos { const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[]; - if (pos && pos.length === 3) { + if (pos != null && pos.length === 3) { return new Pos(pos[0], pos[1], pos[2]); } else { return null; @@ -196,7 +196,7 @@ export class Entity { * Set Entity Position * @param pos Entity Position */ - setPosition(pos: Pos) { + setPosition(pos: Pos): void { useBridge('Entity.setPosition', this.javaObject, pos.getX(), pos.getY(), pos.getZ()); } @@ -206,7 +206,7 @@ export class Entity { */ toTag(): CompoundTag { const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject; - if (obj) { + if (obj != null) { return new CompoundTag(obj); } else { return null; @@ -217,7 +217,7 @@ export class Entity { * Load Data From {@link CompoundTag} * @param tag Tag */ - fromTag(tag: CompoundTag) { + fromTag(tag: CompoundTag): void { useBridge('Entity.fromTag', this.javaObject, tag.javaObject); } } diff --git a/src/main/resources/scriptcraft/minecraft/index.ts b/src/main/js/src/minecraft/index.ts similarity index 93% rename from src/main/resources/scriptcraft/minecraft/index.ts rename to src/main/js/src/minecraft/index.ts index 9bf931e..c7ad293 100644 --- a/src/main/resources/scriptcraft/minecraft/index.ts +++ b/src/main/js/src/minecraft/index.ts @@ -14,4 +14,4 @@ export { ItemStack, ItemSettings, CustomItem, BlockItem } from './item'; export { World } from './world'; export { LivingEntity, PlayerEntity } from './entity'; export { CompoundTag, ListTag, NumberType } from './tag'; -export { Registry } from './registry'; \ No newline at end of file +export { Registry } from './registry'; diff --git a/src/main/resources/scriptcraft/minecraft/item.ts b/src/main/js/src/minecraft/item.ts similarity index 94% rename from src/main/resources/scriptcraft/minecraft/item.ts rename to src/main/js/src/minecraft/item.ts index e074fb1..2cf7f76 100644 --- a/src/main/resources/scriptcraft/minecraft/item.ts +++ b/src/main/js/src/minecraft/item.ts @@ -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) { + 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) { + if (obj != null) { return new Identifier(obj); } else { return null; @@ -67,7 +67,7 @@ export class ItemStack { * Set Item Count * @param count New Count */ - setCount(count: number) { + setCount(count: number): void { useBridge('ItemStack.setCount', this.javaObject, count); } @@ -83,7 +83,7 @@ export class ItemStack { * Set Item Damage * @param count New Damage */ - setDamage(damage: number) { + setDamage(damage: number): void { useBridge('ItemStack.setDamage', this.javaObject, damage); } @@ -101,7 +101,7 @@ export class ItemStack { */ getTag(): CompoundTag { const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject; - if (obj) { + if (obj != null) { return new CompoundTag(obj); } else { return null; @@ -112,7 +112,7 @@ export class ItemStack { * Set Item Tag * @param tag New Item Tag */ - setTag(tag: CompoundTag) { + setTag(tag: CompoundTag): void { useBridge('ItemStack.setTag', this.javaObject, tag.javaObject); } @@ -122,7 +122,7 @@ export class ItemStack { */ toTag(): CompoundTag { const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject; - if (obj) { + 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) { + if (obj != null) { return new ItemStack(obj); } else { return null; @@ -225,7 +225,7 @@ export class CustomItem { * @param hand Hand * @returns Action Result */ - onUse(world: World, player: PlayerEntity, hand: Hand) { + onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult { return ActionResult.PASS; } @@ -238,7 +238,7 @@ export class CustomItem { * @param hand Hand * @returns Action Result */ - onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) { + onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult { return ActionResult.PASS; } @@ -249,7 +249,7 @@ export class CustomItem { * @param hand Hand * @returns Action Result */ - onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand) { + onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult { return ActionResult.PASS; } } @@ -290,7 +290,7 @@ export class ItemRegistry implements SimpleRegistry { this.#items = new Map(); } - register(id: Identifier, obj: CustomItem | BlockItem) { + register(id: Identifier, obj: CustomItem | BlockItem): void { if (obj instanceof CustomItem) { this.#items.set(id.toString(), obj); useBridge('Registry.registerItem', id.toString(), obj.settings.createJavaObject()); diff --git a/src/main/resources/scriptcraft/minecraft/registry.ts b/src/main/js/src/minecraft/registry.ts similarity index 100% rename from src/main/resources/scriptcraft/minecraft/registry.ts rename to src/main/js/src/minecraft/registry.ts diff --git a/src/main/resources/scriptcraft/minecraft/tag.ts b/src/main/js/src/minecraft/tag.ts similarity index 95% rename from src/main/resources/scriptcraft/minecraft/tag.ts rename to src/main/js/src/minecraft/tag.ts index d160586..797a7ef 100644 --- a/src/main/resources/scriptcraft/minecraft/tag.ts +++ b/src/main/js/src/minecraft/tag.ts @@ -85,7 +85,7 @@ export class CompoundTag { */ set(key: string, value: number, numberType: NumberType): void; set(key: string, value: Exclude): void; - set(key: string, value: TagType, numberType?: NumberType) { + 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); } @@ -103,7 +103,7 @@ export class CompoundTag { */ static create(): CompoundTag { const obj = useBridge('CompoundTag.create') as JavaObject; - if (obj) { + if (obj != null) { return new CompoundTag(obj); } else { return null; @@ -147,7 +147,7 @@ export class ListTag { */ set(key: number, value: number, numberType: NumberType): void; set(key: number, value: Exclude): void; - set(key: number, value: TagType, numberType?: NumberType) { + 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); } @@ -165,7 +165,7 @@ export class ListTag { */ static create(): ListTag { const obj = useBridge('ListTag.create') as JavaObject; - if (obj) { + if (obj != null) { return new ListTag(obj); } else { return null; diff --git a/src/main/resources/scriptcraft/minecraft/world.ts b/src/main/js/src/minecraft/world.ts similarity index 90% rename from src/main/resources/scriptcraft/minecraft/world.ts rename to src/main/js/src/minecraft/world.ts index 5544483..f2a3057 100644 --- a/src/main/resources/scriptcraft/minecraft/world.ts +++ b/src/main/js/src/minecraft/world.ts @@ -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) { + 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) { + if (obj != null) { return new Entity(obj); } else { return null; @@ -63,8 +63,8 @@ export class World { * @returns Custom Block Entity At Position */ getCustomBlockEntity(pos: Pos): CustomBlockEntity { - const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number; - if (obj) { + const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number; + 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) { + if (obj != null) { return new Identifier(obj); } else { return null; diff --git a/src/main/resources/scriptcraft/test/index.ts b/src/main/js/src/test/index.ts similarity index 95% rename from src/main/resources/scriptcraft/test/index.ts rename to src/main/js/src/test/index.ts index f085d9c..4097e7e 100644 --- a/src/main/resources/scriptcraft/test/index.ts +++ b/src/main/js/src/test/index.ts @@ -1,4 +1,4 @@ -import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft'; +import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'src/minecraft/index'; console.log('hello'); @@ -10,7 +10,7 @@ class MyBlockEntity extends CustomBlockEntity { return tag; } - fromTag(tag: CompoundTag) { + fromTag(tag: CompoundTag): void { const obj = tag.get('MyTicks'); if (typeof obj === 'number') { this.ticks = obj; @@ -19,7 +19,7 @@ class MyBlockEntity extends CustomBlockEntity { } } - tick() { + tick(): void { this.ticks++; this.markDirty(); } diff --git a/src/main/resources/scriptcraft/types/scriptcraft/index.d.ts b/src/main/js/src/types/scriptcraft/index.d.ts similarity index 99% rename from src/main/resources/scriptcraft/types/scriptcraft/index.d.ts rename to src/main/js/src/types/scriptcraft/index.d.ts index d1d9a0a..7d7da9a 100644 --- a/src/main/resources/scriptcraft/types/scriptcraft/index.d.ts +++ b/src/main/js/src/types/scriptcraft/index.d.ts @@ -31,4 +31,4 @@ declare module 'scriptcraft-core' { function addBridge(name: string, bridge: BridgeType): void; function useBridge(name: string, ...args: BridgeValueType[]): BridgeValueType; -} \ No newline at end of file +} diff --git a/src/main/resources/scriptcraft/tsconfig.json b/src/main/js/tsconfig.json similarity index 65% rename from src/main/resources/scriptcraft/tsconfig.json rename to src/main/js/tsconfig.json index 9bc5cc0..4f92391 100644 --- a/src/main/resources/scriptcraft/tsconfig.json +++ b/src/main/js/tsconfig.json @@ -7,14 +7,14 @@ "lib": ["es2020"], "module": "es2020", "target": "es2020", - "typeRoots": ["types"], - "rootDir": ".", - "baseUrl": ".", + "typeRoots": ["src/types"], + "rootDir": "src", + "baseUrl": "src", "paths": { - "minecraft": ["minecraft/index"] + "minecraft": ["src/minecraft/index"] } }, "include": [ - "**/*" + "src/**/*.ts" ] } \ No newline at end of file diff --git a/src/main/resources/scriptcraft/typedoc.json b/src/main/js/typedoc.json similarity index 100% rename from src/main/resources/scriptcraft/typedoc.json rename to src/main/js/typedoc.json diff --git a/src/main/resources/scriptcraft/.prettierrc b/src/main/resources/scriptcraft/.prettierrc deleted file mode 100644 index 8624f77..0000000 --- a/src/main/resources/scriptcraft/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "trailingComma": "none", - "tabWidth": 4, - "semi": true, - "singleQuote": true, - "arrowParens": "avoid", - "printWidth": 24000 -} \ No newline at end of file