Some coding questions about JSON/Entities

Hello,

I’ve got a questions about some parts of the JSON files for Entities. List follows.
“model_variants”: {
“default”: {
“layer”: “clothing”,
“models”: [ <-- why is an array used here? Does it mean a model can have multiple files?
“file(steel_mail.qb)”
]

“stonehearth:combat:melee_defenses” : [ same here, different types of melee_defenses?
{
“name” : “combat_1h_shield_block”,
“active_frame” : 4,
“cooldown” : 1000,
“priority” : 0
}
]

“region_collision_shape” : {
“region”: [ <-- can there be more than on collision region for an entity?
{
“min” : { “x” : -0.25, “y” : 0, “z” : 0.25 },
“max” : { “x” : 1.25, “y” : 2, “z” : 0.75 }
}
]

And another question is, are there minimum required paramters for an entity to work in the game? For example a placable item has to have this this and that parameter or a weapon has to have these parameters and so on.

regards

Hiya!

Let’s go over your first three questions.

Short version: Yes, yes, and yes.

Long version:

  1. Having multiple models aren’t useful in most simple cases, but it’s very handy when you’d want 2 or more of the same kind of entity to look different from each other. Like the hearthlings: they have several models attached to them so one hearthling can have a beard while the other have none.

  2. Maybe the entity can have more than one way of defending against attacks, like a dodge together with that block.

  3. This is needed for entities that are more complex than a cube. A good example is the bed; it consists of three collision regions: 1 for the head-end, 1 for the foot-end and 1 for the actual bed.

Apart from having a model so it can be shown in the world? Not really. Of course having just a model doesn’t do anything, you’d still need to add the right components and entity data for it to behave just as you want it to.


Hope that answers your questions! :smile:

3 Likes

Thanks for the fast answer.

to 1. ok, so this means I can have multiple models for lets say an armor or maybe some flower with different colors? Does the game chose from all the models which are given?
to 2. ok, good to know, helps alot, but thats not planned yet?
and to 3. ok, I see the reason here

For the last part, yes, I mean which of the components have to be in the simpliest of simple entities and same goes for the entity data. I think even a piece of rock which has no other purpose than laying around hast to have required properties/parameters to work laying around :smiley:

  1. It seems I wasn’t completely correct; the game is using the model_variant component together with stonehearth:customization_variants in entity_data to randomize the looks of an entity. For the goblins though it is using a more straightforward approach when choosing a head model (you can see how it does that in stonehearth/entities/mosters/goblins/goblin/goblin.json).

  2. It’s already implemented; a footman with a shield can both block and dodge. :wink:

Well, what components you need to have for the entity depends entirely on the purpose of the entity. I could give you some pointers if you’re willing to share that kind of information, but I could at least say that you can look at another entity’s definition file that’s similar to what you’re thinking of and copy that one.

2 Likes
  1. I see so it’s kinda very complex to lets say create a random NPC for example if you take the stonehearth:customization_variants approach which is hard to understand for me in the male_x.json and not the lets name it goblin approach where its using one_of the provided items in the list.

  2. And where is that defined? Does it take these parameters from the shield itself? Because in the basic_shield.json there is only block defined.

I know what you mean, that refers to my initial question, there have to be some sort of required properties for an Entity to work the way you want it to work. Can i assume that all the different folders inside the entities folder of the Stonhearth mod are the different kinds of entities you can have in the game?

  1. Yeah, out of those two, I’d recommend going with the same approach as for the goblins since it’s much easier to understand.

  2. Yes, only the block is defined for the shield. The dodge defense is defined in footman_abilities.json. There is no file (from what I’ve seen) that defines more than one defensive ability, though seeing as the footman can both block and dodge and that "stonehearth:combat:melee_defenses" is defined as an array; there’s no doubt in my mind that you can have more than one defensive ability in there.

Not necessarily, if there’s one kind of entity that you want to have in the game but there is none there already, then you can define your own components through scripting. Of course that’s more advanced but that’s the way to do it if you’re looking for a behavior that’s not available.

  1. Yes if I want to completely change the model that would be my approach, and if I want to mix stuff together I have to go with the approach you are using in the male_x.json ok understood
  2. I see, yes, for now there is no file that has both, and I was wondering if I put lets say the block from the shield into the footman_abilities.json would the game take both defense abilities into account or not?

Yes I mean the basic stuff unless I want to create a flying ship for example then I guess I have to implement all this by myself including the scripting part.

I don’t see why it wouldn’t; so yes, it would.

Yeah, pretty much. Continuing on your example, if you’re looking to create something that flies then I’d recommend that you wait until the game has support for flying entities, which will make it much easier for you. I’d say the same for stuff that’s not in the game, but there’s a very high chance of it being in the game eventually.

1 Like

Ok, thanks for the help, now I have something I can work with and understand a bit more about entities in the game and can work on my project further :smile: supersecretprojectwithlotsofworktodo

2 Likes

Related to the original post “minimum requirements” and “placeable items” question: the key thing that distinguishes a plain ol’ item placed in the world from an resource, talisman, weapon, or item of clothing, all which only appear as icons in stockpiles (when not equipped) is the “placeable” bit of this excerpt:

"components": {
   "stonehearth:entity_forms" : {
       "iconic_form" : "file(dresser_iconic.json)",
       "ghost_form" : "file(dresser_ghost.json)",
       "placeable_on_ground" : true
   }
}

or you may see “placeable_on_walls” instead of “placeable_on_ground” (see lantern json). Without that, you won’t see the “chair with down arrow” icon in game that you use to tell your hearthlings where to deploy things.

I recommend finding the thing that is most like what you are trying to create and work from that item’s json. It’s actually not to difficult to make placeable stuff. I haven’t tried any critters or anything that needs animation yet myself.

1 Like

ANd here is another question about this part of the JSON

"models": [
    "file(goblin_body.qb)",
    {
        "type": "one_of",
        "items": [
            "file(goblin_head_1.qb)", 
            "file(goblin_head_2.qb)", 
            "file(goblin_head_3.qb)",
            "file(goblin_head_4.qb)",
            "file(goblin_head_5.qb)"
        ]
    },
    "file(test_head.qb",// can this be done or is there only one option to define the base model?
    {
        "type": "one_of",
        "items": [
            "file(goblin_armor_none.qb)", 
            "file(goblin_armor_vest.qb)"
        ]
    }
]

There’s no problem doing that; the game will load that model as the rest (though it’s missing a ‘)’ in there).

I knew it, mhm, so you can either provide several model files or combine that with the random model selection, right?

And the next question :wink: would it be hard to change the above JSON part to something like this?

"model_variants": {
    "model_variant" : [
        { 
            "type": "default",
            "layer": "clothing",
            "models": [
                "file(steel_mail.qb)",
                {
                    "type": "one_of",
                    "items": [
                        "file(goblin_head_1.qb)",
                        "file(goblin_head_2.qb)",
                        "file(goblin_head_3.qb)",
                        "file(goblin_head_4.qb)",
                        "file(goblin_head_5.qb)"
                    ]
                },
                {
                    "type": "one_of",
                    "items": [
                        "file(goblin_armor_none.qb)",
                        "file(goblin_armor_vest.qb)"
                    ]
                }
            ]
        },
        {
            "type": "depleted",
            "models": [
                "file(sheep_shorn.qb)"
            ]
        }
    ]
},

I think you know where I’m going with this :wink:

Unfortunately model_variants can’t be defined in such a way, or if it can I haven’t seen it used anywhere.

You’d have to change it to something like below, but otherwise it should work fine!

"model_variants": {
    "default" : {
        "layer" : "clothing",
        "models" : [
            "file(steel_mail.qb)",
            {
                "type": "one_of",
                "items": [
                    "file(goblin_head_1.qb)",
                    "file(goblin_head_2.qb)",
                    "file(goblin_head_3.qb)",
                    "file(goblin_head_4.qb)",
                    "file(goblin_head_5.qb)"
                ]
            },
            {
                "type" : "one_of",
                "items" : [
                    "file(goblin_armor_none.qb)",
                    "file(goblin_armor_vest.qb)"
                ]
            }
        ]
    },
    "depleted" : {
        "models" : [
            "file(sheep_shorn.qb)"
        ]
    }
},

I can only speculate what you’re trying to do, but it’s starting to look interesting. :smile:

I didn’t mean to change it on my side :wink: I mean to change it on your side, so a model_variants component has to look like this

So, whats your speculation about it? :wink:

Ah, I understand. :blush:

Well, seeing your use of sheep_shorn makes me think of polymorphism. So maybe your attempting to mod in that kind of spell, or maybe an equippable piece of armor that turns you into sheep upon defeat.

Ummm, I think you are totally wrong :smiley: but I can give you a hint, they way implementing the model_variants this way would be better to ‘read’ :wink:

So you mean that when you ‘harvest’ something that looks like a dead goblin; a sheep pops up?

Haha, noo, the parameters are only examples, I only mean the way model_variants has to look inside the JSON of an entity, because that way it is better to “read” you know :wink:

Oh, well in that case it could be anything; if those are only examples I have absolutely no idea what you’re trying to do.