[MOD] Miner mod

@law Good Work, :slight_smile: Glad to see another modder.

Edit :
@law please ignore this, while it’s a good tutorial for adding other classes that don’t exist, it is not needed for your miner :wink: . It came down to another mod that was causing the errors, sorry for any confusion :wink:

I was unable to promote a worker to the miner during my testing, this I believe this has to do with the fact you haven’t made your miner entity visible to the game, and haven’t mixedinto the jobs index.

You’ve aliased out the miners equipment and such but not the miner himself, you will need to add an alias to your manifest.json

"aliases" : {
    "jobs:miner" : "file(jobs/miner"),

Then in /miner/jobs/miner/miner_description.json change

"alias": "stonehearth:jobs:miner",

to

"alias": "miner:jobs:miner",

Next take a look at /stonehearth/jobs/index.json, it’s a listing of all professions in the game, you need to mixin your miners alias into that list. I am guessing I don’t need to explain this as you’ve done the carpenter recipe mixins and such

Finally comes the tricky part to all of this, the promotion screen. As of now the promotion screen has hard coded positions for all the icons you use to promote citizens to professions. Your profession doesn’t exist in the list so it will error when trying to find the position for your miner icon. You have a few options here.

  1. override /stonehearth/ui/game/promotion_tree/promotion_tree.js, and edit

     self._layout = {
       'stonehearth:jobs:worker' : {x: 372 , y: 244},
       'stonehearth:jobs:carpenter' : {x: 542 , y: 159},
       'stonehearth:jobs:mason' : {x: 542 , y: 244},
       'stonehearth:jobs:blacksmith' : {x: 542 , y: 329},
       'stonehearth:jobs:weaponsmith' : {x: 542 , y: 414},
       ....
       'miner:jobs:miner', : {x:542 , y:265},
    

    Play around with x,y values to get it into the right position.
    While doing things this way might be easy, it will lead to compatibility problems with other mods that are adding classes.

  2. Use Jelly. Jelly does the base game modfications to allow for multiple mods to add professions to the game.Download here. you’ll have to rename the download to just, jelly. It’s a SH mod so put it in your mods folder. You will also have to extract it out of the .zip, SH will not load .zip.

    If you choose to go this route, you will need to add a .js file to your mod. Add this to that file…

     $(top).on('jelly.PromotionTreeLayout', function (e, layout) {
       layout['mymod:jobs:myclass'] = {
    	    x:375, y: 500
       };
     });
    

    Change mymod:jobs:myclass to alias your miner.

    Jelly creates an event 'jelly.PromotionTreeLayout. The idea here is listen in on the event, then modify _layout to include a definition for your profession.

    Last step here would be to reference the .js in your manifest.

     "ui" : {
          "js" : [
             "file(ui/add_to_promotion_tree.js)"
        ]
     }
    

This might be a bit much to understand, let me know if you need further explanations.
Again great work… :slight_smile:

5 Likes