Skip to content

For new registry values, allow copying from existing#11724

Closed
Machine-Maker wants to merge 2 commits intomasterfrom
feature/reg-mod-copy-from
Closed

For new registry values, allow copying from existing#11724
Machine-Maker wants to merge 2 commits intomasterfrom
feature/reg-mod-copy-from

Conversation

@Machine-Maker
Copy link
Member

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

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().register(NEW, EnchantmentKeys.POWER, builder -> {
            builder.maxLevel(10);
            builder.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 9, 2024 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants