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
Raw Normal View History

2020-08-26 21:52:17 +00:00
import { BlockState, CustomBlockEntity, BlockEntity } from './block';
2020-04-25 13:33:17 +00:00
import { Entity } from './entity';
2020-06-02 17:24:32 +00:00
import { Pos, Identifier, JavaObjectWrapper } from './core';
2020-04-28 00:15:24 +00:00
import { useBridge } from 'scriptcraft-core';
2020-04-25 13:33:17 +00:00
/**
* World
*/
2020-06-02 17:24:32 +00:00
export class World extends JavaObjectWrapper {
2020-04-25 13:33:17 +00:00
/**
2020-06-02 17:24:32 +00:00
* Create World Wrapper From Java Object
* @param javaObject Java Object
2020-04-25 13:33:17 +00:00
*/
2020-06-02 17:24:32 +00:00
constructor(javaObject: JavaObject | JavaObjectWrapper) {
super(javaObject);
this.assertValidJavaObject('World');
2020-04-25 13:33:17 +00:00
}
/**
* 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 {
2020-06-02 17:24:32 +00:00
return useBridge('World.setBlockState', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ(), state.getJavaObject()) as boolean;
2020-04-25 13:33:17 +00:00
}
/**
* Get Block State
* @param pos Position
* @returns Block State
*/
getBlockState(pos: Pos): BlockState {
2020-06-02 17:24:32 +00:00
const obj = useBridge('World.getBlockState', this.getJavaObject(), 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 {
2020-06-02 17:24:32 +00:00
const obj = useBridge('World.spawnEntity', this.getJavaObject(), 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-06-02 17:24:32 +00:00
const obj = useBridge('World.getCustomBlockEntity', this.getJavaObject(), pos.getX(), pos.getY(), pos.getZ()) as number;
2020-04-28 14:16:47 +00:00
if (obj !== null) {
2020-08-26 21:52:17 +00:00
return CustomBlockEntity.getByID(obj);
2020-04-28 00:15:24 +00:00
} 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 {
2020-06-02 17:24:32 +00:00
const obj = useBridge('World.getBlockEntity', this.getJavaObject(), 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 {
2020-06-02 17:24:32 +00:00
return useBridge('World.isClient', this.getJavaObject()) as boolean;
2020-04-28 20:18:22 +00:00
}
}