From 473b8c0ba312551cc5f93a175bd810297e98b407 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 27 Apr 2020 14:36:17 -0400 Subject: [PATCH] CustomBlock, CustomBlockWithEntity, and CustomItem are no longer abstract --- .../resources/scriptcraft/minecraft/block.ts | 37 ++++++++++++------- .../resources/scriptcraft/minecraft/core.ts | 4 +- .../resources/scriptcraft/minecraft/entity.ts | 5 +-- .../resources/scriptcraft/minecraft/item.ts | 14 +++++-- .../scriptcraft/minecraft/registry.ts | 4 +- .../resources/scriptcraft/minecraft/tag.ts | 12 +++--- .../resources/scriptcraft/minecraft/world.ts | 2 +- 7 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/main/resources/scriptcraft/minecraft/block.ts b/src/main/resources/scriptcraft/minecraft/block.ts index 67f31ce..f30cd8e 100644 --- a/src/main/resources/scriptcraft/minecraft/block.ts +++ b/src/main/resources/scriptcraft/minecraft/block.ts @@ -68,7 +68,7 @@ export class BlockSettings { /** * Custom Block */ -export abstract class CustomBlock { +export class CustomBlock { /** * @internal */ @@ -88,7 +88,9 @@ export abstract class CustomBlock { * @param hand Hand * @returns Action Result */ - abstract onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult; + onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) { + return ActionResult.PASS; + } } /** @@ -144,7 +146,7 @@ export class BlockState { /** * Custom Block Entity */ -export abstract class CustomBlockEntity { +export class CustomBlockEntity { /** * World */ @@ -169,24 +171,26 @@ export abstract class CustomBlockEntity { * @param tag Tag * @returns Tag */ - abstract toTag(tag: CompoundTag): CompoundTag; + toTag(tag: CompoundTag) { + return tag; + } /** * Load Data From Tag * @param tag Tag */ - abstract fromTag(tag: CompoundTag): void; + fromTag(tag: CompoundTag) {} /** * Runs Every Tick */ - abstract tick(): void; + tick() {} /** * Get World * @returns World */ - getWorld(): World { + getWorld() { return this.world; } @@ -194,7 +198,7 @@ export abstract class CustomBlockEntity { * Get Position * @returns Position */ - getPos(): Pos { + getPos() { return this.pos; } @@ -211,12 +215,14 @@ export abstract class CustomBlockEntity { /** * {@link CustomBlock} With {@link CustomBlockEntity} */ -export abstract class CustomBlockWithEntity extends CustomBlock { +export class CustomBlockWithEntity extends CustomBlock { /** * Create Custom Block Entity * @returns Custom Block Entity */ - abstract createBlockEntity(): CustomBlockEntity; + createBlockEntity(): CustomBlockEntity { + throw new Error('CustomBlockWithEntity.createBlockEntity is not implemented'); + } } /** @@ -290,9 +296,12 @@ addBridge('CustomBlockEntity.fromTag', (id: string, i: number, tag: JavaObject) BlockRegistry.INSTANCE.getCustomBlockEntity(new Identifier(id), i).fromTag(new CompoundTag(tag)); }); -addBridge('CustomBlockEntity.toTag', (id: string, i: number, tag: JavaObject): JavaObject => { - return BlockRegistry.INSTANCE.getCustomBlockEntity(new Identifier(id), i).toTag(new CompoundTag(tag)).javaObject; -}); +addBridge( + 'CustomBlockEntity.toTag', + (id: string, i: number, tag: JavaObject): JavaObject => { + return BlockRegistry.INSTANCE.getCustomBlockEntity(new Identifier(id), i).toTag(new CompoundTag(tag)).javaObject; + } +); addBridge('CustomBlockEntity.tick', (id: string, i: number) => { BlockRegistry.INSTANCE.getCustomBlockEntity(new Identifier(id), i).tick(); @@ -308,4 +317,4 @@ addBridge('CustomBlockEntity.free', (id: string, i: number) => { 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 => { return BlockRegistry.INSTANCE.get(new Identifier(id)).onUse(new World(world), new BlockState(state), new Pos(x, y, z), Direction[side], new PlayerEntity(player), Hand[hand]); -}); \ No newline at end of file +}); diff --git a/src/main/resources/scriptcraft/minecraft/core.ts b/src/main/resources/scriptcraft/minecraft/core.ts index 54ede96..46d32fe 100644 --- a/src/main/resources/scriptcraft/minecraft/core.ts +++ b/src/main/resources/scriptcraft/minecraft/core.ts @@ -108,7 +108,7 @@ export class DirectionUtil { /** * Namespaced Identifier - * + * * Formatted as ":" */ export class Identifier { @@ -302,4 +302,4 @@ export interface SimpleRegistry { * @returns ID */ getID(obj: T): Identifier; -} \ No newline at end of file +} diff --git a/src/main/resources/scriptcraft/minecraft/entity.ts b/src/main/resources/scriptcraft/minecraft/entity.ts index ac47a44..86e5fbd 100644 --- a/src/main/resources/scriptcraft/minecraft/entity.ts +++ b/src/main/resources/scriptcraft/minecraft/entity.ts @@ -71,7 +71,7 @@ export class Entity { /** * @internal */ - constructor(object: JavaObject|Entity) { + constructor(object: JavaObject | Entity) { if (object == null) { return null; } @@ -251,5 +251,4 @@ export class LivingEntity extends Entity { /** * Player Entity */ -export class PlayerEntity extends LivingEntity { -} \ No newline at end of file +export class PlayerEntity extends LivingEntity {} diff --git a/src/main/resources/scriptcraft/minecraft/item.ts b/src/main/resources/scriptcraft/minecraft/item.ts index 2deca3b..34243a6 100644 --- a/src/main/resources/scriptcraft/minecraft/item.ts +++ b/src/main/resources/scriptcraft/minecraft/item.ts @@ -207,7 +207,7 @@ export class ItemSettings { /** * Custom Item */ -export abstract class CustomItem { +export class CustomItem { /** * @internal */ @@ -224,7 +224,9 @@ export abstract class CustomItem { * @param hand Hand * @returns Action Result */ - abstract onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult; + onUse(world: World, player: PlayerEntity, hand: Hand) { + return ActionResult.PASS; + } /** * Called When The Item Is Used On A Block @@ -235,7 +237,9 @@ export abstract class CustomItem { * @param hand Hand * @returns Action Result */ - abstract onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult; + onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) { + return ActionResult.PASS; + } /** * Called When The Item Is Used On An Entity @@ -244,7 +248,9 @@ export abstract class CustomItem { * @param hand Hand * @returns Action Result */ - abstract onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult; + onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand) { + return ActionResult.PASS; + } } /** diff --git a/src/main/resources/scriptcraft/minecraft/registry.ts b/src/main/resources/scriptcraft/minecraft/registry.ts index 27bd258..9f3ceda 100644 --- a/src/main/resources/scriptcraft/minecraft/registry.ts +++ b/src/main/resources/scriptcraft/minecraft/registry.ts @@ -14,7 +14,7 @@ export abstract class Registry { * Item Registry */ static ITEM = ItemRegistry.INSTANCE; - + /** * Register Object * @param registry Target Registry @@ -45,4 +45,4 @@ export abstract class Registry { static getID(registry: SimpleRegistry, obj: T): Identifier { return registry.getID(obj); } -} \ No newline at end of file +} diff --git a/src/main/resources/scriptcraft/minecraft/tag.ts b/src/main/resources/scriptcraft/minecraft/tag.ts index 231c24b..f96d2fe 100644 --- a/src/main/resources/scriptcraft/minecraft/tag.ts +++ b/src/main/resources/scriptcraft/minecraft/tag.ts @@ -1,4 +1,4 @@ -import { useBridge } from "./core"; +import { useBridge } from './core'; type TagType = number | boolean | string | CompoundTag | ListTag; @@ -67,7 +67,7 @@ export class CompoundTag { /** * Get Value In Tag - * + * * Note: This will never return a boolean, because booleans are stored as numbers in NBT. * @param key Key * @returns Value @@ -86,7 +86,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) { - 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); } /** @@ -129,7 +129,7 @@ export class ListTag { /** * Get Value In Tag - * + * * Note: This will never return a boolean, because booleans are stored as numbers in NBT. * @param key Key * @returns Value @@ -148,7 +148,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) { - 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); } /** @@ -171,4 +171,4 @@ export class ListTag { return null; } } -} \ No newline at end of file +} diff --git a/src/main/resources/scriptcraft/minecraft/world.ts b/src/main/resources/scriptcraft/minecraft/world.ts index 4f9c1f5..4d5341c 100644 --- a/src/main/resources/scriptcraft/minecraft/world.ts +++ b/src/main/resources/scriptcraft/minecraft/world.ts @@ -91,4 +91,4 @@ export class World { return null; } } -} \ No newline at end of file +}