Skip to content

Add support for item variants#101

Open
Rover656 wants to merge 2 commits intoBuuz135:1.21from
Rover656:feat/item-variants
Open

Add support for item variants#101
Rover656 wants to merge 2 commits intoBuuz135:1.21from
Rover656:feat/item-variants

Conversation

@Rover656
Copy link
Copy Markdown

See #80 for problem description.

The first commit was my initial attempt at adding support for components by simply declaring which components should be copied, however I decided to re-do this change instead by adding an API for specifying item variants.

The idea here is to allow mods to declare items which have variants based on item data - For example, this is what the Ender IO compat would look like:

new IItemVariantProvider() {
    @Override
    public String getVariantKey(ItemStack stack) {
        var conduit = stack.get(EnderIODataComponents.CONDUIT);
        if (conduit == null)
            return "";

        return conduit.getRegisteredName();
    }

    @Override
    public ItemStack normalize(ItemStack stack) {
        ItemStack result = stack.copy();
        if (stack.has(EnderIODataComponents.CONDUIT)) {
            result.set(EnderIODataComponents.CONDUIT, stack.get(EnderIODataComponents.CONDUIT));
        }

        return result;
    }

    @Override
    public Set<ItemStack> getVariants(HolderLookup.Provider registries) {
        var conduits = registries.lookupOrThrow(EnderIORegistries.Keys.CONDUIT);
        return conduits.listElements()
                .map(i -> ConduitBlockItem.getStackFor(i, 1))
                .collect(Collectors.toSet());
    }
};

This is a very rough draft to seek approval and input before polishing this up :) Hopefully you're happy with this approach.

import java.util.Set;
import java.util.stream.Collectors;

// TODO: Should cache results.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Will handle this if you're happy with the idea :)

@Rover656
Copy link
Copy Markdown
Author

We could also potentially consider adding mod compat (like Ender IO) into Replication itself, but I don't want to drop other mod code into your mod unless you're happy with that :)

@Rover656
Copy link
Copy Markdown
Author

Discovered a crash when clicking on matter types in the terminal (Non [a-z0-9/._-] character in path of location: enderio:conduitenderio:rs), need to change how it reads the 'variants'. Will do that soon

@Buuz135
Copy link
Copy Markdown
Owner

Buuz135 commented Feb 22, 2026

I will check it out soon, any change to the recipe calculation scares me

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants