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.51.1
- phpstan/phpstan: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Resource pack compiler and registrar for Axolotl-PM plugins
Requirements
- Axolotl-PM with plugin API 5.0.0. The exact development revision is recorded in
composer.lockand the CI workflow. - PHP 8.4 with the
zipextension. - A valid Bedrock resource pack manifest in the selected resource folder.
- DevTools for building a consumer PHAR. The consumer workflow is pinned to DevTools 4.1.3.
Installation
Check out ResourcePackManager into your plugin's virions/ResourcePackManager directory. Pin the same source revision in CI and local builds.
virions: - name: ResourcePackManager version: ^2.1.0
For local development, use the public 2.1.0 source revision until a tagged release is available:
git clone https://github.com/AxolotlBucketLabs/ResourcePackManager virions/ResourcePackManager git -C virions/ResourcePackManager checkout b8e065754b92e6a98c2db7ce9a3d3182e6fce7c0
DevTools shades the virion into the consumer PHAR. Keep the consumer's pack source files under its own resources/ directory.
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 AxolotlBucketLabs\ResourcePackManager\ResourcePackManager; use pocketmine\plugin\DisablePluginException; use pocketmine\plugin\PluginBase; final class MyPlugin extends PluginBase{ protected function onEnable() : void{ if(!ResourcePackManager::compileAndRegister($this)){ throw new DisablePluginException(); } } protected function onDisable() : void{ ResourcePackManager::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.
Use compile() when a resource pack should be offered to selected players instead of added to the server-wide stack. Wrap the returned path in ZippedResourcePack and pass it to Axolotl-PM's resource pack offer event. compile() does not register or offer the pack.
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): bool |
Returns true when the pack is registered or identical content is already active. Conflicting UUID content returns false and disables the plugin. |
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): bool |
Returns whether the pack is registered or identical content is already active. It clears a stale encryption key for the generated pack UUID because compiled packs are unencrypted. |
compile() disables the owning plugin if the data folder 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 ResourcePackManager 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. When compileAndRegister() adds or replaces its generated pack, it clears an old encryption key for that UUID because the generated pack is unencrypted. If it reuses identical content registered from another path, it preserves that pack's encryption setting. register() leaves pack encryption settings unchanged.
Resource pack UUIDs must identify one version and one content hash across the server stack. Registering the same UUID with different content disables the registering plugin instead of replacing another plugin's pack. Identical packs are shared without adding duplicate entries. Re-registering the same generated path replaces that path's previous pack.
Development and testing
Run composer install --no-scripts --no-plugins, composer validate --strict, composer phpstan and php -l src/AxolotlBucketLabs/ResourcePackManager/ResourcePackManager.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.
Migration
For migration from 1.x or 2.0.x, change the DevTools virion constraint to ^2.1.0. Composer consumers should switch to axolotlbucketlabs/resource-pack-manager and update the PHP import to AxolotlBucketLabs\ResourcePackManager\ResourcePackManager. Rebuild consumer PHARs after these changes. register() and compileAndRegister() return bool. In onEnable(), throw DisablePluginException when either method returns false so Axolotl-MP stops initialization before pack-dependent content or listeners are registered. Resource folder layouts are unchanged. 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.
License, credits and support
The PHP library is licensed under LGPL-3.0-or-later. See LICENSE. Attribution to AxolotlBucketLabs and jasonwynn10 is recorded in virion.yml. For support, use the AxolotlBucketLabs Discord or open an issue in this repository.