Greymerk / minecraft-roguelike

This is a mod for minecraft that adds randomly generated dungeon complexes.
GNU General Public License v3.0
130 stars 53 forks source link

Adding Support for Other Mods to Register Their Own Loot Providers? #143

Closed AWBuchanan7 closed 5 months ago

AWBuchanan7 commented 6 years ago

For some context: I'm working on a mod that adds a set of upgradable weapons (and a set of crystals "crafted" into them to upgrade them) to the game, and in play-testing I've found Roguelike Dungeons' chests is a fantastic way of distributing these weapons and crystals to the player. This is because, for example, I can place a slightly more powerful version of the same weapon on the next deeper level in the dungeon, or I can place a more valuable crystal on a deeper level, etc.

Because of the involvement of NBT data in the state of the weapon I add them programmatically through some personal tweaks to the actual Roguelike Dungeons mod. However, I'd ultimately love to add support for this in a method I could package and release in my own mod.

The solution that becomes apparent to me would be if there was a means for me to "register" my own "Loot Provider". As things are I can add Roguelike Dungeons as a dependency and extend the ItemBase class, creating my own "Loot Provider" however I'm not able to add my custom ItemBase implementation to the SettingsLootRules class (as far as I can tell at least).

I've actually implemented a solution for this here: https://github.com/BWBuchanan7/minecraft-roguelike that appears to work quite well.

Any interest in adding this?

Greymerk commented 6 years ago

Yeah, I've been thinking it'd be cool to add some sort of API for mod support. I'll take a look at what you have.

Greymerk commented 6 years ago

I just spent a bit of time looking at what you did, and I suspect that it wouldn't be as flexible and extensible as it could be. I think what would work much better is if you could add new DungeonSettings with appropriate criteria. If all you want to do is add loot, then you'd add a Setting with loot rules, containing whatever you want to add.

I'd need to add a custom settings registry for mods to target, but that wouldn't be too difficult.

AWBuchanan7 commented 6 years ago

I had a pretty good hunch you might see a better way of doing this. Will definitely be following to see if you do end up implementing a custom settings registry!

Greymerk commented 6 years ago

I had an idea which I figure might be more useful in general for modding support. I've split dungeon generation into stages with associated generation tasks. Layout, Encase, Tunnels, Rooms, Segments, Links, Tower, Filters, Loot.

The idea is that you design your own task and inject it into the pipeline, and then your task will be executed whenever a dungeon is generated.

I made a simple example mod that adds a totem of undying to every chest and it worked nicely.

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        DungeonTaskRegistry tasks = Dungeon.getTaskRegistry();
        tasks.addTask(new DungeonTaskDemo(), DungeonStage.LOOT);
    }
public class DungeonTaskDemo implements IDungeonTask {

    @Override
    public void execute(IWorldEditor editor, Random rand, IDungeon dungeon, ISettings settings) {
        List<ITreasureChest> chests = dungeon.getChests();
        for(ITreasureChest chest : chests){
            ItemStack totem = new ItemStack(Items.TOTEM_OF_UNDYING);
            chest.setRandomEmptySlot(totem);
        }
    }
}
AWBuchanan7 commented 6 years ago

This looks excellent! I'll be adjusting my mod accordingly this weekend. I'm quite excited that you've implemented this, I do look forward to utilizing this for some enhanced cohesion between our mods!