Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Implement MobSpawnEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjlintkh committed Apr 30, 2022
1 parent 711b878 commit 4af207a
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 319 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
## BDSX-LLSE: Load LiteLoader ScriptingEngine JS plugins in BDSX!

#### Background
Both LiteLoader ScriptingEngine (LLSE) and Bedrock Dedicated Server eXtended (BDSX) are popular options of loading different kinds of plugins currently. However, JS plugins designed for LXL cannot be loaded in BDSX and they need a lot of extra work to port to BDSX. This plugin aims to reduce the work and allow users to load some of the LXL JS plugins with BDSX.
Both LiteLoader ScriptingEngine (LLSE) and Bedrock Dedicated Server eXtended (BDSX) are popular options of loading different kinds of plugins currently. However, JS plugins designed for LLSE cannot be loaded in BDSX and they need a lot of extra work to port to BDSX. This plugin aims to reduce the work and allow users to load some of the LLSE JS plugins with BDSX.

#### Features
We aim to be consistent with the features of LXL, even with the bugs it has. However, there are some features that we could not implement at the time.
We aim to be consistent with the features of LLSE, even with the bugs it has. However, there are some features that we could not implement at the time.

- Supported APIs:
- Scripting
- [x] [💼 Helpers](https://lxl.litebds.com/#/zh_CN/Development/ScriptAPI/ScriptHelp)
- [x] [📅 Logger](https://lxl.litebds.com/#/zh_CN/Development/ScriptAPI/Logger)
- [x] [💡 LXL](https://lxl.litebds.com/#/zh_CN/Development/ScriptAPI/Lxl)
- [x] [💡 LL](https://lxl.litebds.com/#/zh_CN/Development/ScriptAPI/Ll)
- [ ] [💡 I18n](https://lxl.litebds.com/#/zh_CN/Development/ScriptAPI/i18n)
- Game
- [x] [🎨 Basic](https://lxl.litebds.com/#/zh_CN/Development/GameAPI/Basic)
Expand Down Expand Up @@ -68,7 +68,7 @@ We aim to be consistent with the features of LXL, even with the bugs it has. How
- Scripts that pass through `TSC` may throw errors with different position rather than the position of the original code.
- Logging to file is not yet implemented and some colors and formats are not same as LXL's.
- This plugin does not load any plugins written in Lua, the closet approach we tried was using `glua`, but it does not support `GOTO` syntax yet.
- There is no auto-update system currently, but you can run `npm i` to update it if this project got onto it.
- There is no auto-update system currently.

- Tested Plugins:
- [x] [BDSLM - 基岩版卫星地图](https://www.minebbs.com/resources/bdslm.3484/)
Expand Down Expand Up @@ -98,15 +98,15 @@ We aim to be consistent with the features of LXL, even with the bugs it has. How

#### Usage
1. Download `bdsx-lxl.zip` from the [latest release](https://github.com/Rjlintkh/bdsx-lxl/releases/latest) and extract it to `your_bdsx_folder/plugins` so that there is a folder named `your_bdsx_folder/plugins/bdsx-lxl`.
2. Create a folder `your_bdsx_folder/bedrock_server/plugins` and put all the LXL `.js` plugins inside.
2. Create a folder `your_bdsx_folder/bedrock_server/plugins` and put all the LLSE `.js` plugins inside.
OR
Copy all content or create a junction from `your_lxl_folder/plugins` to `your_bdsx_folder/bedrock_server/plugins` if you have previously worked on LXL.
Copy all content or create a junction from `your_llse_folder/plugins` to `your_bdsx_folder/bedrock_server/plugins` if you have previously worked on LLSE.
1. Start the server from `your_bdsx_folder/bdsx.bat`.

#### Disclaimers
- In order to use this project, you must follow the terms of EULA and LXL.
- This project is not affiliated to LXL, but it imitates the functionalities of LXL. No code is directly copied, but the logic of codes are kept for the purpose of loading plugins.
- We do not offer guarantee of successfully loading any LXL plugins.
- In order to use this project, you must follow the terms of EULA and LLSE.
- This project is not affiliated to LLSE, but it imitates the functionalities of LLSE. No code is directly copied, but the logic of codes are kept for the purpose of loading plugins.
- We do not offer guarantee of successfully loading any LLSE plugins.
- The project is experimental, it may contain bugs, bugs found in loading the plugins using this loader should not be reported to their according developers.
- We will not hold any responsibiliy for any corruptions of server. Use it at your own risk.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bdsx/bdsx-llse",
"version": "1.2.1",
"version": "1.2.2",
"description": "LiteLoader ScriptingEngine ported into BDSX",
"main": "index.js",
"keywords": [],
Expand Down
24 changes: 12 additions & 12 deletions src/api/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FloatPos, IntPos, IntPos$newPos } from "./base";
import { BlockEntity$newBlockEntity } from "./block_entity";
import { NbtCompound } from "./nbt";

export class LXL_Block {
export class LLSE_Block {
[PrivateFields]: Block;

getRawPtr() {
Expand Down Expand Up @@ -72,12 +72,12 @@ export class LXL_Block {
}
}

export function Block$newBlock(p: Block, pos: BlockPos, dim: number): LXL_Block;
export function Block$newBlock(p: Block, pos: BlockPos, bs: BlockSource): LXL_Block;
export function Block$newBlock(pos: BlockPos, dim: number): LXL_Block;
export function Block$newBlock(p: Block, pos: BlockPos, dim: number): LLSE_Block;
export function Block$newBlock(p: Block, pos: BlockPos, bs: BlockSource): LLSE_Block;
export function Block$newBlock(pos: BlockPos, dim: number): LLSE_Block;
// export function Block$newBlock(pos: IntVec4): Block;
export function Block$newBlock(a0: any, a1: any, a2?: any): LXL_Block {
const newp = new LXL_Block();
export function Block$newBlock(a0: any, a1: any, a2?: any): LLSE_Block {
const newp = new LLSE_Block();
let p: Block | undefined = undefined!;
let pos: BlockPos | undefined = void 0;
let dim: number | undefined = undefined!;
Expand All @@ -103,8 +103,8 @@ export function Block$newBlock(a0: any, a1: any, a2?: any): LXL_Block {
return newp;
}

export function getBlock(pos: IntPos| FloatPos): LXL_Block;
export function getBlock(x: number, y: number, z: number, dimid: DimensionId): LXL_Block;
export function getBlock(pos: IntPos| FloatPos): LLSE_Block;
export function getBlock(x: number, y: number, z: number, dimid: DimensionId): LLSE_Block;
export function getBlock(a0: any, a1?: any, a2?: any, a3?: any) {
let pos: BlockPos;
let dimId: DimensionId;
Expand All @@ -118,12 +118,12 @@ export function getBlock(a0: any, a1?: any, a2?: any, a3?: any) {
return Block$newBlock(pos, dimId);
}

export function setBlock(pos: IntPos| FloatPos, block: LXL_Block | string | NbtCompound, tiledata?: number): boolean;
export function setBlock(x: number, y: number, z: number, dimid: DimensionId, block: LXL_Block | string | NbtCompound, tiledata: number): boolean;
export function setBlock(pos: IntPos| FloatPos, block: LLSE_Block | string | NbtCompound, tiledata?: number): boolean;
export function setBlock(x: number, y: number, z: number, dimid: DimensionId, block: LLSE_Block | string | NbtCompound, tiledata: number): boolean;
export function setBlock(a0: any, a1: any, a2?: any, a3?: any, a4?: any, a5?: any) {
let pos: BlockPos;
let dimId: DimensionId;
let block: LXL_Block | string | NbtCompound;
let block: LLSE_Block | string | NbtCompound;
let tileData = 0;
if (a0 instanceof IntPos || a0 instanceof FloatPos) {
if (typeof a2 === "number") {
Expand All @@ -146,7 +146,7 @@ export function setBlock(a0: any, a1: any, a2?: any, a3?: any, a4?: any, a5?: an
if (!newBlock) {
return false;
}
} else if (block instanceof LXL_Block) {
} else if (block instanceof LLSE_Block) {
newBlock = block[PrivateFields];
} else if (block instanceof NbtCompound) {
newBlock = Block.create("minecraft:stone")!;
Expand Down
6 changes: 3 additions & 3 deletions src/api/block_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IntPos, IntPos$newPos } from "./base";
import { Block$newBlock } from "./block";
import { NbtCompound } from "./nbt";

export class LXL_BlockEntity {
export class LLSE_BlockEntity {
[PrivateFields]: BlockActor;

getRawPtr() {
Expand All @@ -31,8 +31,8 @@ export class LXL_BlockEntity {
}
}

export function BlockEntity$newBlockEntity(be: BlockActor, dim: DimensionId): LXL_BlockEntity {
const newp = new LXL_BlockEntity();
export function BlockEntity$newBlockEntity(be: BlockActor, dim: DimensionId): LLSE_BlockEntity {
const newp = new LLSE_BlockEntity();
newp[PrivateFields] = be;
Object.defineProperty(newp, "type", { value: be.getType() });
Object.defineProperty(newp, "pos", { value: IntPos$newPos(be.getPosition(), dim) });
Expand Down
19 changes: 10 additions & 9 deletions src/api/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BlockPos } from "bdsx/bds/blockpos";
import { ActorCommandSelector, Command, CommandItem, CommandMessage, CommandOutput, CommandPermissionLevel, CommandPosition, CommandPositionFloat, CommandRawEnum, CommandRawText, PlayerCommandSelector, SoftEnumUpdateType } from "bdsx/bds/command";
import { CommandOrigin, CommandOriginType, ServerCommandOrigin } from "bdsx/bds/commandorigin";
import { JsonValue } from "bdsx/bds/connreq";
import { MobEffectInstance } from "bdsx/bds/effects";
import { MobEffect } from "bdsx/bds/effects";
import { ServerPlayer } from "bdsx/bds/player";
import { command } from "bdsx/command";
import { CommandParameterType } from "bdsx/commandparam";
Expand All @@ -14,14 +14,15 @@ import { bedrockServer } from "bdsx/launcher";
import { bool_t, CxxString, float32_t, int32_t } from "bdsx/nativetype";
import { _tickCallback } from "bdsx/util";
import { IsInDebugMode, LockDebugModeForOnce } from "../debug";
import { MCAPI } from "../dep/native";
import { logger, PrivateFields } from "./api_help";
import { FloatPos$newPos, IntPos$newPos } from "./base";
import { Block$newBlock } from "./block";
import { Entity$newEntity } from "./entity";
import { LXL_Events } from "./event";
import { LLSE_Events } from "./event";
import { Item$newItem } from "./item";
import { NbtCompound } from "./nbt";
import { LXL_Player, Player$newPlayer } from "./player";
import { LLSE_Player, Player$newPlayer } from "./player";

export const OriginType = {
Player: 0,
Expand Down Expand Up @@ -240,8 +241,8 @@ function convertResults(value: any, origin: CommandOrigin) {
if (value instanceof Block) {
return Block$newBlock(value, BlockPos.create(0,0,0), -1);
}
if (value instanceof MobEffectInstance) {
return value.getComponentName();
if (value instanceof MobEffect) {
return MCAPI.MobEffect.getResourceName(value);
}
if (value instanceof ActorDefinitionIdentifier) {
return value.canonicalName.str;
Expand Down Expand Up @@ -511,7 +512,7 @@ export function runcmdEx(cmd: string): { success: boolean, output: string } {
}
}

const playerCmdCallbacks = new Map<string, (player: LXL_Player, args: string[]) => void>();
const playerCmdCallbacks = new Map<string, (player: LLSE_Player, args: string[]) => void>();
const consoleCmdCallbacks = new Map<string, (args: string[]) => void>();

function LxlRegisterNewCmd(isPlayerCmd: boolean, cmd: string, description: string, level: number, func: Function) {
Expand Down Expand Up @@ -569,7 +570,7 @@ events.command.on((cmd, _, ctx) => {
}
const player = ctx.origin.getEntity();
if (player?.isPlayer()) {
const cancelled = LXL_Events.onPlayerCmd.fire(Player$newPlayer(player), cmd);
const cancelled = LLSE_Events.onPlayerCmd.fire(Player$newPlayer(player), cmd);
_tickCallback();
if (cancelled) {
return 0;
Expand Down Expand Up @@ -600,7 +601,7 @@ events.command.on((cmd, _, ctx) => {
return 0;
}
} else {
const cancelled = LXL_Events.onConsoleCmd.fire(cmd);
const cancelled = LLSE_Events.onConsoleCmd.fire(cmd);
_tickCallback();
if (cancelled) {
return 0;
Expand Down Expand Up @@ -635,7 +636,7 @@ events.command.on((cmd, _, ctx) => {
});

/** @deprecated */
export function regPlayerCmd(cmd: string, description: string, callback: (player: LXL_Player, args: string[]) => void, level: number = 0) {
export function regPlayerCmd(cmd: string, description: string, callback: (player: LLSE_Player, args: string[]) => void, level: number = 0) {
return LxlRegisterNewCmd(true, cmd, description, level, callback);
}

Expand Down
16 changes: 8 additions & 8 deletions src/api/container.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Container as _Container } from "bdsx/bds/inventory";
import { LlAPI } from "../dep/native";
import { logger, PrivateFields } from "./api_help";
import { Item$newItem, LXL_Item } from "./item";
import { Item$newItem, LLSE_Item } from "./item";

export class LXL_Container {
export class LLSE_Container {
private [PrivateFields]: _Container;

getRawPtr() {
Expand All @@ -18,23 +18,23 @@ export class LXL_Container {
return LlAPI.Container.getTypeName(this[PrivateFields]);
}

addItem(item: LXL_Item) {
addItem(item: LLSE_Item) {
if (!item[PrivateFields]) {
logger.error("Wrong type of argument in addItem!");
return null;
}
return LlAPI.Container.addItemSafe(this[PrivateFields], item[PrivateFields]);
}

addItemToFirstEmptySlot(item: LXL_Item) {
addItemToFirstEmptySlot(item: LLSE_Item) {
if (!item[PrivateFields]) {
logger.error("Wrong type of argument in addItemToFirstEmptySlot!");
return null;
}
return LlAPI.Container.addItemToFirstEmptySlotSafe(this[PrivateFields], item[PrivateFields]);
}

hasRoomFor(item: LXL_Item) {
hasRoomFor(item: LLSE_Item) {
if (!item[PrivateFields]) {
logger.error("Wrong type of argument in hasRoomFor!");
return null;
Expand All @@ -55,7 +55,7 @@ export class LXL_Container {
return Item$newItem(item);
}

setItem(index: number, item: LXL_Item) {
setItem(index: number, item: LLSE_Item) {
if (!item[PrivateFields]) {
logger.error("Wrong type of argument in setItem!");
return null;
Expand Down Expand Up @@ -94,8 +94,8 @@ export class LXL_Container {
getAllSlots = this.getAllItems;
}

export function Container$newContainer(p: _Container): LXL_Container {
const newp = new LXL_Container();
export function Container$newContainer(p: _Container): LLSE_Container {
const newp = new LLSE_Container();
newp[PrivateFields] = p;
return newp;
}
6 changes: 3 additions & 3 deletions src/api/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ServerPlayer as _ServerPlayer } from "bdsx/bds/player";
import { LlAPI } from "../dep/native";
import { PrivateFields } from "./api_help";

export class LXL_Device {
export class LLSE_Device {
[PrivateFields]: _ServerPlayer;

get ip() {
Expand All @@ -26,8 +26,8 @@ export class LXL_Device {
}
}

export function Device$newDevice(p: _ServerPlayer): LXL_Device {
const newp = new LXL_Device();
export function Device$newDevice(p: _ServerPlayer): LLSE_Device {
const newp = new LLSE_Device();
newp[PrivateFields] = p;
return newp;
}
18 changes: 9 additions & 9 deletions src/api/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Item$newItem } from "./item";
import { NbtCompound } from "./nbt";
import { Player$newPlayer } from "./player";

export class LXL_Entity {
export class LLSE_Entity {
private [PrivateFields]?: Actor;

getRawPtr() {
Expand Down Expand Up @@ -335,22 +335,22 @@ export class LXL_Entity {
getTag = this.getNbt;
}

export function Entity$newEntity(p: Actor): LXL_Entity {
const newp = new LXL_Entity();
export function Entity$newEntity(p: Actor): LLSE_Entity {
const newp = new LLSE_Entity();
newp[PrivateFields] = p;
return newp;
}

export function getAllEntities() {
const entityList = bedrockServer.level.getEntities();
const arr = new Array<LXL_Entity>();
const arr = new Array<LLSE_Entity>();
for (const i of entityList) {
arr.push(Entity$newEntity(i));
}
return arr;
}
export function spawnMob(name: string, pos: IntPos | FloatPos): LXL_Entity;
export function spawnMob(name: string, x: number, y: number, z: number, dimid: DimensionId): LXL_Entity;
export function spawnMob(name: string, pos: IntPos | FloatPos): LLSE_Entity;
export function spawnMob(name: string, x: number, y: number, z: number, dimid: DimensionId): LLSE_Entity;
export function spawnMob(name: string, a1: any, a2?: any, a3?: any, a4?: any) {
let pos: Vec3;
let dimId: DimensionId;
Expand All @@ -372,12 +372,12 @@ export function spawnMob(name: string, a1: any, a2?: any, a3?: any, a4?: any) {
}


export function explode(pos: IntPos | FloatPos, source: LXL_Entity | null, power: number, range: number, isDestroy: number, isFire: number): boolean;
export function explode(x: number, y: number, z: number, dimid: DimensionId, source: LXL_Entity | null, power: number, range: number, isDestroy: number, isFire: number): boolean;
export function explode(pos: IntPos | FloatPos, source: LLSE_Entity | null, power: number, range: number, isDestroy: number, isFire: number): boolean;
export function explode(x: number, y: number, z: number, dimid: DimensionId, source: LLSE_Entity | null, power: number, range: number, isDestroy: number, isFire: number): boolean;
export function explode(a0: any, a1?: any, a2?: any, a3?: any, a4?: any, a5?: any, a6?: any, a7?: any, a8?: any) {
let pos: Vec3;
let dimId: DimensionId;
let source: LXL_Entity | null,
let source: LLSE_Entity | null,
power: number,
range: number,
isDestroy: boolean,
Expand Down
Loading

0 comments on commit 4af207a

Please sign in to comment.