Skip to content
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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion docs/gui/screens.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The second `#blit` adds an additional integer at the end which represents the ti

#### `blitSprite`

`#blitSprite` is a special implementation of `#blit` where the texture is written to the GUI texture atlas. Most textures that overlay the background, such as the 'burn progress' overlay in furnace GUIs, are sprites. All sprite textures are relative to `textures/gui/sprites` and do not need to specify the file extension.
`#blitSprite` is a special implementation of `#blit` where the texture is written to the GUI [texture atlas][txtatlas]. Most textures that overlay the background, such as the 'burn progress' overlay in furnace GUIs, are sprites. All sprite textures are relative to `textures/gui/sprites` and do not need to specify the file extension.

```java
// Points to 'assets/examplemod/textures/gui/sprites/container/example_container/example_sprite.png'
Expand Down Expand Up @@ -424,3 +424,4 @@ private void registerScreens(RegisterMenuScreensEvent event) {
[component]: ../resources/client/i18n.md#components
[keymapping]: ../misc/keymappings.md#inside-a-gui
[modbus]: ../concepts/events.md#event-buses
[txtatlas]: ../resources/client/textures/atlases.md
98 changes: 98 additions & 0 deletions docs/resources/client/textures/atlases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Texture Atlases

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).

## Texture Atlas Sources

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.
Copy link
Contributor

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?

Copy link
Contributor

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?


As of today 14 different atlas sources can be declared:
Copy link
Contributor

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.


|File 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|

### 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`.
Copy link
Contributor

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?


The file named the same as the altas it is appending to, will then describe what file will be added to the atlas:
```json
Copy link
Contributor

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.

-- Inside gui.json
{
"sources": [
-- Gather all sprites within the "source" folder
{
"type": "minecraft:directory",
"prefix": "",
"source": "gui/sprites/widgets"
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean? What is prefix doing? Is the folder the default namespace or any asset pack?

},
-- Gather sprites within the "icons" spritesheet
{
"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
}
]
}
Copy link
Contributor

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.
Copy link
Contributor

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.



## 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:

```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 ()
Copy link
Contributor

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.

{
// 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", ""));
Copy link
Contributor

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?

}
}
```
Copy link
Contributor

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.


[reg]:../../../concepts/registries.md
[dtgn]:../../index.md#data-generation
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ To actually be animated and not just be displayed as a distorted texture, there
}
```

[rl]: ../../misc/resourcelocation.md
[rl]: ../../../misc/resourcelocation.md
8 changes: 5 additions & 3 deletions docs/resources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Resource packs may contain folders with files affecting the following things:

| Folder Name | Contents |
|---------------|-----------------------------------------|
| `atlases` | Texture Atlas Sources |
| `atlases` | [Texture Atlas Sources][txtatlas] |
| `blockstates` | [Blockstate Files][bsfile] |
| `equipment` | [Equipment Info][equipment] |
| `font` | Font Definitions |
Expand Down Expand Up @@ -88,7 +88,7 @@ All data providers extend the `DataProvider` interface and usually require one m
| [`LanguageProvider`][langprovider] | `addTranslations()` | Translations | Client | Also requires passing the language in the constructor. |
| [`ParticleDescriptionProvider`][particleprovider] | `addDescriptions()` | Particle definitions | Client | |
| [`SoundDefinitionsProvider`][soundprovider] | `registerSounds()` | Sound definitions | Client | |
| `SpriteSourceProvider` | `gather()` | Sprite sources / atlases | Client | |
| [`SpriteSourceProvider`][spritesourceprovider] | `gather()` | Sprite sources / atlases | Client | |
| [`AdvancementProvider`][advancementprovider] | `generate()` | Advancements | Server | Make sure to use the NeoForge variant, not the Minecraft one. |
| [`LootTableProvider`][loottableprovider] | `generate()` | Loot tables | Server | Requires extra methods and classes to work properly, see linked article for details. |
| [`RecipeProvider`][recipeprovider] | `buildRecipes(RecipeOutput)` | Recipes | Server | |
Expand Down Expand Up @@ -229,5 +229,7 @@ runs {
[sounds]: client/sounds.md
[tags]: server/tags.md
[tagsprovider]: server/tags.md#datagen
[textures]: client/textures.md
[textures]: client/textures/index.md
[translations]: client/i18n.md#language-files
[txtatlas]: client/textures/atlases.md#texture-atlas-sources
[spritesourceprovider]: client/textures/atlases.md#datagen