Architectury API (Fabric/Forge/NeoForge)

Architectury API (Fabric/Forge/NeoForge)

170M Downloads

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

moritz-htk opened this issue ยท 1 comments

commented

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.

commented

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

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