Page 1 of 1

[Mod] Common Mob Interface [0.1.0.0] [cmi]

Posted: Fri Sep 02, 2016 03:52
by Byakuren
This is a mod providing an interface like I described in viewtopic.php?f=47&t=15331. It provides a common interface for dealing with mobs independently of specific mob mods, as long as the mobs you target are from mods that implement the interface.

Features:
  • Callback registration for certain mob events (dying, mob step, etc.)
  • "Entity components", pieces of state you can register to be attached to all mobs. For example, you could implement mob potion effects by giving a potion effect component that keeps track of applied potions, and use a mob step callback to simulate the potion effects.
  • Unique mob IDs - these have been implemented using the components system.
License: Apache 2.0
Mod dependencies: none
Download: https://github.com/raymoo/cmi/archive/v0.1.0.1.zip (Rename folder to cmi)

Github: https://github.com/raymoo/cmi
API docs: https://cmi-minetest.github.io
Implementation Guide (For mob framework writers): https://github.com/raymoo/cmi/blob/mast ... MENTING.md
Code Examples: https://github.com/raymoo/cmi_examples

I would like feedback from both modders who want to use the interface, and authors of mob frameworks. For modders using the interface, what do you think needs to be added/changed/removed in the interface? For mob framework writers, do you forsee any problems in implementing the interface? After writing the interface I did a quick check through Mobs Redo and it looks like it would be easy to integrate there, but that might not cover all cases. If you want to say something, I'm fine with it being posted in this thread or as an issue on the github repository.

Mob mods that implement the CMI interface (modders can use CMI with these mobs): Ideas for mods utilizing CMI:
  • Use the health change callbacks to display floating damage numbers when mobs are hit
  • Track the mobs killed by a player, for achievement purposes or otherwise

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sat Sep 03, 2016 20:20
by Byakuren
If you think the API looks great, you can say that too.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sat Sep 03, 2016 22:51
by Christian9
Looks neat, but if this is for creating mobs is there a template for mob creation?

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Sep 04, 2016 04:42
by Byakuren
Christian9 wrote:Looks neat, but if this is for creating mobs is there a template for mob creation?
It's neither. It's a standard interface you can put on top of existing or new mob frameworks so that modders who want to interact with those mobs only need to know about the CMI interface, instead of writing separate code for every mob mod that exists.

Concretely, the mod provides some callback registration functions and something sort of like an attribute system for mobs. You can use these features with any mobs that implement the interface.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Sep 04, 2016 06:51
by Krock
The Lua code is well documented but even with the implementation helpfile I have no clue how to use this framework/interface in a mobs mod. An example file would help here a lot to see how it could look like.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Sep 04, 2016 07:13
by Byakuren
Krock wrote:The Lua code is well documented but even with the implementation helpfile I have no clue how to use this framework/interface in a mobs mod. An example file would help here a lot to see how it could look like.
Alright, I'll put making an example on my todo list. I've mentioned this mod to tenplus1 in IRC, so either he'll implement it or I'll start making PRs (that's not meant to be a threat), and that will be an additional "live example".

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Tue Sep 06, 2016 03:09
by Byakuren
I've added an implementation code example (check the OP). You can do /spawnentity cmi_examples:mob to spawn the example mob. I plan on adding examples for other parts of the API later.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Mon Jan 16, 2017 02:56
by Byakuren
It's been a while, but I think I'm about ready to release. Any comments from anyone who is interested in the project?

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Mon Jan 16, 2017 02:59
by Christian9
Excited to test it out

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Mon Jan 16, 2017 03:32
by Byakuren
Christian9 wrote:Excited to test it out
Thanks

Though really I just replied so I can say something extra: I'm specifically interested in complaints about the API (both on the library-user and implementor sides).

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Tue Jan 17, 2017 07:46
by D00Med
This seems very interesting, especially this: "Modders can write mobs that don't use any framework, by just implementing the interface"
Now I just have to get my head around how to use the mod :]

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Tue Jan 17, 2017 09:42
by Byakuren
D00Med wrote:This seems very interesting, especially this: "Modders can write mobs that don't use any framework, by just implementing the interface"
Now I just have to get my head around how to use the mod :]
Just in case there's any misunderstanding, this just means CMI can be used on your mob as long as it implements the interface. CMI won't make your mob walk around or attack players by itself, that would have to be coded by the mob author.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Jun 18, 2017 07:13
by Byakuren
I've added a second example for showing how to use the registration functions. I've also PR'd CMI support to mobs redo. Maybe I can get some feedback in the response to the PR.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Jun 18, 2017 18:42
by Wuzzy
I cheered when I saw “cmi_is_mob”.

Then I realized this should have a leading underscore because it is a custom field, according to naming conventions. (see lua_api.txt)

As well as all other custom fields.

Re: [Mod] [Draft] Common Mob Interface [cmi]

Posted: Sun Jun 18, 2017 21:55
by Byakuren
Wuzzy wrote:I cheered when I saw “cmi_is_mob”.

Then I realized this should have a leading underscore because it is a custom field, according to naming conventions. (see lua_api.txt)

As well as all other custom fields.
RIP, and right after I got it into mobs redo. Maybe it won't be so bad if I change it quickly since I don't know any mod that uses it (other than cmi_examples)

Re: [Mod] Common Mob Interface [0.1.0.0] [cmi]

Posted: Tue Jul 04, 2017 15:18
by Wuzzy
Ideas:
  • Add spawn function to spawn a mob (assuming default spawning settings)
  • Add on_spawn(mob, pos) callback, called when the mob is spawned at pos
  • Standardize some core mob attributes:
    • Health (nil if if infinite health or the notion of health does not apply)
    • Max. health (nil if no limit)
    • Drops: List of “usual” drops when the mob dies; converted to a parsable, standardized format (Best implemented as a function)
    • (your idea here)
Finally, please put the readily-generated documetation into the mod directory, not everyone wants to install ldoc.

Re: [Mod] Common Mob Interface [0.1.0.0] [cmi]

Posted: Wed Jul 05, 2017 01:08
by Byakuren
Wuzzy wrote:Ideas:
  • Add spawn function to spawn a mob (assuming default spawning settings)
  • Add on_spawn(mob, pos) callback, called when the mob is spawned at pos
  • Standardize some core mob attributes:
    • Health (nil if if infinite health or the notion of health does not apply)
    • Max. health (nil if no limit)
    • Drops: List of “usual” drops when the mob dies; converted to a parsable, standardized format (Best implemented as a function)
    • (your idea here)
Finally, please put the readily-generated documetation into the mod directory, not everyone wants to install ldoc.
I don't think I will include a spawning function, since this mod is supposed to be unopinionated on how exactly a mob is defined or created. Entities are flexible enough that you could have a mob mod that doesn't require mobs to be registered beforehand, and then there wouldn't be a way to specify how to spawn the mob. However, on_spawn would be a good idea, since all entities need to be spawned at some point. I don't think a position parameter is necessary though, since that could be obtained from the mob. I think on_spawn could even be implemented as a (standard, supplied by CMI itself) component, like how unique IDs are.

I agree about the stats handling.

I have been a little bit busy the past few days but I am on summer break so I will find time to work on CMI.

If anyone makes a mod that uses the CMI APIs or has ideas for such mods, feel free to post them. I have updated the OP with a couple ideas.

EDIT: And also I have added docs to the main repo.

Re: [Mod] Common Mob Interface [0.1.0.0] [cmi]

Posted: Sun Aug 25, 2019 20:54
by Wuzzy
Is this mod going to be finished one day?