Taking Questions about Mixintos and Overrides


#201

Oh, that code is standalone sure enough. You can insert it into any mod, or even an own, as long as it’s executed on the server (similar to my math.random() fix.)

However, yes, it would make sense to have some functionality for this. However, even I can’t think of a proper solution for this (except maybe offering built-in functions to do what I just did, which is more or less a GROUP BY). By changing the data structure to an object, you lose the ability to sort properly (unless you add an index or position or weight attribute too, therefore making things more complicated than they already are).

I thought about implementing such a helper function in RP, maybe Jelly, but as for now, there’s no real demand. I’m just sure that this isn’t necessarily something that should be done by mixintos.


#202

Yes. Right now it’s a huge pain that mixintos work best with maps, while the handlebars templating in Ember only takes arrays. The recipe format was written so the UI doesn’t have to do any parsing, but I expect the recipe format to change when we allow for dynamically added recipes, and when we do that, we’ll probably use a different format for specifying categories.


#203

@sdee @RepeatPan
Is it with the current alpha-version possible to give an entity 2 different commands? For example renewable resource and chopping. It used to be possible, as I used it in one of my mods. They might have changed it since then. As it might conflicted with mass gathering command.

In the stonehearth/call_handlers/resource_call_handler.lua it says this:

function ResourceCallHandler:harvest_entity(session, response, entity)
  local town = stonehearth.town:get_town(session.player_id)
  if entity:get_component("stonehearth:renewable_resource_node") then
    town:harvest_renewable_resource_node(entity)
  elseif entity:get_component("stonehearth:resource_node") then
    town:harvest_resource_node(entity)
  elseif entity:get_component("stonehearth:crop") then
    town:harvest_crop(entity, "/stonehearth/data/effects/chop_overlay_effect")
  end 

With my non-existing code knowledge it seems it only can choose 1. And renewable resource as first priority?


Crops / resource nodes / renewable resource nodes / growing
#204

I haven’t touched SH code in ages so all I can share is some memory about this:

All AI harvesting tasks share one table. That means, if you queue somebody to harvest a renewable resource, you cannot queue them for harvesting them normally. In addition, the object becomes unharvestable until it was replenished, even for the, well, “final” harvest.

The code you have posted does basically exclude this, yes. If a resource is renewable, it cannot be harvested normally - at least, not with this command. It’s not checking whether the resource is currently available (and shouldn’t in my opinion).

The whole system isn’t built to support multiple resources from one entity (yet). That was an issue I ran into with rp_growing_trees too.

You could create your own command which calls the town-function itself I suppose. There shouldn’t be any harm in doing that - harvest_entity will, however, continue to be the one that’s used for the “normal” harvest command.


#205

I see. I shall try to call the town-function directly. Thanks

This is the reason why they removed the 'chop berry bush ’ command I suppose.


#206

Hey @Miturion, it IS possible to give an entity multiple commands (see, Trapper) but as per the code you mention, we lost the ability to chop down individual bushes when we decided to make the “harvest” function generic and exercised through the toolbar and not the individual objects. We’re still due to have a conversation about the design implications of that, but anyway, to add a command to the unit frame, you have to:

  • make sure the entity has a commands component (declared in its .json file)
  • add the list of desired commands to the commands component
  • make a .json file that represents the command (see like, chop.json)
  • the command .json file should specify if on click, the command fires a UI event (the way that craft does) or calls a game function (the way chop does).
  • The code to handle the command then does whatever you need the command to do.
  • If you’re calling a game function, then you’ll need a call handler. The call handler needs to be declared in the manifest, and can be either a client call handler, or a server call handler.
  • client call handlers deal with things that are relevant only to the user, and do not change the world: for example, dragging out a box on the ground for selection.
  • server call handlers change the way the world works. Client call handlers usually handle selection, and then pass the data derived from the user to a server call handler to actually make changes in the game.

I realize this is pretty high level, but let me know if I can offer you more resolution on something in particular.


#207

Thanks for the explanation sdee.
I tried to make a separate call handler that just changed priority of resource node above renewable resource node, didnt work :smile:.

I have this now:
A json file for the entity:

  {
   "type": "entity", 
   "components": {
      "stonehearth:commands" : {
         "commands" : [
            "file(../../../commands/harvest_pumpkins)",
            "file(../../../commands/chop_farming_plot)"
         ]
      },

      "model_variants": {
         "default": {
            "models": [
               "file(pumpkins_plot.qb)"
            ]
         },
         
             "depleted": {
            "models": [
               "file(pumpkins_plot_empty.qb)"
            ]
         }
      },
      "region_collision_shape" : {
         "region": [
            {
               "min" : { "x" : -1, "y" : 0, "z" : -1 },
               "max" : { "x" :  1, "y" : 1, "z" :  1 }
            }
         ]
      },
      
      "destination" : {
         "region" : [
            {
               "min" : { "x" : -1, "y" : 0, "z" : -1 },
               "max" : { "x" :  1, "y" : 1, "z" :  1 }
            }
         ]
      },
      "unit_info": {
         "name": "Pumpkin Farming Plot", 
         "description": "Cultivars of Squash!"
      }, 
      "stonehearth:resource_node": {
         "resource": "stonehearth:oak_log", 
         "durability": 1
      },
      "stonehearth:renewable_resource_node": {
         "resource" : "mod_egypt:pumpkins_basket",
         "harvest_profession" : "worker",
         "renewal_time" : "12h",
         "harvest_command" : "harvest_pumpkins",
         "wait_text" : "Not yet ripe for harvest.",
         "harvest_overlay_effect" : "/stonehearth/data/effects/harvest_berries_overlay_effect"

        
      }
   }
}

A chop_farming_plot command:

{
   "type" : "command",

   "name": "remove plot",
   "tooltip": "I dont need this mud here!",
   "description": "Harvest for lumber, or just to get it out of the way.",
   "icon": "file(chop_harvest_plot.png)",

   "action": "call",
   "function": "stonehearth:harvest_entity",
   "args": [
      "{{self}}"
   ]
}

A harvest pumpkins command (renewable)

{
   "type" : "command",

   "name": "harvest_pumpkins",
   "tooltip" : "Gather Pumpkins",
   "description" : "This farmplot produces pumpkins that can be harvested to feed your settlers.",
   "disabled_description" : "The pumpkins on this farmplot aren't ripe yet!",

   "default_enabled": true,  
   "icon": "file(gather_pumpkins.png)",

   "action": "call",
   "function": "stonehearth:harvest_entity",
   "args": [
      "{{self}}"
   ]
}

I know the problem is the harvest_entity in the chop command. But not sure what to write there instead. :blush:


#208

Right. Try this:

  • open stonehearth’s manifest.json and scroll all the way down to the section that’s call handler declarations. Look for stonehearth:harvest_entity.
  • This part of the manifest is how something like sh:harvest_entity is mapped to the harvest_entity function inside resource_call_handler.lua
  • You want to make a new file, like chop_pumpkin_wood.lua, and give it a chop_pumpkin_wood function, and then map a new call like stonehearth:chop_pumpkin_wood to that function in that file, by copying what’s going on with resource call handler and sh:harvest_entity.
  • put stonehearth:chop_pumpkin_wood in for harvest_entity in the chop command.
  • Inside the chop_pumpkin_wood function, call town:harvest_resource_node(entity) and see if that works.

#209

wow that is actually almost what I tried :smile:. But since I did not understand most of the code I did not throw anything away. I go try it now.


#210

hmm I am stuck again. I get the error: atempt to call a nil value.
I made a lua file

chop_farming_plot.lua:

function ResourceCallHandler:chop_pumpkins_wood(session, response, entity)
  local town = stonehearth.town:get_town(session.player_id)
  if entity:get_component("stonehearth:resource_node") then
    town:harvest_resource_node(entity)
  elseif entity:get_component("stonehearth:renewable_resource_node") then
    town:harvest_renewable_resource_node(entity)
  elseif entity:get_component("stonehearth:crop") then
    town:harvest_crop(entity, "/stonehearth/data/effects/chop_overlay_effect")
  end
end
function ResourceCallHandler:shear_sheep(session, response, sheep)
  asset(false, "shear_sheep was broken, so i deleted it =)  -tony")
end
return ResourceCallHandler

A chop_farming_plot.json file:

{
   "type" : "command",

   "name": "remove plot",
   "tooltip": "I dont need this mud here!",
   "description": "Harvest for lumber, or just to get it out of the way.",
   "icon": "file(chop_harvest_plot.png)",

   "action": "call",
   "function": "mod_egypt:chop_pumpkins_wood",
   "args": [
      "{{self}}"
   ]
}

And put this in my mods manifest:

"functions" : {
       "chop_pumpkins_wood" : {
         "controller": "file(commands/chop_farming_plot.lua)",
         "endpoint" : "server"}
       },

#211

This just means that there is a nil value somewhere in the code. :wink: A few possible sources:

  • ResourceCallHandler is a class, and must be declared as one. Make sure your file copies over this line:
    local ResourceCallHandler = class()
  • ResourceCallHandler is the name of a class; in your function, replace all occurances of ResourceCallHandler with ChopPumpkinsCallHandler or something similar. :slight_smile:

#212

The good news is that the nil error is gone. The bad news is that it still does not work.

This is my call handler lua file:

local ChopPumpkinsCallHandler = class()

function ChopPumpkinsCallHandler:chop_pumpkins_wood(session, response, entity)
  local town = stonehearth.town:get_town(session.player_id)
  if entity:get_component("stonehearth:resource_node") then
    town:harvest_resource_node(entity)
  elseif entity:get_component("stonehearth:renewable_resource_node") then
    town:harvest_renewable_resource_node(entity)
  elseif entity:get_component("stonehearth:crop") then
    town:harvest_crop(entity, "/stonehearth/data/effects/chop_overlay_effect")
  end
end

return ChopPumpkinsCallHandler

Do I maybe also need anything out of this? It was also in the resource_call_handler.

local Point3 = _radiant.csg.Point3
local Cube3 = _radiant.csg.Cube3
local Color4 = _radiant.csg.Color4
local Rect2 = _radiant.csg.Rect2
local Point2 = _radiant.csg.Point2
local priorities = require("constants").priorities.worker_task
local farming_service = stonehearth.farming

#213

None of these classes are used, so they’re not required. The call handler looks fine so far. I assume that your command is broken.

Personally, I’d just spam prints() into that thing to see if it actually gets called - but I don’t know if the console supports that. You could go for os.exit() but I’m not sure if that’s a good idea.


#214

ah well. Then I dont know.


#215

Hmm, what’s the “not working” behavior that you’re witnessing? You click the new command in the unit frame and nothing happens?

Definitely check and see if the code is even getting called, if you can. Another thing to try, for now, is to check if everything works if you add the call handler to the stonehearth manifest.json (and put the relevant files in the stonehearth folder) instead of yours, to try to isolate if the problem is with the code or the plumbing.


#216

Yes, exactly that. shortkey 1 (harvest pumpkins) works, shortkey 2 (chop down farmplot) does not do anything when clicked on. I tried to put it in the stonehearth manifest and changing links, same result.

I dont know how print() works. And it is about time to go to bed :smile:
In case anyone wants to look, here is the mod. Make a pumpinsplot with the carpenter and place it somewhere.
https://drive.google.com/folderview?id=0B0JhuggbnqMZTm9VaW05SkJfekk&usp=sharing


#217

assuming I’m in front of my PC for any reasonable amount of time tonight, I might take a stab at this… with the change in work schedule, and newest (canine) member of the family, it might be tough…


#218

I took a look! It looks like the harvest function in the town now expects a harvest_overlay_effect and a harvest_profession. Take a look at tree.json and copy what’s in there. I got it to work by changing you pumpkin plot.json to:

"stonehearth:resource_node": {
     "resource": "stonehearth:oak_log", 
     "durability": 1,
     "harvest_profession" : "worker",
     "harvester_effect" : "chop",
     "harvest_overlay_effect" : "/stonehearth/data/effects/chop_overlay_effect"
  },

Otherwise, the mod looks great! I really enjoyed the bread and columns. :slight_smile:

Edit: I wasn’t able to get the stairs working–do they work for you?


#219

Awesome, many many thanks :smile:. Guess mixins is the place to look. I was still looking at entities.
Glad you enjoyed the colums. Bread still need grain farm tho to work.

Stairs used to work. But you guys totally broke it :stuck_out_tongue_closed_eyes:. Nah was simple fix. Was still in the old format. Like half the mod still is. I was about to update it untill I bumped into the pumpkinproblem.
I got the modding fever again. :pensive:


#220

That’s so cool. :slight_smile: Glad they’re working! Obviously, the Egyptians really do have access to superior technology :wink: