CustomBlock, CustomBlockWithEntity, and CustomItem are no longer abstract
All checks were successful
ScriptCraft/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-04-27 14:36:17 -04:00
parent 05f7d5923c
commit 473b8c0ba3
7 changed files with 46 additions and 32 deletions

View File

@ -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]);
});
});

View File

@ -108,7 +108,7 @@ export class DirectionUtil {
/**
* Namespaced Identifier
*
*
* Formatted as "<namespace>:<path>"
*/
export class Identifier {
@ -302,4 +302,4 @@ export interface SimpleRegistry<T> {
* @returns ID
*/
getID(obj: T): Identifier;
}
}

View File

@ -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 {
}
export class PlayerEntity extends LivingEntity {}

View File

@ -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;
}
}
/**

View File

@ -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<T>(registry: SimpleRegistry<T>, obj: T): Identifier {
return registry.getID(obj);
}
}
}

View File

@ -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<TagType, number>): 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<TagType, number>): 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;
}
}
}
}

View File

@ -91,4 +91,4 @@ export class World {
return null;
}
}
}
}