Stacking issues when trying to implement craftable coins

I’ve found a few posts talking loosely about this, but nothing concrete so I thought I’d start a dedicated thread.

The inability to convert gold bars into coins and vice versa has been bugging me for a while, so I decided to try and mod it in and promptly ran into two issues that seem to make using gold as a crafting ingredient cumbersome at best:

  • When specifying a requirement of 80 loot:gold for crafting an ingot, the game reads this as 80 stacks.
    Not sure if it technically requires 80 full stacks, but since there is no obvious way of splitting gold stacks that seems somewhat irrelevant. So my question is: is it possible to use a partial stack in a recipe? If not, would it be possible to implement?

  • When specifying loot:gold as the product of a recipe, the game produces a full stack.
    Basically the reverse of the above problem, hence the reverse question - is it possible to produce a partial stack from a recipe?

Generally, I don’t quite understand the ‘stacks’ attribute.
When does the game consider a stack to be one item and when is it considered to be items? For example, the vegetable stew requires 3 vegetables. Does this mean 3 baskets or 3 individual vegetables? How would one go about obtaining/addressing individual items from a stack?

Something of a tangent, but when researching how to do this I couldn’t seem to find a way to make a recipe produce more than one item. This seems like it could be a useful feature.

Producing more than one item is pretty easy. In my own mod, I have a recipe that creates 2 columns from one recipe. The code looks like this:

         "item" : "tuhalu:furniture:gold_plate_column_half",
	 "item" : "tuhalu:furniture:gold_plate_column_half"

Hrm. Never tried just duplicating the item line, I just experimented with different arguments along the lines of count. Good to know, thanks!

The terms used with monetary gold are a bit confusing.

Each pile of gold is defined as an object with the alias stonehearth:loot:gold, which can be found in stonehearth/entities/loot/gold/.

In gold.json, it has a component stonehearth:stacks which defines how much you can fit in the one object and is currently set to 1000.

In the lua code, when they refer to “stacks”, they are usually talking about how many items are being stacked, not the stack itself!

Edible food is similar to gold in that it has a stonehearth:stacks component which defines how many servings it has. For instance, a Carrot Basket has a value of 6. This means it can be eaten from 6 times and on the 6th time, the item will be destroyed. However, if you want to use a Carrot Basket in a recipe (Veggie Stew for instance), it really doesn’t care how many “stacks” are still left in the stack. It just uses the whole basket (as far as I know).

I think you’ll find the same case with gold. For every stonehearth:loot:gold item you require, the recipe will consume an entire stack. Using “count” just means you require more items, not individual coins.

I may be wrong (and I’ve only just had a look for a couple hours just now), but it seems like interactions with the number in a stacks component only occur at the level of lua code.

For gold, the game has a set of functions that handle adding and subtracting gold from the world. The adding function ensures that any partially full objects are first filled before creating a new object. The subtracting function ensures that partially full objects are the first to be taken from (and potentially destroyed) before removing from a full gold item. This is there to ensure that gold is always stacked as fully as possible, but it means that recipes can’t be allowed to make partial stacks, only full stacks.

The opposite problem is that there may be no way to ensure that only full stacks of gold are used in recipes, so you have no way of ensuring that a 1000g loot:gold is used instead of a 5g loot:gold. I’m not absolutely sure about this though. Maybe someone else will know better!

1 Like