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

89 lines
2.6 KiB
TypeScript

import { BlockState, CustomBlockEntity, BlockEntity } from './block';
import { Entity } from './entity';
import { Pos, Identifier, JavaObjectWrapper } from './core';
import { useBridge } from 'scriptcraft-core';
/**
* World
*/
export class World extends JavaObjectWrapper {
/**
* Create World Wrapper From Java Object
* @param javaObject Java Object
*/
constructor(javaObject: JavaObject | JavaObjectWrapper) {
super(javaObject);
this.assertValidJavaObject('World');
}
/**
* Set Block State
* @param pos Position
* @param state Block State
* @returns TRUE If Successful, Otherwise FALSE
*/
setBlockState(pos: Pos, state: BlockState): boolean {
return useBridge('World.setBlockState', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ(), state.getJavaObject()) as boolean;
}
/**
* Get Block State
* @param pos Position
* @returns Block State
*/
getBlockState(pos: Pos): BlockState {
const obj = useBridge('World.getBlockState', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
if (obj !== null) {
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.getJavaObject(), pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject;
if (obj !== null) {
return new Entity(obj);
} else {
return null;
}
}
/**
* Get Custom Block Entity At Position
* @param pos Position
* @returns Custom Block Entity At Position
*/
getCustomBlockEntity(pos: Pos): CustomBlockEntity {
const obj = useBridge('World.getCustomBlockEntity', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ()) as number;
if (obj !== null) {
return CustomBlockEntity.getByID(obj);
} else {
return null;
}
}
/**
* Get Block Entity ID At Position
* @param pos Position
* @returns Block Entity ID At Position
*/
getBlockEntity(pos: Pos): BlockEntity {
const obj = useBridge('World.getBlockEntity', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
if (obj !== null) {
return new BlockEntity(obj);
} else {
return null;
}
}
isClient(): boolean {
return useBridge('World.isClient', this.getJavaObject()) as boolean;
}
}