Paper icon indicating copy to clipboard operation
Paper copied to clipboard

For new registry values, allow copying from existing

Open Machine-Maker opened this issue 1 year ago • 0 comments

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 avatar Dec 09 '24 01:12 Machine-Maker