ModSAPI Documentation

website·Indexed 30 days ago

https://modsapi.pages.dev

A development framework for creating mods, featuring client and server interfaces. It includes modules for world management, entity and player interaction, event listening (BeforeEvents and AfterEvents), and UI tools such as CustomUI and FormUI (an upgrade of MoreUI).

Tokens
10.4K
Snippets
78
Records
99
Agent score
75%

What's inside ModSAPI

  1. Overview of the Server module

    The Server module provides a set of server-side interfaces equivalent to the @minecraft/server module in SAPI. It is the primary entry point for interacting with the game server's world and system state.
  2. Overview of the Server_ui form module

    The Server_ui module provides a set of form interfaces equivalent to the @minecraft/server-ui module in SAPI. It allows developers to create and manage user interface forms within the server environment. Available form types and utilities include ActionFormData, ModalFormData, CustomForm, and MoreUI.
  3. Overview of FormUI library

    FormUI is a portable library that enables developers to quickly create and manage multiple forms within a single user interface. It is the upgraded version of the previous MoreUI library.
  4. Intercept block breaking with playerBreakBlock

    The playerBreakBlock event triggers before a player successfully breaks a block. It provides details about the block, the dimension, and the tool used, and allows the action to be cancelled.
    // Example event parameters for playerBreakBlock
    {
      player: Player,                      // The player breaking the block
      block: Block,                        // The block at the event location
      dimension: Dimension,                 // The dimension containing the block
      brokenBlockPermutation: BlockPermutation, // Block state before breaking
      itemStackBeforeBreak: ItemStack | undefined, // Tool used to break the block
      cancel: boolean                      // Set to true to prevent the block from breaking
    }
  5. Use the ModSAPI Client module for client-side interfaces

    The ModSAPI Client module provides a set of interfaces for interacting with the client. It primarily exposes the manager class for client management and the CustomUI type for defining custom user interfaces.
  6. Manage items in a Minecraft Container

    The Container class allows developers to manipulate items within player inventories, entity backpacks, and block containers. It provides capabilities to add, remove, move, and swap items across different containers.
  7. Handle world events using afterEvents and beforeEvents

    The world object provides two event containers: afterEvents for events that have already occurred and completed, and beforeEvents for events that are about to happen and can potentially be intercepted.
    # Subscribe to an event that has already happened
    world.afterEvents.entityDie.subscribe(callback)
    
    # Subscribe to an event that is about to happen
    world.beforeEvents.chatSend.subscribe(callback)
  8. Interact with world dimensions using the Dimension class

    The Dimension class represents a specific dimension in the world (e.g., Overworld, Nether, End). It provides properties to identify the dimension and methods to manipulate blocks, entities, and players within that dimension.
  9. Reference for Entity and DamageSource in ModSAPI

    When handling entity damage events in ModSAPI, use the following properties and methods:

    • EntityHurtAfterEvent: The event triggered after an entity is hurt.
    • damageSource: An EntityDamageSource object containing information about the attack.
    • damageSource.damagingEntity: The Entity that caused the damage (may be None).
    • hurtEntity: The Entity that received the damage.
    • Entity.isInWater: A boolean indicating if the entity is currently in water.
    • Entity.kill(): A method to immediately kill the entity.
  10. Handle entity damage events with entityHurt

    The entityHurt after-event provides critical information about combat interactions. The event argument contains:

    • damageSource: An EntityDamageSource object, which includes the damagingEntity (the attacker).
    • hurtEntity: The Entity that received the damage.
  11. Subscribe to world after-events in ModSAPI

    The world object in ModSAPI contains afterEvents, which stores events that trigger after a specific action has occurred. To listen for these events, use the subscribe() method, passing the name of the function to be executed when the event triggers.
    # Example: subscribing to the entityHurt event
    world.afterEvents.entityHurt.subscribe(your_function_name)