Skip to content

Add an atlas registry#5390

Open
CelDaemon wants to merge 12 commits into
FabricMC:26.1.2from
CelDaemon:atlas-registry
Open

Add an atlas registry#5390
CelDaemon wants to merge 12 commits into
FabricMC:26.1.2from
CelDaemon:atlas-registry

Conversation

@CelDaemon
Copy link
Copy Markdown
Contributor

Adds a registry for adding custom atlases, and fixes the testmod double sprite source.

/**
* Registers an atlas using a given texture and atlas id.
*
* @param textureId The id of the texture that will be generated.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to give a example format for texture id.
Through maybe it would be good idea to rather than requiring to provide the textureId, having it be created out of the atlasId and then returned by this method? Could also be an additional method instead

@Patbox Patbox added enhancement New feature or request area: rendering labels May 17, 2026
register(textureId, atlasId, createMipmaps, Set.of());
}

public static void register(Identifier textureId, Identifier atlasId, boolean createMipmaps, Set<MetadataSectionType<?>> additionalMetadata) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate ID checks this method performs should check against vanilla atlases as well.

* @param atlasId The atlas id to generate a texture id for.
* @return The generated texture id.
*/
public static Identifier createTextureLocation(Identifier atlasId) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I thought this was used to get the texture ID of the given registered atlas, but looking at the testmod revealed that it is used to create the default texture ID for some new atlas. I would rename the method to createDefaultTextureLocation and clarify it in the javadoc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hoped the create part of the name would be clear enough. I guess I can change it?


@Mixin(AtlasManager.class)
class AtlasManagerMixin {
@ModifyExpressionValue(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/client/resources/model/sprite/AtlasManager;KNOWN_ATLASES:Ljava/util/List;", opcode = Opcodes.GETSTATIC))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how the actual value of KNOWN_ATLASES is not modified. Doing it on classload would be ideal for covering edge cases but is problematic in other ways (making the timing of the registry freeze unreliable and making checking against vanilla atlases in the registry impossible), so an acceptable way to handle this would be to still inject into <init>, but at head and modify the field instead of only its accesses in the constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like all the possible injections have some weird caveat here. My ideas was that KNOWN_ATLASES doesn't necessarily need to contain all of the atlases.

A mod shouldn't really read from here anyway, everything will be available through the atlas manager itself. And even if we write our entries there, it'll be so late that a mod might as well just read from the atlas manager.

* @param hasMipmaps Whether to generate mipmaps for the atlas.
* @param additionalMetadata Additional metadata to be set in .mcmeta files.
*/
public static void register(Identifier textureId, Identifier atlasId, boolean hasMipmaps, Set<MetadataSectionType<?>> additionalMetadata) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for this to not accept an AtlasConfig directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It allows the params to be documented, and might be a bit more stable in the case that vanilla changes the signature of the Atlas config.

But yeah you're right, this should probably just take a config directy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: rendering enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants