Is it possible to have a resource_loot_table in a renewable_resource_node?

How to make an entity that can be harvested multiple times drop multiple items per harvest?

Simple adding a “resource_loot_table” node to the “stonehearth:renewable_resource_node” isn’t working. Actually, it is giving an error.
But, adding a “resource_loot_table” to a “stonehearth:resource_node” is possible and I’m actually using it in another item. The difference is that a “stonehearth:resource_node” (not the renewable) make it harvestable only once, destroying the item. Those zombie chests have this exactly behavior, you harvest them and it drops multiple items, and the chest is destroyed.

Example code:
Using “stonehearth:resource_node”. This works (but is a single harvest destroying the item after, like how a tree works):

  "stonehearth:resource_node": {
     "resource_loot_table": {
        "entries": {
           "default": {
              "items": {
                 "log1": {
                    "uri": "stonehearth:resources:wood:oak_log",
                    "weight": 1.5
                 },
                 "log2": {
                    "uri": "stonehearth:resources:wood:acacia_log",
                    "weight": 1
                 }
              }
           }
        }
     }
  },

Now, the same thing, but in the “stonehearth:renewable_resource_node”, doesn’t work.

"stonehearth:renewable_resource_node": {
	"category": "harvest",
	"harvest_overlay_effect": "stonehearth:effects:loot_effect",
	"unripe_description": "empty",
	"resource_loot_table": {
		"entries": {
			"default": {
				"items": {
					"log1": {
						"uri": "stonehearth:resources:wood:oak_log",
						"weight": 1.5
					},
					"log2": {
						"uri": "stonehearth:resources:wood:acacia_log",
						"weight": 1
					}
				}
			}
		}
	},
	"renewal_time": "2d"
},

So, there are items that you consume, like mining boulders or chopping trees, for them the “resource_loot_table” works and you can make them drop multiple items.
But for items that you can harvest multiple times, like berry bushes or silkweeds, using “resource_loot_table” doesn’t works and give errors.

3 Likes

Heyho!

for the first prob:

you can make an renewable_node and a resource_node - then you can give the resource_node an command like harvest . so he will normally harvest the tree - the correct function for the command is “function”: “stonehearth:permanently_harvest_entity”, - then he will harvest the tree and you get the wood

for the loot_table i have asked yang and point here :smiley:

ok i have get an answer for this - not included ^^

at the moment renewable havent this option but yshan will add this :smiley:

Thanks, I was actually doing this exact thing you mentioned for the trees. The harvest function gets the fruits, and then, if you want, you select the tree and there will be the button to chop it. (Had to create the command using that function because there wasn’t any chop_tree ready, the closest command was a “slaughter” command, that also had the permanently_harvest_entity)
It works for my fruit trees.

But it doesn’t for the other thing I want, which is to have a chance of getting a rare loot from a harvest. You would normally harvest to get item1, but rarely (maybe a 1/15 chance) instead you would receive item2.

1 Like

because of this she will add this :wink:

2 Likes

Sooo its now added to the new release :smiley: AND AGAIN LIKE ALWAYS: THX YANG!!! :heart: :heart: :heart:

3 Likes

Not only that, in the stream she also added the ability to change the harvest animation, which I was going to post here in this topic too, but she just did there super fast lol
Now I just need to find (or create) an harvest fruit animation for tall trees.

5 Likes

what? ok i will look into the stream xD best you tell me a time xD

you know makeing an animation istn easy xD

1 Like

soo i have test it a little bit ^^ at first you need still a normal ressource - or it gets ai errors xD

and if you want more then one item to spawn you can add a roll function x

here my example:

"stonehearth:renewable_resource_node": {
         "category": "harvest",
         "resource": "brewerymod:cooking:apple",
         "renewal_time": "25h",
         "unripe_description": "i18n(brewerymod:entities.trees.apple_tree.unripe_apple_tree.description)",
         "harvest_overlay_effect": "stonehearth:effects:harvest_plant_overlay_effect",
         "resource_loot_table": {
            "entries": {
                "default": {
                  "num_rolls": {
                           "min": 1,
                           "max": 1
                     },
               "items": {
                  "apple": {
                     "uri": "brewerymod:cooking:apple",
                     "weight": 2
                     },
                  "log": {
                     "uri": "stonehearth:resources:wood:oak_log",
                     "weight": 1
                     }
                  }
               }
            }
         }
      },
1 Like

I still didn’t played with the new version. What you are saying is that I’m forced to have a “resourse”? Because in the “resource_node” (non renewable) I’m able to have just the “resource_loot_table” without the “resource”.
If that’s the case it makes it impossible to do things like for your case drops either a red apple or a green apple (not both), cause you are forced to always drop the red one at the “resource” first and then run the “resource_loo_table” to a chance to get the green as extra. What if I want it to drop just a green or just a red one? A single but random item, not one plus a chance for extras.

And to compliment your example, you don’t need to use the “num_rolls” if it is a single time use, and doesn’t need weights if it is 1.

it works! but when i remove the resouce i get this error message:

develop-3131 (x64)[M]radiant/modules/entities.lua:181: attempt to index local 'entity' (a nil value)stack traceback:
	radiant/modules/entities.lua:181: in function 'get_display_name'
	...h/ai/actions/harvest_renewable_resource_adjacent.lua:47: in function <...h/ai/actions/harvest_renewable_resource_adjacent.lua:26>
	[C]: ?
	[C]: ?
	[C]: ?
	[C]: ?
	[C]: in function 'run'
	...tonehearth/services/server/tasks/run_task_action.lua:143: in function <...tonehearth/services/server/tasks/run_task_action.lua:141>
	[C]: ?
	[C]: ?
	[C]: ?
	...
	[C]: in function 'run'
	stonehearth/components/ai/ai_component.lua:525: in function <stonehearth/components/ai/ai_component.lua:509>
	[C]: in function 'xpcall'
	radiant/modules/common.lua:257: in function 'xpcall'
	stonehearth/components/ai/ai_component.lua:509: in function '_thread_main'
	stonehearth/services/server/threads/thread.lua:249: in function <stonehearth/services/server/threads/thread.lua:246>
	[C]: in function 'xpcall'
	radiant/modules/common.lua:257: in function 'xpcall'
	stonehearth/services/server/threads/thread.lua:246: in function 'f'
	radiant/lib/env.lua:15: in function <radiant/lib/env.lua:14>

perhaps its only need a litte tweak ^^

also i saied you can add it ^^ for just one unit - just add it and then you have two items xD normally when you have only the loot_table you need the rolls with min 2 and both weight 1 or you will get only 1 item with different chances

If you want to drop two item, instead of rolling twice, just add two loot_table, each with one item, this way you are sure to get both, instead of a random chance of getting it or not.

My case is, I don’t want to get both. I need to get only item1 or item2. Sometimes it is supposed to drop only item1, sometimes only item2.
The way it works now I’m forced to have item1 in the “resource” and item2 in the loot_table and I will always get item1 when harvesting, plus a chance of getting item2 based on the luck of the loot_table. Noticed the difference? I can’t have only item2 dropping without the item1.
Using an empty uri in the “resource” didn’t worked last version, I don’t know if it will in this new one. (It works in the loot_table, that’s how you add a chance to not drop items there)

And this error you posted is the same from the last version. The game still is checking for the “resource” and assuming it has contents, failing when trying to access it when empty.

ok if an empty works i havent checked ^^ and i dont think that its the same errormessage but im not sure xD

Ok, I got the new version.
An empty uri gives an error, but in the error there is actually a suggestion:
assertion failed: Attempting to create an entity without a uri. If it is a temporary entity that shouldn’t be saved, use stonehearth:object:transient

Which I’m using now and it fulfills what I needed. :wink:

2 Likes

so if its empty its gives an wonderful error :smiley:

Yes, you need to have the “resource”. The work around is to assign an empty object to it. In this case there was already one for this purpose, the “object:transient”.
With this we trick the game into thinking it has an item in the resource. So no errors, and then it proceeds to the “resource_loot_table”, where the real items will be.

2 Likes

Hi,
I can make a fix for this in the next release so you don’t have to specify a resource.
Thanks
-Yang

5 Likes

That would be even better, thanks Yang!

1 Like

Thank you very much @yshan :smiley: