94 lines
2.4 KiB
TypeScript
94 lines
2.4 KiB
TypeScript
import { BlockState, CustomBlockEntity, BlockRegistry } from './block';
|
|
import { Entity } from './entity';
|
|
import { useBridge, Pos, Identifier } from './core';
|
|
|
|
/**
|
|
* World
|
|
*/
|
|
export class World {
|
|
/**
|
|
* @internal
|
|
*/
|
|
readonly javaObject: JavaObject;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
constructor(javaObject: JavaObject) {
|
|
this.javaObject = javaObject;
|
|
}
|
|
|
|
/**
|
|
* Set Block State
|
|
* @param pos Position
|
|
* @param state Block State
|
|
* @returns True If Successful
|
|
*/
|
|
setBlockState(pos: Pos, state: BlockState): boolean {
|
|
return useBridge('World.setBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), state.javaObject) as boolean;
|
|
}
|
|
|
|
/**
|
|
* Get Block State
|
|
* @param pos Position
|
|
* @returns Block State
|
|
*/
|
|
getBlockState(pos: Pos): BlockState {
|
|
const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
|
|
if (obj) {
|
|
return new BlockState(obj);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Spawn Entity
|
|
* @param id Entity ID
|
|
* @param pos Position
|
|
*/
|
|
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) {
|
|
return new Entity(obj);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
private getCustomBlockEntities(): CustomBlockEntity[] {
|
|
return BlockRegistry.INSTANCE.getCustomBlockEntities();
|
|
}
|
|
|
|
/**
|
|
* Get Custom Block Entity At Position
|
|
* @param pos Position
|
|
* @returns Custom Block Entity At Position
|
|
*/
|
|
getCustomBlockEntity(pos: Pos): CustomBlockEntity {
|
|
const list = this.getCustomBlockEntities();
|
|
for (const entity of list) {
|
|
if (pos.equals(entity.getPos())) {
|
|
return entity;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get Block Entity ID At Position
|
|
* @param pos Position
|
|
* @returns Block Entity ID At Position
|
|
*/
|
|
getBlockEntity(pos: Pos): Identifier {
|
|
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
|
|
if (obj) {
|
|
return new Identifier(obj);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
} |