-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Texture Atlases #221
base: main
Are you sure you want to change the base?
Texture Atlases #221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
In it's current state, there is a lot of missing detail (e.g., how does a texture atlas work, what is generated, how to access and use it within the game, and what are the available sources to pull from). Also, there are a few spelling mistakes and sentences that need clarification.
Texture atlas sources are json files located inside the `atlases` asset folder. | ||
A texture atlas source describes the name of the targeted atlas and its contents. Additions to the atlases need to be created under the namespace of a mod or datapack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additions to what atlas? Are you talking about creating your own atlas here, or adding to an existing atlas?
Texture atlas sources are json files located inside the `atlases` asset folder. | ||
A texture atlas source describes the name of the targeted atlas and its contents. Additions to the atlases need to be created under the namespace of a mod or datapack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additions to what atlas? Are you talking about creating your own atlas here, or adding to an existing atlas?
Texture atlas sources are json files located inside the `atlases` asset folder. | ||
A texture atlas source describes the name of the targeted atlas and its contents. Additions to the atlases need to be created under the namespace of a mod or datapack. | ||
|
||
As of today 14 different atlas sources can be declared: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is today? State it as fact rather than specifying a time. It can always be updated later.
Also, the sources are not to be declared. Those are the existing sources that vanilla adds. Is it necessary to be aware of the files themselves though? I think it's better to specify how to use them in the codebase instead.
|
||
### Creating an atlas source | ||
|
||
To add new textures to an atlas, a new file needs to be created in the `atlases` asset folder: `resources/assets/example_mod/atlases`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any file? How does the codebase knows what to reference for the atlas itself?
To add new textures to an atlas, a new file needs to be created in the `atlases` asset folder: `resources/assets/example_mod/atlases`. | ||
|
||
The file named the same as the altas it is appending to, will then describe what file will be added to the atlas: | ||
```json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use json5 format. See https://docs.neoforged.net/contributing#code-references for more information.
{ | ||
"type": "minecraft:unstitch", | ||
"resource": "example_mod:gui/sprites/icons", | ||
"divisor_x": 0.0, | ||
"divisor_y": 0.0, | ||
"regions": [ | ||
{ | ||
"sprite": "example_mod:energy_low", | ||
"x": 0.0, | ||
"y": 0.0, | ||
"width": 8.0, | ||
"height": 8.0 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here. What is this doing? All I understand reading this is that it attempts to merge the texture generated for the icon atlas with your custom one. x, y and the like are not explained.
} | ||
``` | ||
|
||
All paths are realtive to the texture folder and extentions (`.png`, `.png.mcmeta`) are implied. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you trying to say that all textures are PNGs? I don't think that's important to state here as the format is already defined in the textures section. Also, we don't know what is referring to a texture here or not as you don't state as such.
|
||
```Java | ||
public class MySpriteSourceProvider extends SpriteSourceProvider { | ||
|
||
// Parameters obtained via GatherDataEvent | ||
public MySpriteSourceProvider ( | ||
PackOutput output, | ||
CompletableFuture<HolderLookup.Provider> lookupProvider | ||
) { | ||
super(output, lookupProvider, "example_mod"); | ||
} | ||
|
||
@Override | ||
protected void gather () | ||
{ | ||
// Creates a new "gui" atlas for the mod's namespace | ||
SourceList gui = atlas( | ||
ResourceLocation.fromNamespaceAndPath("example_mod", "gui") | ||
); | ||
|
||
// Adds the "resources/assets/example_mod/textures/gui/sprites" folder | ||
// as a source for the atlas | ||
sources.addSource(new DirectoryLister("gui/sprites", "")); | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other examples on how we show data generation. Usually, we make it a tab-like system and show how to register it via gather data.
|
||
// Adds the "resources/assets/example_mod/textures/gui/sprites" folder | ||
// as a source for the atlas | ||
sources.addSource(new DirectoryLister("gui/sprites", "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is sources from? A parameter on the source list?
} | ||
|
||
@Override | ||
protected void gather () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should match what's in the example JSON.
@ChampionAsh5357 I have rewritten most of the article, please tell me what you think of it when you have the time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things of note. Currently, you are simply explaining the existing vanilla types and not how to use the texture atlas. Additionally, you should assume that the average reader has little to no knowledge in the system, so they're not going to understand why to use X or Y in a given situation.
A lot of this information seems like it came from the Minecraft wiki page on the atlas JSON format due to similar wording. While that's partially fine, you need to supplement with additional information as to what would be useful to know from a modder's perspective.
Other than that, just spelling and grammar mistakes that I have not added a review for as it should be caught in further rewrites.
|
||
Many textures in Minecraft are compiled within Atlases (also known as sprite sheets) for optimisation purposes. Most of them are automaticaly generated by Minecraft when registered throught the use of datapacks or [Registries][reg] (such as block textures). | ||
|
||
Optionaly, datapacks can register their own [texture atlas sources][txtatlassource], giving more control over wich sprite or image gets included within an atlas. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not giving more control. The sprite sources quite literally determine what is within the final stitched texture.
|Altas name |Description| | ||
|-----------------|-| | ||
|`blocks` |Block textures| | ||
|`banner_patterns`|Banner patterns| | ||
|`beds` |Every bed variant (i.e. colors)| | ||
|`chest` |Chest textures| | ||
|`shield_patterns`|Shield textures and patterns| | ||
|`shulker_boxes` |Every shulker related textures (Shulker box variants, head and projectile)| | ||
|`signs` |Sign textures| | ||
|`particles` |Particle textures| | ||
|`paintings` |Every painting| | ||
|`mob_effects` |Potion effect icons| | ||
|`gui` |Every GUI wigets (buttons, scroll bars...)| | ||
|`map_decorations`|Icons displayed on a map (banners, locations...)| | ||
|`armor_trims` |Armor trim patterns for every material| | ||
|`decorated_pot` |Texture for the decorated pot and every sherd| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once again, how are the atlases stored in code? How do I use them?
|
||
Texture atlas sources are JSON configuration files in ressource packs, that control wich textures of a resource pack are included in the atlases. | ||
|
||
Texture atlas sources are located within the `altases` asset folder, under the namespace of the datapack it is gathering textures from. For a datapack named `example_mod` the directory will be located in `resources/assets/example_mod/atlases`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resources
doesn't exist within the compiled jar.
|
||
### Creating a texture atlas source | ||
|
||
To add textures of a datapack to an atlas, a JSON file with the name of the atlas needs to be declared within the `atlases` asset folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this refer to creating a new sprite source list, or adding to an existing sprite source list. I can tell in the codebase it works similar to tags, but it should be explicitly stated.
// This texture altas source does not | ||
// declare any sprite sources. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then what's the point of this example? Just say 'Add sources here'.
|`divisor_x`|Used for determining the scale of coordinates on the x axis| | ||
|`divisor_y`|Used for determining the scale of coordinates on the y axis| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, the divisors should be larger than the texture in question as these are inversely scaling the coordinates.
|`x` |x coordinate within the file (before scaling by `divisor_x`)| | ||
|`y` |y coordinate within the file (before scaling by `divisor_y`)| | ||
|`width` |width of the sprite (before scaling by `divisor_x`)| | ||
|`height`|height of the sprite (before scaling by `divisor_y`)| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scaling will affect the rectangle that is being copied.
## Datagen | ||
|
||
Like many resources in Minecraft, texture atlas sources can be proceduraly generated using [datagen][dtgn]. | ||
To do so, we extend `SpriteSourceProvider` and override the `gather()` method: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention that SpriteSourceProvider
is added by neoforge.
// Creates a new texture atlas source for the "blocks" atlas | ||
SourceList blocks = atlas( | ||
ResourceLocation.fromNamespaceAndPath("example_mod", "blocks") | ||
); | ||
|
||
/* Adds the "resources/assets/example_mod/textures/blocks" | ||
directory as a source for the atlas. | ||
|
||
Adding "block/" at the start of every ResourceLocation's path. | ||
|
||
This will result in "example_mod:block/<my_block>". | ||
*/ | ||
gui.addSource(new DirectoryLister("blocks", "block/")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still wrong. gui
doesn't exist, and blocks
is never used.
// Registers the new `SpriteSourceProvider` | ||
// The fisrt parameter is `true` because Texture Atlases are client | ||
// resources and we know that this event is only fired for client resources | ||
generator.addProvider(true, new MySpriteSourceProvider(packOutput, lookupProvider)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume we recommend using createProvider
now instead of using this.
Add documentation on texture atlases under
Resources > Client > Textures