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

For new registry values, allow copying from existing #11796

Merged
merged 5 commits into from
Dec 26, 2024

Conversation

Machine-Maker
Copy link
Member

@Machine-Maker Machine-Maker commented Dec 23, 2024

Replaces #11724


This creates a copy of the power enchant and just changes some things about it. This is useful because you don't have to redefine everything about the other enchant, and it will stay updated to the other enchant's values.

@Override
public void bootstrap(@NotNull BootstrapContext context) {
    // io.papermc.testplugin.brigtests.Registration.registerViaBootstrap(context);

    final TypedKey<Enchantment> NEW = EnchantmentKeys.create(Key.key("mm:test"));
    context.getLifecycleManager().registerEventHandler(RegistryEvents.ENCHANTMENT.freeze(), event -> {
        event.registry().factoryRegistry(
			NEW,
			builderFactory -> builderFactory
				.copyFrom(EnchantmentKeys.POWER)
				.maxLevel(10);
            	.description(text("MOARR POWER")
        );
    });

    context.getLifecycleManager().registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ENCHANTMENT), event -> {
        final PreFlattenTagRegistrar<Enchantment> registrar = event.registrar();
        registrar.addToTag(EnchantmentTagKeys.IN_ENCHANTING_TABLE, List.of(TagEntry.valueEntry(NEW)));
    });
}

@Machine-Maker Machine-Maker requested a review from a team as a code owner December 23, 2024 22:33
@kennytv kennytv added the type: feature Request for a new Feature. label Dec 24, 2024
@Machine-Maker Machine-Maker force-pushed the feature/reg-mod-copy-from branch from 173c5ac to 8551cb2 Compare December 24, 2024 23:55
@Machine-Maker
Copy link
Member Author

Machine-Maker commented Dec 25, 2024

Something I just thought about... perhaps we should "clone" the nms object before pre-filling the builder with it's values. Just so the newly built value doesn't use the instance of all the subtypes. I don't know if it would cause any problems, but to get out ahead of those.

EDIT: Hmm, but it won't be possible with all registry types because only the data-driven ones have direct codecs (you need a direct codec to copy it).

@lynxplay lynxplay force-pushed the feature/reg-mod-copy-from branch from 64e8731 to cca5df2 Compare December 26, 2024 21:29
@Machine-Maker Machine-Maker merged commit af2812f into PaperMC:main Dec 26, 2024
3 checks passed
@Machine-Maker Machine-Maker deleted the feature/reg-mod-copy-from branch December 26, 2024 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: api type: feature Request for a new Feature.
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants