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/scriptcraft/src/main/ts/src/minecraft/world.ts

92 lines
2.5 KiB
TypeScript
Raw Normal View History

2020-04-28 20:18:22 +00:00
import { BlockState, CustomBlockEntity, BlockRegistry, BlockEntity } from './block';
2020-04-25 13:33:17 +00:00
import { Entity } from './entity';
2020-04-28 00:15:24 +00:00
import { Pos, Identifier } from './core';
import { useBridge } from 'scriptcraft-core';
2020-04-25 13:33:17 +00:00
/**
* 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
2020-04-27 20:22:28 +00:00
* @returns TRUE If Successful, Otherwise FALSE
2020-04-25 13:33:17 +00:00
*/
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;
2020-04-28 14:16:47 +00:00
if (obj !== null) {
2020-04-25 13:33:17 +00:00
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;
2020-04-28 14:16:47 +00:00
if (obj !== null) {
2020-04-25 13:33:17 +00:00
return new Entity(obj);
} else {
return null;
}
}
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 {
2020-04-28 02:30:12 +00:00
const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
2020-04-28 14:16:47 +00:00
if (obj !== null) {
2020-04-28 00:15:24 +00:00
return BlockRegistry.INSTANCE.getCustomBlockEntity(obj);
} else {
return null;
2020-04-26 17:23:16 +00:00
}
}
2020-04-26 22:07:01 +00:00
/**
* Get Block Entity ID At Position
* @param pos Position
* @returns Block Entity ID At Position
*/
2020-04-28 20:18:22 +00:00
getBlockEntity(pos: Pos): BlockEntity {
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
2020-04-28 14:16:47 +00:00
if (obj !== null) {
2020-04-28 20:18:22 +00:00
return new BlockEntity(obj);
2020-04-26 22:07:01 +00:00
} else {
return null;
}
}
2020-04-28 20:18:22 +00:00
isClient(): boolean {
return useBridge('World.isClient', this.javaObject) as boolean;
}
}