@ascentbv/ts-common - v1.0.199
    Preparing search index...

    Class CacheLayerAbstract

    Public cache layer Use this class as the main entrypoint for caching APIs Prefer the unified methods below over direct world/player calls

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    Methods

    • Returns all players using the world cache

      Returns Player[]

      // Before
      const allPlayers = world.getAllPlayers();

      // After
      const allPlayers = CacheLayer.getAllPlayers();
    • Returns one player by id using the world player index cache

      Parameters

      • id: string

      Returns Player | undefined

      // Before
      const targetPlayer = world.getAllPlayers().find((player) => player.id === id);

      // After
      const targetPlayer = CacheLayer.getPlayerById(id);
    • Reads a player's game mode through the player cache

      Parameters

      Returns GameMode

      // Before
      const gamemode = player.getGameMode();

      // After
      const gamemode = CacheLayer.getGameMode(player);
    • Writes a player's game mode and updates cache state

      Parameters

      Returns void

      // Before
      player.setGameMode(GameMode.Creative);

      // After
      CacheLayer.setGameMode(player, GameMode.Creative);
    • Returns a dimension instance by id using the dimension cache

      Parameters

      • id: string

      Returns Dimension

      // Before
      const overworld = world.getDimension("minecraft:overworld");

      // After
      const overworld = CacheLayer.getDimension("minecraft:overworld");
    • Gets an entity component using the entity component cache Results are memorized per tick for the same entity/component pair

      Parameters

      • entity: Entity
      • componentType: string

      Returns EntityComponent | undefined

      // Before
      const inventory = entity.getComponent("minecraft:inventory") as EntityInventoryComponent;

      // After
      const inventory = CacheLayer.getEntityComponent(entity, "minecraft:inventory");
    • Gets a block at a location using the block cache Results are memorized per tick, clearing automatically on next tick

      Parameters

      Returns Block | undefined

      // Before
      const block = dimension.getBlock(location);

      // After
      const block = CacheLayer.getBlock(dimension, location);
    • Returns the current weather for a dimension using the weather cache

      There is no native getter for weather; the cache listens to world.afterEvents.weatherChange and provides a synchronous read.

      Parameters

      Returns WeatherType

      const weather = CacheLayer.getWeather(dimension);
      
    • Sets the weather for a dimension and updates cache state

      Parameters

      Returns void

      // Before
      dimension.setWeather(WeatherType.Rain);

      // After
      CacheLayer.setWeather(dimension, WeatherType.Rain);