diff --git a/src/Resource/DynamicResources/DecoratedPotModelGenerator.php b/src/Resource/DynamicResources/DecoratedPotModelGenerator.php index 2271f82..53023f2 100644 --- a/src/Resource/DynamicResources/DecoratedPotModelGenerator.php +++ b/src/Resource/DynamicResources/DecoratedPotModelGenerator.php @@ -6,12 +6,10 @@ use Aternos\Renderchest\Exception\ModelResolutionException; use Aternos\Renderchest\Model\ModelInterface; use Aternos\Renderchest\Resource\ResourceLocator; -use Aternos\Renderchest\Resource\ResourceManagerInterface; -use Exception; class DecoratedPotModelGenerator extends DynamicResourceGenerator { - protected array $models = []; + protected ?array $models = null; /** * @inheritDoc @@ -22,12 +20,15 @@ public static function getNamespace(): string } /** - * @param ResourceManagerInterface $resourceManager - * @throws Exception + * @return void + * @throws ModelResolutionException */ - public function __construct(ResourceManagerInterface $resourceManager) + protected function initializeModels(): void { - parent::__construct($resourceManager); + if ($this->models !== null) { + return; + } + $this->models = []; foreach (Constants::POTTERY_SHERDS as $sherd) { $this->createBasePot($sherd); $this->createOverlayModel($sherd); @@ -72,6 +73,7 @@ protected function createOverlayModel(string $sherd): ModelInterface */ public function getModel(ResourceLocator $locator): ModelInterface { + $this->initializeModels(); if (!isset($this->models[strval($locator)])) { throw new ModelResolutionException("Cannot resolve model locator " . $locator); } @@ -80,9 +82,11 @@ public function getModel(ResourceLocator $locator): ModelInterface /** * @inheritDoc + * @throws ModelResolutionException */ public function getAllItems(string $namespace): array { + $this->initializeModels(); return array_keys($this->models); } } diff --git a/src/Resource/DynamicResources/LeatherArmorTrimModelGenerator.php b/src/Resource/DynamicResources/LeatherArmorTrimModelGenerator.php index f123b52..d956161 100644 --- a/src/Resource/DynamicResources/LeatherArmorTrimModelGenerator.php +++ b/src/Resource/DynamicResources/LeatherArmorTrimModelGenerator.php @@ -7,12 +7,11 @@ use Aternos\Renderchest\Model\GeneratedItem; use Aternos\Renderchest\Model\ModelInterface; use Aternos\Renderchest\Resource\ResourceLocator; -use Aternos\Renderchest\Resource\ResourceManagerInterface; use Exception; class LeatherArmorTrimModelGenerator extends DynamicResourceGenerator { - protected array $models = []; + protected ?array $models = null; /** * @inheritDoc @@ -23,12 +22,15 @@ public static function getNamespace(): string } /** - * @param ResourceManagerInterface $resourceManager + * @return void * @throws Exception */ - public function __construct(ResourceManagerInterface $resourceManager) + protected function initializeModels(): void { - parent::__construct($resourceManager); + if ($this->models !== null) { + return; + } + $this->models = []; foreach (Constants::ARMOR_ITEM_TYPES as $armorItem) { $this->createModelFromLayers("leather_" . $armorItem . "_base", [ "minecraft:item/leather_" . $armorItem @@ -68,9 +70,11 @@ protected function createModelFromLayers(string $locatorPath, array $layers): Ge /** * @inheritDoc + * @throws Exception */ public function getModel(ResourceLocator $locator): ModelInterface { + $this->initializeModels(); if (!isset($this->models[strval($locator)])) { throw new ModelResolutionException("Cannot resolve model locator " . $locator); } @@ -79,9 +83,11 @@ public function getModel(ResourceLocator $locator): ModelInterface /** * @inheritDoc + * @throws Exception */ public function getAllItems(string $namespace): array { + $this->initializeModels(); return array_keys($this->models); } }