Use ESLint
All checks were successful
ScriptCraft/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-04-27 22:30:12 -04:00
parent aa8e3f5e2b
commit bc7dc8d5c2
22 changed files with 199 additions and 155 deletions

View File

@ -30,5 +30,3 @@ RUN curl -sL https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key a
apt-get install --no-install-recommends -y cmake apt-get install --no-install-recommends -y cmake
RUN apt-get clean RUN apt-get clean
RUN npm install -g typescript typedoc

View File

@ -92,9 +92,8 @@ sourceSets {
} }
} }
def typescriptRoot = rootProject.typescript_root as String def typescriptRoot = 'src/main/js'
def resources = new File(rootProject.rootDir, 'src/main/resources') def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
def typescriptRootFile = new File(resources, typescriptRoot)
task typescript(group: 'build') { task typescript(group: 'build') {
inputs.dir typescriptRootFile inputs.dir typescriptRootFile
@ -107,14 +106,24 @@ task typescript(group: 'build') {
typescriptOut.mkdirs() typescriptOut.mkdirs()
project.exec { project.exec {
executable 'tsc' workingDir typescriptRootFile
args '--outDir', new File(typescriptOut, typescriptRoot).absolutePath executable 'npm'
args '--project', typescriptRootFile.absolutePath
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 processResources.dependsOn typescript
def typedocOut = new File(buildDir, 'typedoc') def typedocOut = new File(buildDir, 'typedoc')
@ -131,8 +140,10 @@ task typedoc(group: 'documentation') {
project.exec { project.exec {
workingDir typescriptRootFile workingDir typescriptRootFile
executable 'typedoc'
executable 'npm'
args 'run', 'typedoc', '--'
args '--out', typedocOut.absolutePath args '--out', typedocOut.absolutePath
} }
} }
@ -151,9 +162,6 @@ processResources {
exclude 'fabric.mod.json' exclude 'fabric.mod.json'
} }
exclude typescriptRoot + '/**/*.ts'
exclude typescriptRoot + '/types'
for (JNIPlatform platform : jniPlatforms) { for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}") def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) { if (!buildDir.exists()) {

View File

@ -1,8 +1,6 @@
# Done to increase the memory available to gradle. # Done to increase the memory available to gradle.
org.gradle.jvmargs = -Xmx1G org.gradle.jvmargs = -Xmx1G
typescript_root = scriptcraft
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version = 1.15.2 minecraft_version = 1.15.2

View File

@ -4,3 +4,6 @@ set -e
./download-quickjs.sh ./download-quickjs.sh
./download-jni-headers.sh ./download-jni-headers.sh
cd ../src/main/js
npm install

View File

@ -12,22 +12,22 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable { 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) { public CustomBlockEntity(BlockEntityType<?> type, Identifier id) {
super(type); super(type);
objID = newObjID++; objID = newObjID++;
QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), (double) objID); QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), objID);
} }
@Override @Override
public void fromTag(CompoundTag tag) { public void fromTag(CompoundTag tag) {
super.fromTag(tag); super.fromTag(tag);
QuickJSManager.bridge("CustomBlockEntity.fromTag", (double) objID, tag); QuickJSManager.bridge("CustomBlockEntity.fromTag", objID, tag);
} }
@Override @Override
@ -37,7 +37,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
@Override @Override
public CompoundTag toTag(CompoundTag tag) { 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 @Override
@ -47,20 +47,20 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
@Override @Override
public void tick() { public void tick() {
QuickJSManager.bridge("CustomBlockEntity.tick", (double) objID); QuickJSManager.bridge("CustomBlockEntity.tick", objID);
} }
@Override @Override
public void setLocation(World world, BlockPos pos) { public void setLocation(World world, BlockPos pos) {
super.setLocation(world, 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") @SuppressWarnings("deprecation")
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
QuickJSManager.bridge("CustomBlockEntity.free", (double) objID); QuickJSManager.bridge("CustomBlockEntity.free", objID);
} finally { } finally {
super.finalize(); super.finalize();
} }
@ -74,7 +74,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
} }
} }
public long getObjID() { public double getObjID() {
return objID; return objID;
} }
} }

View File

@ -1,7 +1,5 @@
package com.thebrokenrail.scriptcraft.api.block; 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.BlockEntityProvider;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;

View File

@ -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"]
}
}

2
src/main/js/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
package-lock.json

15
src/main/js/package.json Normal file
View File

@ -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"
}
}

View File

@ -89,11 +89,80 @@ export class CustomBlock {
* @param hand Hand * @param hand Hand
* @returns Action Result * @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; 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 * 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} * {@link CustomBlock} With {@link CustomBlockEntity}
*/ */
@ -241,7 +241,7 @@ export class BlockRegistry implements SimpleRegistry<CustomBlock> {
this.#blockEntities = []; this.#blockEntities = [];
} }
register(id: Identifier, obj: CustomBlock) { register(id: Identifier, obj: CustomBlock): void {
this.#blocks.set(id.toString(), obj); this.#blocks.set(id.toString(), obj);
if (obj instanceof CustomBlockWithEntity) { if (obj instanceof CustomBlockWithEntity) {
useBridge('Registry.registerBlockWithEntity', id.toString(), obj.settings.createJavaObject()); useBridge('Registry.registerBlockWithEntity', id.toString(), obj.settings.createJavaObject());
@ -271,12 +271,12 @@ export class BlockRegistry implements SimpleRegistry<CustomBlock> {
return this.#blockEntities; return this.#blockEntities;
} }
createCustomBlockEntity(id: Identifier, i: number) { createCustomBlockEntity(id: Identifier, i: number): void {
const block = this.get(id) as CustomBlockWithEntity; 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]; delete this.#blockEntities[i];
} }
} }
@ -289,10 +289,9 @@ addBridge('CustomBlockEntity.fromTag', (i: number, tag: JavaObject) => {
BlockRegistry.INSTANCE.getCustomBlockEntity(i).fromTag(new CompoundTag(tag)); BlockRegistry.INSTANCE.getCustomBlockEntity(i).fromTag(new CompoundTag(tag));
}); });
addBridge('CustomBlockEntity.toTag', ( i: number, tag: JavaObject): JavaObject => { addBridge('CustomBlockEntity.toTag', (i: number, tag: JavaObject): JavaObject => {
return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject; return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject;
} });
);
addBridge('CustomBlockEntity.tick', (i: number) => { addBridge('CustomBlockEntity.tick', (i: number) => {
BlockRegistry.INSTANCE.getCustomBlockEntity(i).tick(); BlockRegistry.INSTANCE.getCustomBlockEntity(i).tick();
@ -303,7 +302,9 @@ addBridge('CustomBlockEntity.setLocation', (i: number, world: JavaObject, x: num
}); });
addBridge('CustomBlockEntity.free', (i: number) => { addBridge('CustomBlockEntity.free', (i: number) => {
console.log('Free: ' + i);
BlockRegistry.INSTANCE.freeCustomBlockEntity(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 => { 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 => {

View File

@ -25,7 +25,7 @@ export class DamageSource {
*/ */
private static build(bridge: string, value: BridgeValueType): DamageSource { private static build(bridge: string, value: BridgeValueType): DamageSource {
const obj = useBridge(bridge, value) as JavaObject; const obj = useBridge(bridge, value) as JavaObject;
if (obj) { if (obj != null) {
return new DamageSource(obj); return new DamageSource(obj);
} else { } else {
return null; return null;
@ -89,7 +89,7 @@ export class Entity {
*/ */
getEntityWorld(): World { getEntityWorld(): World {
const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject; const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject;
if (obj) { if (obj != null) {
return new World(obj); return new World(obj);
} else { } else {
return null; return null;
@ -102,7 +102,7 @@ export class Entity {
*/ */
getID(): Identifier { getID(): Identifier {
const obj = useBridge('Entity.getID', this.javaObject) as string; const obj = useBridge('Entity.getID', this.javaObject) as string;
if (obj) { if (obj != null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;
@ -143,14 +143,14 @@ export class Entity {
/** /**
* Kill Entity * Kill Entity
*/ */
kill() { kill(): void {
useBridge('Entity.kill', this.javaObject); useBridge('Entity.kill', this.javaObject);
} }
/** /**
* Remove Entity * Remove Entity
*/ */
remove() { remove(): void {
useBridge('Entity.remove', this.javaObject); useBridge('Entity.remove', this.javaObject);
} }
@ -158,7 +158,7 @@ export class Entity {
* Set Entity Fire Ticks * Set Entity Fire Ticks
* @param ticks Fire Ticks * @param ticks Fire Ticks
*/ */
setFireTicks(ticks: number) { setFireTicks(ticks: number): void {
useBridge('Entity.setFireTicks', this.javaObject, ticks); useBridge('Entity.setFireTicks', this.javaObject, ticks);
} }
@ -175,7 +175,7 @@ export class Entity {
* @param source Damage Source * @param source Damage Source
* @param amount Damage Amount * @param amount Damage Amount
*/ */
damage(source: DamageSource, amount: number) { damage(source: DamageSource, amount: number): void {
useBridge('Entity.damage', source.javaObject, amount); useBridge('Entity.damage', source.javaObject, amount);
} }
@ -185,7 +185,7 @@ export class Entity {
*/ */
getPosition(): Pos { getPosition(): Pos {
const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[]; 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]); return new Pos(pos[0], pos[1], pos[2]);
} else { } else {
return null; return null;
@ -196,7 +196,7 @@ export class Entity {
* Set Entity Position * Set Entity Position
* @param pos Entity Position * @param pos Entity Position
*/ */
setPosition(pos: Pos) { setPosition(pos: Pos): void {
useBridge('Entity.setPosition', this.javaObject, pos.getX(), pos.getY(), pos.getZ()); useBridge('Entity.setPosition', this.javaObject, pos.getX(), pos.getY(), pos.getZ());
} }
@ -206,7 +206,7 @@ export class Entity {
*/ */
toTag(): CompoundTag { toTag(): CompoundTag {
const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject; const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject;
if (obj) { if (obj != null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -217,7 +217,7 @@ export class Entity {
* Load Data From {@link CompoundTag} * Load Data From {@link CompoundTag}
* @param tag Tag * @param tag Tag
*/ */
fromTag(tag: CompoundTag) { fromTag(tag: CompoundTag): void {
useBridge('Entity.fromTag', this.javaObject, tag.javaObject); useBridge('Entity.fromTag', this.javaObject, tag.javaObject);
} }
} }

View File

@ -27,7 +27,7 @@ export class ItemStack {
*/ */
static create(item: Identifier, count?: number): ItemStack { static create(item: Identifier, count?: number): ItemStack {
const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject; const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject;
if (obj) { if (obj != null) {
return new ItemStack(obj); return new ItemStack(obj);
} else { } else {
return null; return null;
@ -40,7 +40,7 @@ export class ItemStack {
*/ */
getItem(): Identifier { getItem(): Identifier {
const obj = useBridge('ItemStack.getItem', this.javaObject) as string; const obj = useBridge('ItemStack.getItem', this.javaObject) as string;
if (obj) { if (obj != null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;
@ -67,7 +67,7 @@ export class ItemStack {
* Set Item Count * Set Item Count
* @param count New Count * @param count New Count
*/ */
setCount(count: number) { setCount(count: number): void {
useBridge('ItemStack.setCount', this.javaObject, count); useBridge('ItemStack.setCount', this.javaObject, count);
} }
@ -83,7 +83,7 @@ export class ItemStack {
* Set Item Damage * Set Item Damage
* @param count New Damage * @param count New Damage
*/ */
setDamage(damage: number) { setDamage(damage: number): void {
useBridge('ItemStack.setDamage', this.javaObject, damage); useBridge('ItemStack.setDamage', this.javaObject, damage);
} }
@ -101,7 +101,7 @@ export class ItemStack {
*/ */
getTag(): CompoundTag { getTag(): CompoundTag {
const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject; const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject;
if (obj) { if (obj != null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -112,7 +112,7 @@ export class ItemStack {
* Set Item Tag * Set Item Tag
* @param tag New Item Tag * @param tag New Item Tag
*/ */
setTag(tag: CompoundTag) { setTag(tag: CompoundTag): void {
useBridge('ItemStack.setTag', this.javaObject, tag.javaObject); useBridge('ItemStack.setTag', this.javaObject, tag.javaObject);
} }
@ -122,7 +122,7 @@ export class ItemStack {
*/ */
toTag(): CompoundTag { toTag(): CompoundTag {
const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject; const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject;
if (obj) { if (obj != null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -136,7 +136,7 @@ export class ItemStack {
*/ */
static fromTag(tag: CompoundTag): ItemStack { static fromTag(tag: CompoundTag): ItemStack {
const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject; const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject;
if (obj) { if (obj != null) {
return new ItemStack(obj); return new ItemStack(obj);
} else { } else {
return null; return null;
@ -225,7 +225,7 @@ export class CustomItem {
* @param hand Hand * @param hand Hand
* @returns Action Result * @returns Action Result
*/ */
onUse(world: World, player: PlayerEntity, hand: Hand) { onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult {
return ActionResult.PASS; return ActionResult.PASS;
} }
@ -238,7 +238,7 @@ export class CustomItem {
* @param hand Hand * @param hand Hand
* @returns Action Result * @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; return ActionResult.PASS;
} }
@ -249,7 +249,7 @@ export class CustomItem {
* @param hand Hand * @param hand Hand
* @returns Action Result * @returns Action Result
*/ */
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand) { onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult {
return ActionResult.PASS; return ActionResult.PASS;
} }
} }
@ -290,7 +290,7 @@ export class ItemRegistry implements SimpleRegistry<CustomItem | BlockItem> {
this.#items = new Map<string, CustomItem>(); this.#items = new Map<string, CustomItem>();
} }
register(id: Identifier, obj: CustomItem | BlockItem) { register(id: Identifier, obj: CustomItem | BlockItem): void {
if (obj instanceof CustomItem) { if (obj instanceof CustomItem) {
this.#items.set(id.toString(), obj); this.#items.set(id.toString(), obj);
useBridge('Registry.registerItem', id.toString(), obj.settings.createJavaObject()); useBridge('Registry.registerItem', id.toString(), obj.settings.createJavaObject());

View File

@ -85,7 +85,7 @@ export class CompoundTag {
*/ */
set(key: string, value: number, numberType: NumberType): void; set(key: string, value: number, numberType: NumberType): void;
set(key: string, value: Exclude<TagType, number>): void; set(key: string, value: Exclude<TagType, number>): 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); 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 { static create(): CompoundTag {
const obj = useBridge('CompoundTag.create') as JavaObject; const obj = useBridge('CompoundTag.create') as JavaObject;
if (obj) { if (obj != null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -147,7 +147,7 @@ export class ListTag {
*/ */
set(key: number, value: number, numberType: NumberType): void; set(key: number, value: number, numberType: NumberType): void;
set(key: number, value: Exclude<TagType, number>): void; set(key: number, value: Exclude<TagType, number>): 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); 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 { static create(): ListTag {
const obj = useBridge('ListTag.create') as JavaObject; const obj = useBridge('ListTag.create') as JavaObject;
if (obj) { if (obj != null) {
return new ListTag(obj); return new ListTag(obj);
} else { } else {
return null; return null;

View File

@ -36,7 +36,7 @@ export class World {
*/ */
getBlockState(pos: Pos): BlockState { getBlockState(pos: Pos): BlockState {
const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject; const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
if (obj) { if (obj != null) {
return new BlockState(obj); return new BlockState(obj);
} else { } else {
return null; return null;
@ -50,7 +50,7 @@ export class World {
*/ */
spawnEntity(id: Identifier, pos: Pos): Entity { spawnEntity(id: Identifier, pos: Pos): Entity {
const obj = useBridge('World.spawnEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject; 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); return new Entity(obj);
} else { } else {
return null; return null;
@ -63,8 +63,8 @@ export class World {
* @returns Custom Block Entity At Position * @returns Custom Block Entity At Position
*/ */
getCustomBlockEntity(pos: Pos): CustomBlockEntity { getCustomBlockEntity(pos: Pos): CustomBlockEntity {
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number; const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
if (obj) { if (obj != null) {
return BlockRegistry.INSTANCE.getCustomBlockEntity(obj); return BlockRegistry.INSTANCE.getCustomBlockEntity(obj);
} else { } else {
return null; return null;
@ -78,7 +78,7 @@ export class World {
*/ */
getBlockEntity(pos: Pos): Identifier { getBlockEntity(pos: Pos): Identifier {
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string; const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
if (obj) { if (obj != null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;

View File

@ -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'); console.log('hello');
@ -10,7 +10,7 @@ class MyBlockEntity extends CustomBlockEntity {
return tag; return tag;
} }
fromTag(tag: CompoundTag) { fromTag(tag: CompoundTag): void {
const obj = tag.get('MyTicks'); const obj = tag.get('MyTicks');
if (typeof obj === 'number') { if (typeof obj === 'number') {
this.ticks = obj; this.ticks = obj;
@ -19,7 +19,7 @@ class MyBlockEntity extends CustomBlockEntity {
} }
} }
tick() { tick(): void {
this.ticks++; this.ticks++;
this.markDirty(); this.markDirty();
} }

View File

@ -7,14 +7,14 @@
"lib": ["es2020"], "lib": ["es2020"],
"module": "es2020", "module": "es2020",
"target": "es2020", "target": "es2020",
"typeRoots": ["types"], "typeRoots": ["src/types"],
"rootDir": ".", "rootDir": "src",
"baseUrl": ".", "baseUrl": "src",
"paths": { "paths": {
"minecraft": ["minecraft/index"] "minecraft": ["src/minecraft/index"]
} }
}, },
"include": [ "include": [
"**/*" "src/**/*.ts"
] ]
} }

View File

@ -1,8 +0,0 @@
{
"trailingComma": "none",
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 24000
}