Interface GameContext

A representation of the Game from the Mod's point of view. While the actual game object is exposed to the mod, this interface describes the agreed contract between the mod and the game. Anything outside of this might break between versions.

Hierarchy

  • GameContext

Methods

  • Add an sound effect to the internal cache. If the sound effect already existed it will be replaced. This lets you switch assets.

    Parameters

    • id: string

      The ID of the sound effect in the cache

    • data: string

      The raw data as returned from

    Returns void

    See

    getModResource

  • Add a block definition to the list. The Block ID is a numeric index thats used in the world array. If you're doing custom ones probably best to start at 100. Right now theres only 255 allowed.

    Parameters

    • blockId: number

      The ID of the block to add. If it already exists it'll be replaced.

    • tileDef: Block

      The definition of the new block.

    Returns void

    See

    Block for more details.

  • Add an image to the internal cache. If the image already existed it will be replaced. This lets you switch assets.

    Parameters

    • id: string

      The ID of the image in the cache

    • data: string

      The raw data as returned from

    Returns void

    See

    getModResource

  • Add a set of particulars at a particular world location

    Parameters

    • image: string

      The ID of the image in the cache to use as the particle

    • x: number

      The x coordinate of the world position to add the particles at

    • y: number

      The y coordinate of the world position to add the particles at

    • count: number

      The number of particles to add

    Returns void

  • Add a set of particulars at a particular tile location

    Parameters

    • image: string

      The ID of the image in the cache to use as the particle

    • x: number

      The x coordinate of the tile position to add the particles at

    • y: number

      The y coordinate of the tile position to add the particles at

    • count: number

      The number of particles to add

    Returns void

  • Add a recipe to the game

    Parameters

    • name: string

      The name of the recipe

    • recipeDef: Recipe

      The recipe to be added

    Returns void

  • Add a skin definition

    Parameters

    • name: string

      The name to use for this skin

    • skinDef: SkinDefinition

      The definition of the skin as a structure

    Returns void

  • Add a skin definition from a JSON file (@see getModResource)

    Parameters

    • name: string

      The name to use for this skin

    • skinDef: string

      The definition of the skin in a resource file

    Returns void

  • Add a tool into the default inventory of all players.

    Parameters

    • image: string

      The ID of the image in the cache to show for this tool.

    • place: number

      The ID of the block to place for this tool (or zero for none)

    • toolId: undefined | string

      An ID to assign for this tool so that callbacks can identify particular calls being used

    • targetEmpty: boolean

      True if this tool can target empty spaces

    • targetFull: boolean

      True if this tool can target spaces with a block in

    • Optional delayOnOperation: number

      Time before operation takes place on a full block

    • Optional breakable: boolean

      True if this tool has a condition - i.e. some of it used but not a whole item

    • Optional amountUsed: number

      The number of items to use up for each use of the tool (note this can be partial for items that wear out over time)

    Returns string

    An identifier that can be used to make the tool into a found item

  • Get the number of an item a mob has

    Parameters

    • mob: MobContext

      The mob to check

    • typeId: string

      The type of item to count as returned from

    Returns number

    The number of the item the mob has

    See

    addTool

  • Create new item floating in the world for a play to pick up

    Parameters

    • x: number

      The x coordinate in blocks to place the item at

    • y: number

      The y coordinate in blocks to place the item at

    • count: number

      The number of the item in the stack

    • typeId: string

      The type of the item to create as returned from

    Returns string

    The type of the uniquely created item

    See

    addTool

  • Create a mob in the world

    Parameters

    • name: string

      The name to give the mod (or "" to not display a name)

    • skin: string

      The ID of the skin of the mob to create (@see SKINS)

    • x: number

      The x coordinate in the world to create the mob in world coordinates (* BLOCK_SIZE)

    • y: number

      The y coordinate in the world to create the mob in world coordinates (* BLOCK_SIZE)

    • Optional thinkFunction: MobThinkFunction

      The callback for the mob to think each frame

    Returns MobContext

  • Display a chat message in game

    Parameters

    • message: string

      The message to retrieve

    Returns void

  • Log a error to the Javascript console in the context of this mod

    Parameters

    • e: any

      The error to be logged

    Returns void

  • Get the block at a particular location

    Parameters

    • x: number

      The x coordinate of the block to be retrieved in tiles.

    • y: number

      The y coordinate of the block to be retrieved in tiles.

    • layer: Layer

      The layer on which the block should be set (0 = foreground, 1 = background).

    Returns number

    The block ID at the given location or 0 for none.

    See

    Layer

  • Get the value of a property

    Parameters

    • prop: GameProperty

      The name of the property whose value is retrieved

    Returns string | number | boolean

    The value of the property

  • Get a handle to the local player's mob. This is kinda weird right now since mods only run on the server.

    Returns MobContext

    The local player to be manipulated.

  • Get the meta data blob associated with the current map

    Returns any

    The data associated with this mod

  • Get a resource that was uploaded along with this mod. The name will be the path in the zip.

    Parameters

    • name: string

      The name of the resource to get

    Returns string

  • Give a mob an item

    Parameters

    • mob: MobContext

      The mob to give the item

    • count: number

      The number of the item to give

    • typeId: string

      The type of item to give as returned from

    Returns void

    See

    addTool

  • Check if the game is in creative mode

    Returns boolean

  • Check if we're running on the host. Only some parts of the mod run on the client side.

    Returns boolean

  • Load a map from a file thats part of the mod

    Parameters

    • resource: string

      The reference to the resource (@see getModResource)

    Returns void

  • Log a message to the Javascript console in the context of this mod

    Parameters

    • message: string

      The message to be logged

    Returns void

  • Play a sound effect

    Parameters

    • id: string

      The ID of the sound effect in the cache

    • volume: number

      The volume at which to play the sound (0 = silent, 1 = loudest)

    • Optional variations: number

      The variations of the sound effect to attempt to apply

    Returns void

  • Remove a block from the game configuration based on its block ID. This is useful for mods to change the default mod rather than turning it off altogether.

    Parameters

    • blockId: number

      The ID of the block to remove

    Returns void

  • Remove a previously created mob

    Parameters

    Returns void

  • Remove a recipe from the game

    Parameters

    • name: string

      The name of the recipe to be removed

    Returns void

  • Remove a tool from the game configuration based on its block it places. This is useful for mods to change the default mod rather than turning it off altogether.

    Parameters

    • blockId: number

      The placement block ID of the tool to remove

    Returns void

  • Remove a tool from the game configuration based on the image it uses. This is useful for mods to change the default mod rather than turning it off altogether.

    Parameters

    • image: string

      The name of the image used by the tool to be removed

    Returns void

  • Remove a tool from the game configuration based on its tool ID. This is useful for mods to change the default mod rather than turning it off altogether.

    Parameters

    • toolId: string

      The ID of the tool to remove

    Returns void

  • Replace all the blocks on the map that match the original block with the new one.

    Parameters

    • originalBlock: number

      The original block to be replaced

    • newBlock: number

      The new block to be put into the map

    Returns void

  • Set a block in the game world.

    Parameters

    • x: number

      The x coordinate of the block to be set in tiles.

    • y: number

      The y coordinate of the block to be set in tiles.

    • layer: Layer

      The layer on which the block should be set (0 = foreground, 1 = background).

    • blockId: number

      The ID of the block to be placed

    Returns void

    See

    Layer

  • Set a game property

    Parameters

    • prop: GameProperty

      The name of the property to set

    • value: string | number | boolean

      The value to apply to the property

    Returns void

    See

    GameProperty

  • Set the meta data blob associated with the current map for this mod. Note this should be called sparingly since it'll results in the meta data being transmitted to the clients (theres no real use for that yet)

    Parameters

    • blob: any

      The blob to store for this mod

    Returns void

  • Equivalent to Javascript setTimeout but fired in the context of the mod

    Parameters

    • callback: string

      The callback name to call back with

    • timeout: number

      The timeout in game ticks

    • Optional tileX: number

      The x coordinate of the optional tile location this time was associated with

    • Optional tileY: number

      The y coordinate of the optional tile location this time was associated with

    • Optional layer: number

      The layer of optional tile location this time was associated with

    Returns void

  • Take an item from a mob

    Parameters

    • mob: MobContext

      The mob to take the item from

    • count: number

      The number of the item to take

    • typeId: string

      The type of item to take as returned from

    Returns void

    See

    addTool

Generated using TypeDoc