Jump to content

Lureplant digestion revisited


Recommended Posts

Hey folks. Got a few questions on lureplants that weren't covered in other threads or on the Don't Starve wiki.

 

There's threads about lureplant digestion, but nobody seems to go into much detail about how lureplants handle item stacks.

 

I had a lureplant grab a stack of 20 logs and another one of 40 grass, and was able to get them back, but I'm wondering if the plant would have digested each log in the stack one by one or the whole stack all at once? Does anyone have experience here?

 

I took a look at the .lua code for the digester component and it doesn't seem to explain how it handles stacks, but I'm kind of new to .lua. I've quoted it below in case anyone can shed some light on it:

 

 

local Digester = Class(function(self, inst)

self.inst = inst
self.digesttime = 20
self.itemstodigestfn = nil
self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) 
self.inst:ListenForEvent("gotnewitem", function() 
if not self.task then 
self.task = self.inst:DoPeriodicTask(self.digesttime, function() self:TryDigest() end) 
end 
end)
end)
 
 
function Digester:TryDigest()
if self.inst.components.inventory then
local helditems = {}
 
for k,v in pairs(self.inst.components.inventory.itemslots) do
if not v:HasTag("irreplaceable") then
if self.itemstodigestfn then
if self.itemstodigestfn(self.inst, v) then
table.insert(helditems, v.prefab)
end
else
table.insert(helditems, v.prefab)
end
end
end
if #helditems > 0 then
local rnd = math.random(#helditems)
self.inst.components.inventory:ConsumeByName(helditems[rnd], 1)
else
if self.task then
self.task:Cancel()
self.task = nil
end
end
end
end
 

return Digester

 

Link to comment
Share on other sites

  • Developer

"self.inst.components.inventory:ConsumeByName(helditems[rnd], 1)" is the part that actually consumes the item. The "1" that it's passing in means that it will only consume one item at a time, even from stackable items. 

Link to comment
Share on other sites

Hey, a dev response! Thanks, Bryce. So the idea of using lureplants for gathering items CAN work, potentially, so long as the items in question are too plentiful for it to digest. Guess that means I can set up harvesting if I feel like replanting 96 saplings that will essentially never be reliably harvested and then adding on however many saplings on top of that which WILL be reliably stockpiled as they'd be too much for the lureplant's digestion rate to handle.

 

Makes sense only for games so long there's an eventual benefit, I suppose.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...