This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/src/main/resources/scriptcraft/minecraft/world.ts

94 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-04-26 17:23:16 +00:00
import { BlockState, CustomBlockEntity, BlockRegistry } from './block';
2020-04-25 13:33:17 +00:00
import { Entity } from './entity';
import { useBridge, Pos, Identifier } from './core';
/**
* World
*/
export class World {
/**
* @internal
*/
2020-04-26 01:17:59 +00:00
readonly javaObject: JavaObject;
2020-04-25 13:33:17 +00:00
/**
* @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;
}
}
2020-04-26 17:23:16 +00:00
/**
2020-04-26 22:07:01 +00:00
* @internal
2020-04-26 17:23:16 +00:00
*/
2020-04-26 22:07:01 +00:00
private getCustomBlockEntities(): CustomBlockEntity[] {
2020-04-27 18:22:07 +00:00
return BlockRegistry.INSTANCE.getCustomBlockEntities();
2020-04-26 17:23:16 +00:00
}
/**
* 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;
}
2020-04-26 22:07:01 +00:00
/**
* 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;
}
}
2020-04-25 13:33:17 +00:00
}