81 lines
2.1 KiB
TypeScript
81 lines
2.1 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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get All Custom Block Entities
|
|
* @returns All Custom Block Entities
|
|
*/
|
|
getCustomBlockEntities(): CustomBlockEntity[] {
|
|
return BlockRegistry.INSTANCE.getBlockEntities();
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
} |