Moai personal thread

Hehe, oops. You found the javascript guy. (16.7 KB)

And, to reiterate, user_settings.json:

"logging" : {
	"show_console" : true,
	"mods" : {
		"cannonade" : 9

Thank you very much for the help!

Probably should’ve said what the mod does. Using debug tools, stamp down a cannonade:artillery, select it, and try using its custom command. You can right or left click to get rid of the banner. Clicking the button should output the logs.

I don’t know what to tell you, it works perfectly for me…

| client |  0 |                             mod cannonade | hello world
| client |  1 |                             mod cannonade.test | [] hello again
| client |  0 |                             mod cannonade | resolving

I used it without modifying it and just added in the logging info in my user settings.

Ugh! <_____>

Let me PM you my user settings whole. Maybe you can diff them and there’s something really dumb I’m missing?

When Archers use them appropriately, yes. They don’t always do that (yet).

1 Like

Cautiously loving the new conversations update.

1 Like

Mod Maintenance

So I’ve just released my first mod, yay! The theory was rather simple, but the execution took far longer than I would have liked. Every programmer, naturally, is familiar with hunting for a missing semicolon for 6 hours, but it’s so much worse when you don’t even realize that you’re looking for a missing semicolon. Oh well, it’s out there now, and as of this writing, Steam is showing 120 subscribers, so I personally consider that a resounding success.

But what now? I’ve got lots of features that I want to add, but at this point, the deployment alone will take me a solid half an hour – package into smod, upload to dropbox, upload to github, update the Steam upload, update the Discourse post about the mod, update the Steam description, update Github readme (once I actually write that)… and I have to do this every time there’s an update or a bugfix. Sure am wondering if there can’t be a method to automate all this updating, but right now, I’m too excited about making more mods to write such a tool. Blah. Any other modders have any advice on this?

Miner Overview

I’ve included a Github link for my mod, so that anyone who wants to use it as a reference for their own miner class, or a different profession. The very basic idea was a modification of Radiant’s dig_adjacent_action.lua. Normally, when Hearthlings dig, they execute a single “work” animation (the strike of a pickaxe), then as soon as they do, they pick up a single block. I re-wrote this to require a certain number of work animations to start with, but after those are completed, the Hearthling can now pick up a number of blocks without striking them. It doesn’t look 100% as good as regular mining does, yet (especially when the miner decides to mine vertically, rather than horizontally), but it definitely achieves the goal I was aiming for – having a faster mining profession. This, the very core of the mod, was, incidentally, by far the easiest part of writing it. However, simply by modifying an existing lua file, a) we don’t actually have a mod yet, b) everybody and their cat can now do fast mining, rather than just the miner.

MoAI, MoProblems

The far more difficult part, then, was packaging the fast mining action into a profession, and then integrating that profession into the game properly. We need to make a distinction between the mining that all other hearthlings do, and the mining that the miner does, so I made a separate set of actions for fast mining. I copy-pasted stonehearth/actions/mining folder and made my modifications to it. When you want some specific class of Hearthlings to be able to execute a set of actions, you create an AI Pack for it, and tell your class that it’s allowed to use that AI pack. So I did that, and injected the pack into my miner. But now, the issue is that when I create a Mining Zone, only regular Hearthlings go to mine it! For some reason, my miner didn’t “know” that you’re supposed to go to a mining zone and mine it.

That took me a bit of investigation to figure out. There exists a file called town.lua, which essentially describes the functioning of your in-game community. This includes creating so-called “task groups”, which are, as the name suggests, groups of tasks that are unified by purpose. The game appears to do this in order to be able to orchestrate large numbers of hearthlings quickly towards a specific task. Mining for the sake of mining is one such task group, another one is mining out a foundation for a building, another one yet is for creating a building. This way, if the game has multiple definitions for, say, “mine”, it can have the freedom to say: “all hearthlings who can mine, go to that place and mine those blocks. I don’t care how you do it, but those blocks have got to go.”

The way you specify that a task does the same thing as another task is just like that – through the does attribute of a task. This was the mistake that cost me hours to fix. I thought that by giving everything a name that would be unique to my mod would decrease the likelihood of mod conflicts in the future. In so doing, I totally failed to realize that names are part of how Stonehearth identifies the various entities and events that take place within it. So instead of saying that my miners are able to do miner_prof:mine_fast, which Stonehearth has no clue what it is, I had to say that they are indeed capable of stonehearth:mine action definition. From that point on, I differentiate into my action (dig_fast_action.lua and dig_fast_adjacent_action.lua). Now Stonehearth knows that Miners are also capable of executing the “mining” task group, and it asks them to do so when a mining task is available. When the Miners actually receive the request, they go and use their own mining ability, rather than the standard Stonehearth one that most Hearthlings have; this is not something the game has to ask them to do specifically, it’s simply the only action they can perform that fulfills the stonehearth:mine request.

Additional documentation
Official Stonehearth modding guide
In-depth look at AI


I can’t believe how easy and forgiving this game is in modding. Making my pickaxe glow as a test for a Lantern item only took adding a lamp_component to it. Wowowow


Hrm, that statement seems ironic after I spent 10 hours bashing my head against the wall over what I thought was a trivial issue. Oh well. as they say, back to work :muscle::muscle:

Making an item portrait

I saw a thread asking on how to create portraits. I feel like there used to be a thread or a dev stream at some point about how to make these, but I can't find it right now, so I thought I would share my method, using all free software. I have used a less good variation of this method while creating the portraits for the Miner mod, which I hadn't perfected until after I was done with all the items. They still don't look 100% like Radiant's, but close enough for my purposes.

I use free software for my modding work. You will need to get these, if you do not have them already:

Step 1: Export model
I’ll skip the creation of the model here, and will assume you already have a model ready to go. You will need to open VoxelShop and import (ctrl+i) your model’s qb file. I’ll use Radiant’s footman outfit for this. Import it, and you will see something like this:

Next, we’re going to merge all the visible layers, and use the selection and camera controls to move the model as much in the center of the wireframe cage as we can. When finished, press the Move Selection button to confirm the move:

OK, now we’re going to press Esc to remove the selection and the Reset View button in our 3D view screen to put it on a standard angle, turn off the wireframe to prepare it for export:

Press Ctrl+Shift+e to open the export window. Select export to “png” (render), turn OFF render depth map, and export the file to your chosen location.

Step 2: Crop and add outline
Now we will open the exported PNG file for editing in (don’t click that link, it’s some guy’s paint selling website, this forum just likes to format things in fun ways). Use the Rectangular Select tool to get a close cropping (with ~20 pixels breathing space on the sides) of your model, and press the Crop to Selection button when you’re satisfied.

We need to duplicate the background layer, and move our duplicate to the bottom, making sure we’re always working with the duplicate. Once it’s on the bottom, go to Effects > Stylize > Outline, and turn the thickness to 5 and intensity to 100.

Now we just need to colour the outline black. Making sure your bottom layer is still selected, go to Adjustments > Curves, and drag that top point down to the bottom right:

After pressing OK, you are now good to Save As… > png, and save it with the default settings. It will ask you to flatten layers, say yes. Here’s what should come out:


I love this game


Random thought: right now, Radiant divides up armor into default and female variants. A great way for Radiant to get into the news for free would’ve been to have default and male variants. Also, less typing for coders = more lines per hour!

@malley @max99x do you guys ever fall asleep thinking of the input/output bin mini-items solution and grin to yourself because of how clever you are? Because my goodness is this clever. My head is spinning.


lol, I have not before, but maybe I will now ; )


Does anybody know how a component that’s sitting on a piece of equipment can address the entity that’s holding it from within the component lua file?

Components can retrieve the entity that has them via


The equipment_piece component then has a function to retrieve the entity that equipped it:

function EquipmentPieceComponent:get_owner()
   return self._sv.owner
1 Like

well I’m not you @Moai, but i thought this might be nifty to share:
i nicked some code from the goblins and made made a shield in such a way that it doesnt have a print when its still stored, but as soon as they pick it up they have options on different prints, so your fighters get their own little recognisable shields :slight_smile: …unless they all pic mostly the same anyway because i only made 3 models to test from BUT THE CONCEPT WORKED

(snippet from the shields .json, the : wooden_round_shield_empty.qb is literally an empty field, lol.)

“components”: {
“model_variants”: {
“default”: {
“models”: [
“type”: “one_of”,
“items”: [

1 Like

Excellent work! Stonehearth is funny, some things that you’d think are really difficult to do, like turn a sword into a glowing sword, or create a completely new piece of equipment (I’m working on a proper backpack for the miner), are actually pretty easy. Then you get to things that SHOULD be easy, like getting a hearthling’s gender, and suddenly, things become nontrivial.

Keep up the good work, and make sure to not let your experiments stay just that – when you think you’re ready, pack it right up into an SMOD and either drop it here or over to Steam.

1 Like

well my viking mod is already on steam :slight_smile: this was for the round shields.
already have a function axeal (that needs better art) and an actual honest to god +ulfber+t sword moddeld(much better then the axe) and functional, just thought i’d put some other cool stuff in before i update it again

but after ive got some more stuff in it i think ill make a thread here to to show it off a bit more :slight_smile:

1 Like

Yo Radiant (@sdee @max99x)

Can we get a new JSON file, the SLOT_TO_BONE_MAP constant from equipment_piece_component.lua and all related places that use similar data? I’m a bit bummed about having to override the entire lua file just to have to add one itty bitty line of data to it. It’s not even code! Just a string! Plz ilu radiant :heart:

1 Like

Sure. It’ll be in constants.json in the next release.