nhanaz / libregrsp
Resource pack compiler and registrar for Axolotl-PM plugins
Requires
- php: ^8.1
- ext-zip: *
- pocketmine/pocketmine-mp: ^5.0.0
Requires (Dev)
- axolotl-pm/pocketmine-mp: 5.49.1
- phpstan/phpstan: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-14 09:53:50 UTC
README
libRegRsp compiles a plugin's bundled resources into a Bedrock resource pack and registers it with Axolotl-PM. Version 1.0.6 declares plugin API 5.0.0 and requires PHP 8.1 or later. Consumer CI smoke-tests the declared API floor and one pinned Axolotl-PM release; the workflow records exact revisions. Intermediate 5.x releases are not verified.
Overview
The library reads assets from resources/<PluginName>/ or the legacy resources/<PluginName> Pack/ layout. It creates a .mcpack file in the plugin data directory and places the pack at the top of the server resource stack. A custom folder and output name are supported.
- Compiles and validates a pack before replacing any existing pack file.
- Preserves an existing pack if the new build fails.
- Removes the current process's registered pack on
unregister(). - Can require players to accept the pack through
forceRequired.
Requirements
- Axolotl-PM with plugin API 5.0.0. The exact development revision is recorded in
composer.lockand the CI workflow. - PHP 8.1 or later with the
zipextension. - A valid Bedrock resource pack manifest in the selected resource folder.
- DevTools for building a consumer PHAR. The consumer workflow pins the exact builder revision.
Installation
Place a checkout of this virion at virions/libRegRsp next to your plugin project. Add a compatible declaration to its devtools.yml.
virions: - name: libRegRsp version: ^1.0.5
Build a standalone consumer PHAR with DevTools after copying the library's virion.yml, src/ and LICENSE into that directory. The PHP source is shaded into the consumer PHAR. The consumer must include its own resource pack files. A Composer consumer can depend on nhanaz/libregrsp when it supplies the Axolotl-PM API and resource files.
Usage
Store pack files under resources/MyPlugin/, including manifest.json at the folder root. Register the pack when the plugin starts and remove it when the plugin stops.
use NhanAZ\libRegRsp\libRegRsp; use pocketmine\plugin\PluginBase; final class MyPlugin extends PluginBase{ protected function onEnable() : void{ libRegRsp::compileAndRegister($this); } protected function onDisable() : void{ libRegRsp::unregister($this); } }
For a different resource folder, pass it as the second argument to compileAndRegister(). The third argument sets the output name without an extension. The output name must be a safe single file name. The fourth argument controls whether players must accept the resource pack, and defaults to true.
API
| Method | Result |
|---|---|
compile(PluginBase $plugin, ?string $packFolder = null, ?string $zipFileName = null): ?string |
Returns the built pack path or null on failure. |
register(PluginBase $plugin, ?string $zipPath = null, bool $forceRequired = true): void |
Adds a valid pack to the server stack. |
unregister(PluginBase $plugin, ?string $zipPath = null): void |
Removes a pack registered by the current process and deletes its generated file. |
compileAndRegister(PluginBase $plugin, ?string $packFolder = null, ?string $zipFileName = null, bool $forceRequired = true): void |
Compiles and registers a pack. |
compile() disables the owning plugin if the data directory is unusable, the output name is unsafe, a resource cannot be read, or the generated pack is invalid. If a previous pack file exists, a failed replacement keeps it for recovery. register() sets Axolotl-PM's server-wide resource pack requirement to the supplied forceRequired value when the runtime exposes that API. On older API builds without a runtime setter, the existing force_resources value in resource_packs/resource_packs.yml must already match forceRequired; otherwise libRegRsp logs the required configuration and disables the plugin before compiling or changing the resource stack. Coordinate that server-wide setting with other plugins that manage resource packs.
Development and testing
Run composer install --no-scripts --no-plugins, composer validate --strict, composer phpstan and php -l src/NhanAZ/libRegRsp/libRegRsp.php. CI runs the same checks against locked Axolotl-PM development dependencies. DevTools builds a consumer PHAR. A clean server startup and pack lifecycle test verifies packaging. A Bedrock client is still needed to verify its presentation.
For migration from 1.0.4 or 1.0.5, preserve a copy of the previous consumer PHAR and generated pack, update the virion declaration to ^1.0.6, then rebuild the consumer. On runtimes without the resource requirement setter, configure force_resources in resource_packs/resource_packs.yml to match the consumer's forceRequired value before starting the server. If startup or pack loading fails, restore the previous PHAR and restart the server. Existing API method names and resource folder layouts remain supported.
License, credits and support
The PHP library is licensed under LGPL-3.0-or-later. See LICENSE. Existing attribution to NhanAZ and jasonwynn10 is preserved in virion.yml. For support, use NhanAZ Discord or open an issue in this repository.