Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DevBed

A simplified implementation of the Minecraft Bedrock Scripting API.

Hierarchy

  • DevBed

Index

Constructors

constructor

  • new DevBed(obj: IClient | IServer, __namedParameters?: object): DevBed
  • Parameters

    • obj: IClient | IServer

      The client or server object.

    • Default value __namedParameters: object = {}
      • bedspace: string

        The main DevBed namespace name to use.

    Returns DevBed

Properties

Private bedspace

bedspace: string = "devbed"

The namespace name used by DevBed.

Private callbacks

callbacks: any

The callbacks for the events.

Private defaultData

defaultData: any

The default data for custom events.

ext

ext: any

The extended properties.

Private ids

ids: number = -1

The amount of ids that have already been created.

Private intervalled

intervalled: object

The functions set to execute on interval.

Type declaration

  • [id: number]: object
    • func: Function
    • passed: number
    • time: number

Private obj

obj: IClient | IServer

The client or server object.

players

players: string[] = []

An array of players in a server.

system

system: IClientSystem<any> | IServerSystem<any>

The system object.

Private systemType

systemType: "client" | "server"

The type of object the system is.

ticks

ticks: number = 0

The total ticks that have passed since the script started.

Methods

block

  • block(area: ITickingArea, coords: ICoords | [number, number, number, number, number, number]): IBlock | IBlock[][] | null
  • Get blocks from the world.

    block

    Parameters

    • area: ITickingArea

      The ticking area to use.

    • coords: ICoords | [number, number, number, number, number, number]

      3 coords specifying the location of a block or 6 for an area of blocks.

    Returns IBlock | IBlock[][] | null

blockAt

  • blockAt(coords: ICoords, callback?: Function): Promise<string> | void
  • Get the id of the block at specific coordinates.

    slash
    beta

    Parameters

    • coords: ICoords

      The coords of the block to check.

    • Optional callback: Function

      The callback to fire after checking.

    Returns Promise<string> | void

blockLoaded

  • blockLoaded(coords: ICoords, callback?: Function): Promise<boolean> | void
  • Check if a specific block has loaded.

    slash
    shorthand

    Parameters

    • coords: ICoords

      The coords of the block to check.

    • Optional callback: Function

      The callback to fire after checking.

    Returns Promise<boolean> | void

Private callEachCallback

  • callEachCallback(name: string, ...data: any): void
  • Call each callback of a specific name.

    events

    Parameters

    • name: string

      The name of the callback to call.

    • Rest ...data: any

      The data to provide in the callback.

    Returns void

chat

  • Post a message in chat.

    events
    shorthand

    Parameters

    • Rest ...message: IStringable[]

      The message to post. Accepts unlimited arguments.

    Returns void

chunkLoaded

  • chunkLoaded(coords: [number, number], callback?: Function): Promise<boolean> | void
  • Check if a specific chunk has loaded.

    slash
    shorthand

    Parameters

    • coords: [number, number]

      The coords of the chunk to check.

    • Optional callback: Function

      The callback to fire after checking.

    Returns Promise<boolean> | void

clearInterval

  • clearInterval(id?: number): void

cmd

  • cmd(command: string | string[], callback?: Function): Promise<object> | void
  • cmd(command: string | string[], as: string | string[], callback?: Function): Promise<object> | void
  • Execute a slash command.

    slash

    Parameters

    • command: string | string[]

      The command to execute.

    • Optional callback: Function

      The callback to invoke when the command returned data.

    Returns Promise<object> | void

  • Execute a slash command.

    slash

    Parameters

    • command: string | string[]

      The command to execute. Prepend with "c:" parameter for chat.

    • as: string | string[]

      The player to execute the command as.

    • Optional callback: Function

      The callback to invoke when the command returned data.

    Returns Promise<object> | void

component

  • Create a component.

    component

    Parameters

    • Default value data: object = {}

      The data to associate with the component.

    Returns BedComponent | null

Private createEntity

  • createEntity(entityType?: "entity" | "item_entity", identifier?: string): BedEntity | null
  • Create an entity.

    entity

    Parameters

    • Optional entityType: "entity" | "item_entity"

      The type of entity to create.

    • Optional identifier: string

      The template identifier of the enitity to create.

    Returns BedEntity | null

effect

  • effect(sel: string | string[], eff?: string, seconds?: number, amplifier?: number, particles?: boolean): void
  • Give or take potion effects from players.

    slash

    Parameters

    • sel: string | string[]

      The player selectors or usernames to apply the effect to.

    • Optional eff: string

      The effect type.

    • Default value seconds: number = 30

      The seconds the effect will be active.

    • Default value amplifier: number = 0

      The amplifier amount.

    • Default value particles: boolean = true

      Whether or not to show the particles.

    Returns void

entity

  • entity(identifier?: string): BedEntity | null
  • Create an entity.

    entity

    Parameters

    • Optional identifier: string

      The template identifier of the enitity to create.

    Returns BedEntity | null

extend

  • extend(data: object): void
  • extend(name: string, data: any): void
  • Extend DevBed functionality.

    utility

    Parameters

    • data: object

      The data to extend DevBed with. Specify names as keys and functions as values.

      • [key: string]: any

    Returns void

  • Extend DevBed functionality.

    utility

    Parameters

    • name: string

      The name of the data to extend DevBed with.

    • data: any

      The data to extend DevBed with.

    Returns void

getComponent

  • Get the component of an entity.

    component

    Parameters

    • id: string

      The identifier of the component to create.

    • ent: IEntity | BedEntity

      The entity with the component.

    Returns BedGetComponent | null

Private getId

  • getId(): string
  • Get a new ID for DevBed to use.

    Returns string

item

  • item(identifier?: string): BedEntity | null
  • Create an item.

    entity

    Parameters

    • Optional identifier: string

      The template identifier of the item to create.

    Returns BedEntity | null

json

  • json(obj: object, indent?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10): void
  • Post formatted json to the chat.

    utility
    shorthand

    Parameters

    • obj: object

      The javascript object.

    • Default value indent: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 = 4

      The indention level to use.

    Returns void

level

  • level(id: string, data?: any[] | object | Function): BedComponent | null | void
  • Get the data of a component stored in level.

    entity
    shorthand

    Parameters

    • id: string

      The id of the component.

    • Optional data: any[] | object | Function

      The data to set the component to.

    Returns BedComponent | null | void

locate

  • locate(name: string, callback?: Function): Promise<[number, number] | [undefined, undefined]> | void
  • Locate a structure.

    slash
    shorthand

    Parameters

    • name: string

      The structure to locate.

    • Optional callback: Function

      The function to invoke with the results.

    Returns Promise<[number, number] | [undefined, undefined]> | void

logconfig

  • logconfig(__namedParameters?: object): void
  • Configure the logging.

    events
    shorthand

    Parameters

    • Default value __namedParameters: object = {}
      • error: boolean
      • info: boolean
      • warning: boolean

    Returns void

Private maybe

  • maybe(cb: Function, promise: Promise<any>): void
  • maybe(cb: any, promise: Promise<any>): Promise<any>
  • Convert a promise to a callback function when needed.

    Parameters

    • cb: Function

      The callback to check.

    • promise: Promise<any>

      The promise to integrate into the callback.

    Returns void

  • Convert a promise to a callback function when needed.

    Parameters

    • cb: any

      The callback to check.

    • promise: Promise<any>

      The promise to integrate into the callback.

    Returns Promise<any>

Private modifyPrototype

  • modifyPrototype(obj: any, newProto: object): any
  • Modify the prototype of an object.

    utility

    Parameters

    • obj: any

      The object to be transformed.

    • newProto: object

      The transformation to apply.

    Returns any

newEvent

  • newEvent(event: string, defaultData?: object): void
  • Setup namespaced event to be listened for.

    events

    Parameters

    • event: string

      The event identifier.

    • Default value defaultData: object = {}

      The callback to trigger.

    Returns void

off

  • Remove an event listener for an event.

    events

    Parameters

    • event: IListenableEvent

      The event identifier.

    • Optional callback: Function

      The callback to remove.

    Returns void

on

  • Listen for an event.

    Parameters

    • event: IListenableEvent

      The event identifier.

    • callback: Function

      The callback to trigger. A respond function is included for custom events.

    Returns void

  • Listen for an event.

    Parameters

    • event: IBedEvent

      The event identifier.

    • callback: Function | function

      The callback to trigger. A respond function is included for custom events.

    Returns void

once

  • Listen for an event and trigger the callback once.

    events
    shorthand

    Parameters

    • event: IListenableEvent

      The event identifier.

    • Optional callback: Function

      The callback to trigger.

    Returns Promise<any> | void

Private parseTransform

  • parseTransform(data: object, transform: object | Function): object
  • parseTransform(data: any[], transform: any[] | Function): any[]
  • Parse the transformation of an array or object.

    Parameters

    • data: object

      The object to be transformed.

    • transform: object | Function

      The transformation to apply.

    Returns object

  • Parse the transformation of an array or object.

    Parameters

    • data: any[]

      The object to be transformed.

    • transform: any[] | Function

      The transformation to apply.

    Returns any[]

proxyEvent

  • proxyEvent(name: string, proxyName: string): void
  • Proxy an event to another event.

    utility

    Parameters

    • name: string

      The event to proxy.

    • proxyName: string

      The proxied event.

    Returns void

query

  • query(component?: string, fields?: [string, string, string]): BedQuery | null
  • Query for an object.

    entity

    Parameters

    • Optional component: string

      The component to query.

    • Default value fields: [string, string, string] = ["x", "y", "z"]

      The 3 query fields as an array of strings.

    Returns BedQuery | null

radius

  • radius(ent: IEntity | BedEntity, radius: number): IEntity[] | void
  • Get the entities within a specific radius of an entity.

    slash

    Parameters

    • ent: IEntity | BedEntity

      The centre entity.

    • radius: number

      The radius to search.

    Returns IEntity[] | void

rules

  • rules(rules: object | string, data: boolean | number | string): void
  • Set gamerules.

    slash
    shorthand

    Parameters

    • rules: object | string

      The rules or rule to set or get.

    • data: boolean | number | string

      The data to set if a single rule was provided.

    Returns void

setInterval

  • setInterval(cb: Function, time: number, type?: "ms" | "ticks"): number
  • Execute callback every specified milliseconds.

    utility

    Parameters

    • cb: Function

      Callback to execute.

    • time: number

      Milliseconds to wait between executions. (1 sec = 1000 ms)

    • Default value type: "ms" | "ticks" = "ms"

      The type of time to count. Can be set to ms or ticks.

    Returns number

setTimeout

  • setTimeout(cb: Function, time: number, type?: "ms" | "ticks"): number
  • Execute a function once after a specific amount of time.

    utility

    Parameters

    • cb: Function

      Callback to execute.

    • time: number

      Milliseconds to wait before executing. (1 sec = 1000 ms)

    • Default value type: "ms" | "ticks" = "ms"

      The type of time to count. Can be set to ms or ticks.

    Returns number

teleport

  • teleport(sel: string | string[], dest: string | ICoords, facing?: [number, number] | ICoords | string): void
  • Teleport players.

    slash
    shorthand
    beta

    Parameters

    • sel: string | string[]

      The player selectors or usernames to teleport.

    • dest: string | ICoords

      The destination to teleport to.

    • Optional facing: [number, number] | ICoords | string

      The y and x rotation values, coordinates or entity selector

    Returns void

Private toString

tp

  • tp(sel: string | string[], dest: string | ICoords, facing?: [number, number] | ICoords | string): void
  • Teleport players.

    slash
    shorthand
    beta

    Parameters

    • sel: string | string[]

      The player selectors or usernames to teleport.

    • dest: string | ICoords

      The destination to teleport to.

    • Optional facing: [number, number] | ICoords | string

      The y and x rotation values, coordinates or entity selector

    Returns void

Private transformComponent

  • transformComponent(id: string, obj: any): BedComponent | null
  • Transform IComponent to BedComponent.

    component

    Parameters

    • id: string

      The identifier of the component.

    • obj: any

      The IComponent object.

    Returns BedComponent | null

trigger

  • trigger(name: string, data?: object, callback?: Function): void
  • Trigger an event.

    events

    Parameters

    • name: string

      The name of the event to post.

    • Default value data: object = {}

      The data to include in the event.

    • Optional callback: Function

      The callback to handle a responded custom event.

    Returns void

Object literals

Static version

version: object

The API version targeted by DevBed.

major

major: number = 0

minor

minor: number = 0

Generated using TypeDoc