architectury / architectury-api

An intermediary api aimed at easing development of multiplatform mods.
https://discord.architectury.dev/
GNU Lesser General Public License v3.0
306 stars 55 forks source link

[Feature] Add `getEntries()` method to `DeferredRegister` #510

Closed moritz-htk closed 1 month ago

moritz-htk commented 1 month ago

I propose adding a getEntries() method to the DeferredRegister class. This method would allow retrieving all entries from the DeferredRegister at once instead of calling each one individually.

Add the following method to the DeferredRegister class:

    public Collection<RegistrySupplier<T>> getEntries() {
        return entryView;
    }

With this method, it would be possible to streamline operations in datagen, for example:

    @Override
    protected void registerModels() {
        MFItems.ITEMS.getEntries().stream().map(RegistrySupplier::get).forEach(this::basicItem);
    }

Without this method, each entry must be written individually, as shown here:

    @Override
    protected void registerModels() {
        basicItem(...)
        basicItem(...)
        basicItem(...)
        basicItem(...)
        basicItem(...)
    }

I have tested this implementation and it works as intended.

shedaniel commented 1 month ago

it extends Iterable already, you can just for loop it, for example:

for (RegistrySupper<Item> item : MFItems.ITEMS) {
    basicItem(item);
}