@@ -70,6 +70,8 @@ public class ResourcePack extends Pack {
7070 private final BlockColorCalculatorFactory colorCalculatorFactory ;
7171 private final BlockPropertiesConfig blockPropertiesConfig ;
7272
73+ private final Map <ResourcePackExtensionType <?>, ResourcePackExtension > resourcePackExtensions ;
74+
7375 private final Map <String , ResourcePath <BlockState >> blockStatePaths ;
7476 private final Map <String , ResourcePath <Texture >> texturePaths ;
7577 private final LoadingCache <de .bluecolored .bluemap .core .world .BlockState , BlockProperties > blockPropertiesCache ;
@@ -87,6 +89,10 @@ public ResourcePack(int packVersion) {
8789 this .colorCalculatorFactory = new BlockColorCalculatorFactory ();
8890 this .blockPropertiesConfig = new BlockPropertiesConfig ();
8991
92+ this .resourcePackExtensions = new HashMap <>();
93+ for (ResourcePackExtensionType <?> extensionType : ResourcePackExtensionType .REGISTRY .values ())
94+ resourcePackExtensions .put (extensionType , extensionType .create ());
95+
9096 this .blockPropertiesCache = Caffeine .newBuilder ()
9197 .executor (BlueMap .THREAD_POOL )
9298 .maximumSize (10000 )
@@ -203,6 +209,12 @@ private void loadResources(Path root) throws IOException {
203209 if (cause != null ) throw new IOException (cause );
204210 throw new IOException (ex );
205211 }
212+
213+ // invoke extensions
214+ for (ResourcePackExtension extension : resourcePackExtensions .values ()) {
215+ extension .loadResources (root );
216+ }
217+
206218 }
207219
208220 private void loadTextures (Path root ) throws IOException {
@@ -251,6 +263,13 @@ private void loadTextures(Path root) throws IOException {
251263 if (cause != null ) throw new IOException (cause );
252264 throw new IOException (ex );
253265 }
266+
267+ // invoke extensions
268+ for (ResourcePackExtension extension : resourcePackExtensions .values ()) {
269+ extension .loadTextures (root )
270+ .forEach (texture -> textures .put (texture .getResourcePath (), texture ));
271+ }
272+
254273 }
255274
256275 private void bake () throws IOException , InterruptedException {
@@ -286,33 +305,33 @@ private void bake() throws IOException, InterruptedException {
286305 if (grass == null ) throw new IOException ("Failed to bake resource-pack: No grass-colormap found!" );
287306 this .colorCalculatorFactory .setGrassMap (grass );
288307
308+ // invoke extensions
309+ for (ResourcePackExtension extension : resourcePackExtensions .values ()) {
310+ extension .bake ();
311+ }
312+
289313 }
290314
291- @ Nullable
292- public BlockState getBlockState (de .bluecolored .bluemap .core .world .BlockState blockState ) {
315+ public @ Nullable BlockState getBlockState (de .bluecolored .bluemap .core .world .BlockState blockState ) {
293316 ResourcePath <BlockState > path = blockStatePaths .get (blockState .getFormatted ());
294317 return path != null ? path .getResource (this ::getBlockState ) : MISSING_BLOCK_STATE .getResource (this ::getBlockState );
295318 }
296319
297- @ Nullable
298- public BlockState getBlockState (ResourcePath <BlockState > path ) {
320+ public @ Nullable BlockState getBlockState (ResourcePath <BlockState > path ) {
299321 BlockState blockState = blockStates .get (path );
300322 return blockState != null ? blockState : MISSING_BLOCK_STATE .getResource (blockStates ::get );
301323 }
302324
303- @ Nullable
304- public BlockModel getBlockModel (ResourcePath <BlockModel > path ) {
325+ public @ Nullable BlockModel getBlockModel (ResourcePath <BlockModel > path ) {
305326 BlockModel blockModel = blockModels .get (path );
306327 return blockModel != null ? blockModel : MISSING_BLOCK_MODEL .getResource (blockModels ::get );
307328 }
308329
309- @ Nullable
310- public ResourcePath <Texture > getTexturePath (String formatted ) {
330+ public @ Nullable ResourcePath <Texture > getTexturePath (String formatted ) {
311331 return texturePaths .get (formatted );
312332 }
313333
314- @ Nullable
315- public Texture getTexture (ResourcePath <Texture > path ) {
334+ public @ Nullable Texture getTexture (ResourcePath <Texture > path ) {
316335 Texture texture = textures .get (path );
317336 return texture != null ? texture : MISSING_TEXTURE .getResource (textures ::get );
318337 }
@@ -348,4 +367,9 @@ private BlockProperties loadBlockProperties(de.bluecolored.bluemap.core.world.Bl
348367 return props .build ();
349368 }
350369
370+ @ SuppressWarnings ({"unchecked" , "unused" })
371+ public <T extends ResourcePackExtension > @ Nullable T getResourcePackExtension (ResourcePackExtensionType <T > extensionType ) {
372+ return (T ) resourcePackExtensions .get (extensionType );
373+ }
374+
351375}
0 commit comments