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

Smarter Registry System #26

Merged
merged 5 commits into from
Oct 30, 2023
Merged

Conversation

GiantLuigi4
Copy link
Contributor

@GiantLuigi4 GiantLuigi4 commented Oct 30, 2023

Unsure if there are potential problems with it

I've tested it with a couple of of weird config setups, and it seems to work fine

Usage looks like this:

        Toml toml = new Toml("Registry config");
        toml.addCategory("Registry configs for blocks", "registry.blocks");
        TomlConfigHandler handler = new TomlConfigHandler("modid", toml);
        Toml blockRegistry = handler.getRawParsed().get(".registry.blocks", Toml.class);

        BlockHelper.reserveRuns("modid", blockRegistry, 8 /* this can change as needed */, (ids) -> {
            BiFunction<String, Material, Block> blockCreator = (key, material) -> new BlockBuilder("modid").build(new Block("modid.block." + key, ids.next(), material));

            Block stone      = blockCreator.apply("stone", Material.stone);
            Block ice        = blockCreator.apply("ice", Material.ice);
            Block cactus     = blockCreator.apply("cactus", Material.cactus);
            Block cake       = blockCreator.apply("cake", Material.cake);
            Block explosive  = blockCreator.apply("explosive", Material.explosive);
            Block dirt       = blockCreator.apply("dirt", Material.dirt);
            // removed, but still reserved to avoid block transmutations
            // bta/beta mc itself does this
            ids.next();
            Block cloth      = blockCreator.apply("cloth", Material.cloth);
            handler.writeConfig();
        });

This system works in a multistep process

  • collect reservations from mods based off provided TOML categories
  • run configuerd legacy reservations (prevents id overlap with existing mods that used the legacy system but haven't updated yet)
  • run reservation based registration
  • run unconfigured legacy registration (assumed to be able to automatically respond to the reservation system, as it's assumed to calculate ids based off unregistered slots)

Once a function provided in reserveRuns has reached its last id, it updates the TOML instance with the runs

If the function doesn't grab as many ids as it requested, or if it grabs more ids than it requests, an error will be thrown

@MartinSVK12 MartinSVK12 merged commit f88ee51 into Turnip-Labs:1.7.7.0 Oct 30, 2023
2 checks passed
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