Skip to content

Optional resource#5781

Open
leagris wants to merge 65 commits intomasterfrom
OptionalResource
Open

Optional resource#5781
leagris wants to merge 65 commits intomasterfrom
OptionalResource

Conversation

@leagris
Copy link
Contributor

@leagris leagris commented Jan 26, 2026

Reviewers: Here are some Notes to help your with this large PR


Instead of having thousands copy of the empty icon, 4 different copies of the RENDERING_ERROR and its overlay this patch replace all of these by internal already existing versions from the texture atlases.

It saves a huge amount of atlas space which in term also save a good amount fo the VRAM on the GFX card.
Incidentally, the ultimate best optimized texture is the texture than you can delete entirely.

Now blocks icons can declare their resource file optional, if so, when resource file is not available, it will fall back to a single reference to the fully transparent texture from the vanilla atlas, not even loading a resource from disk.
BlockIcon with Overlay defaults to optional resources.
All ItemIcons now default to optional resources.

An optional icon, even if not present in the JAR, might still be provided by Resources Pack. This now gives entire freedom for Resource Pack creator to provide the OVERLAY or GLOW OVERLAY they like on any face if it fits their style.

Deduplication of runnable custom icons registration, combined with the removal of empty png files, reduces the texture load/reload time by 13% (F3+t tested 2.6s on master branch, 2.3s on this OptionalResource branch), this on a system with a very fast SSD. System with slower disk access will notice an ever greater speed gain.

Now features an icons registration log file that can be activated:

config/GregTech/GregTech.cfg:

debug {
        # Enables logging of icons registration. (May help resource-pack creators) [default: false]
        B:logRegisterIcons=true
}

logs/RegisterIcon.log:

*****************************************************************
* This is the log of texture icons registered in GT5-Unofficial *
* First column R|O tells if resource is (Required or Optional)  *
* Second column is the resource path                            *
*****************************************************************
R gregtech:textures/items/iconsets/MORTAR.png
O gregtech:textures/items/iconsets/MORTAR_OVERLAY.png
R gregtech:textures/items/iconsets/ROLLING_PIN.png
O gregtech:textures/items/iconsets/ROLLING_PIN_OVERLAY.png
R gregtech:textures/items/iconsets/HANDLE_SWORD.png
O gregtech:textures/items/iconsets/HANDLE_SWORD_OVERLAY.png

API Breaking Change in GT5U (GTNH fork): CustomIcons & Textures Enum

In an upcoming GT5U release (see PR: #5781), the following API changes are introduced:

  1. CustomIcons constructors are deprecated
    Direct instantiation will soon become impossible (the implementation classes will move to a non-public/internal package).
    Reason: Bypasses caching, deduplication, and compile-time distinction of optional base textures.

    Use the static factory methods instead:

    • BlockIcons.custom(String) → base required
    • BlockIcons.customOptional(String) → base optional (falls back to invisible)
    • BlockIcons.customAlpha(String) → base required, rendered in pass 1
    • ItemIcons.custom(String) → base or overlay required

    Migration steps:

    • Replace new CustomIcon(name) with the appropriate factory above
    • Change field/variable types from CustomIconIIconContainer
  2. Deprecated enum constants in Textures.ItemIcons and Textures.BlockIcons

    • NULL → use GlobalIcons.VOID
    • RENDERING_ERROR → use GlobalIcons.RENDERING_ERROR

    Applies to both ItemIcons and BlockIcons (identical names, same replacements).
    GlobalIcons entries are unified and safe for items and blocks.

    The old constants remain available during this transition release but will be removed in a future release.

Migration examples:

// Old (deprecated)
new CustomIcon("gregtech:icons/something");
TextureFactory.of(Textures.ItemIcons.NULL);
TextureFactory.of(Textures.BlockIcons.RENDERING_ERROR);

// New (recommended)
BlockIcons.custom("gregtech:icons/something");          // or ItemIcons.custom(...)
TextureFactory.of(GlobalIcons.VOID);
TextureFactory.of(GlobalIcons.RENDERING_ERROR);

Validated tests:

  • runClient, runClient25
  • runServer
  • Updated API dependency on the HydroEnergy project
  • Full pack

Notes for reviewers

3553 affected files?

This PR deletes 3459 PNG files. (Don't worry, those are all blank or error icons, now replaced by internal fallback)

Features

Main changes:

The src/main/java/gregtech/api/enums/Textures.java class is where all of the important changes occurs.

  • Internal BlockIcons and ItemIcons enum classes have been refactored to standard final classes with the same backward-compatible constant names and IIconContainer type.
  • IIconContainer and Runnable implementations have been entirely removed from the API realm and moved to the internal gregtech.client.iconContainers package.
  • Decorator deprecated classes for CustomIcons have been provided for backward-compatible new instanciation, while helping the migration to the new implementation-free factory methods.
  • The VOID and RENDERING_ERROR IIconContainer constants now refers to internal implementations which do not use a PNG resource file.

Displaced implementations

These classes now internally provide both the IIconContainer and Runnable implementations within the gregtech.client.iconContainers package:

src/main/java/gregtech/client/iconContainers/blocks/AbstractBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/blocks/GTBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/blocks/GTCustomAlphaBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/blocks/GTCustomBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/blocks/GTCustomOptionalBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/blocks/GTOptionalBlockIconContainer.java
src/main/java/gregtech/client/iconContainers/items/AbstractItemIconContainer.java
src/main/java/gregtech/client/iconContainers/items/GTCustomItemIconContainer.java
src/main/java/gregtech/client/iconContainers/items/GTItemIconContainer.java

Cascaded changes

Updated 83 classes to use to the new Textures Blocks or Items custom icons factories instead of the new deprecated CustomIcons instanciations.

- Removed 217 fully transparent PNGs from `blocks/iconsets`.
- Optimized `blocks/iconsets/VOID.png` to 1 pixel (126 → 80 bytes).
- Updated the `BlockIcons` enum to use an optional fallback to `VOID.png`.
  This saves VRAM in the texture atlas while still allowing resource packs
  to override the icons if they provide their own resources.
Making basic machines overlay textures optional allowed the removal of
575 fully transparent PNGs.
Allowed the removal of 149 fully transparent PNGs.
Items might not have icon resources.
If a resource is absent, the item uses the VOID icon, which is fully
transparent.
This allowed the removal of 2511 empty PNGs.
Rather than implementing several copies of VOID and ERROR_RENDERING textures,
reuse thos already provided by the vanilla Texture Atlas Map
Allow GTPlusPlus to register item icons with Optional Resource assets
and fallback to Global VOID icon.
@leagris leagris added the Refactor For PRs rewriting a part of the code to have a nicer code overall. label Jan 26, 2026
@leagris leagris marked this pull request as ready for review January 27, 2026 16:17
@leagris leagris requested a review from sisyphussy January 28, 2026 00:16
@Nikolay-Sitnikov
Copy link
Contributor

Nikolay-Sitnikov commented Feb 10, 2026

I didn't mean to add these empty PNG to our repo. Merely an option to generate them locally

Generate them locally where? Plus, 3000+ empty PNG files isn't any less scary than 3000+ lines of text.

I mean, make all resources optional

I believe the only practical difference between required and optional assets is whether they get replaced with the magenta/black missingno texture, or a transparent empty texture. In this way, required assets are only there for the ease of finding bugs.

@leagris
Copy link
Contributor Author

leagris commented Feb 10, 2026

I mean, make all resources optional

Lower layer of block icons cannot be optional or it would make the block invisible and x-ray.
Both layers of item icons cannot be optional.

For helping resource-pack creators, the processable list of textures is perfectly usable to create dummy files and directories. It is as simple as this one-liner I used in 30s:

< logs/RegisterIcon.log awk -F: '/^O/{ print "assets/gregtech/"$2 }' | xargs -l1 install -D dummy.png 

LazyFleshWasTaken and others added 19 commits February 11, 2026 15:51
Co-authored-by: VortexSo4 <kreker.maxim@mail.ru>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
…nipulator. (#5853)

Co-authored-by: lc-1337 <62835225+lc-1337@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
…modules (#5828)

Co-authored-by: VortexSo4 <kreker.maxim@mail.ru>
Co-authored-by: chrombread <119648279+chrombread@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: UltraProdigy <187078471+UltraProdigy@users.noreply.github.com>
Co-authored-by: Pxx500 <81298696+Pxx500@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: Pxx500 <pbartulik@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: kuba6000 <kuba.123123.6000@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: VortexSo4 <kreker.maxim@mail.ru>
Co-authored-by: Jakub <kuba.123123.6000@gmail.com>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Co-authored-by: VortexSo4 <kreker.maxim@mail.ru>
Co-authored-by: Martin Robertz <dream-master@gmx.net>
@Dream-Master Dream-Master added 🚧 Testing on Zeta Do not merge yet, testing this PR on Zeta ❌ There is a merge conflict with another PR There is a merge conflict with another PR, so it can not be tested in Dev at this time. and removed 🚧 Testing on Zeta Do not merge yet, testing this PR on Zeta ❌ There is a merge conflict with another PR There is a merge conflict with another PR, so it can not be tested in Dev at this time. labels Feb 13, 2026
@leagris
Copy link
Contributor Author

leagris commented Feb 16, 2026

@Dream-Master Merge conflicts from other PRs now resolved

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

Labels

Refactor For PRs rewriting a part of the code to have a nicer code overall.

Projects

None yet

Development

Successfully merging this pull request may close these issues.