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

Post Reply
Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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
Last edited by Byakuren on Wed Jul 05, 2017 01:15, edited 10 times in total.
Every time a mod API is left undocumented, a koala dies.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

If you think the API looks great, you can say that too.
Every time a mod API is left undocumented, a koala dies.

User avatar
Christian9
Member
Posts: 338
Joined: Fri Sep 19, 2014 20:29
In-game: Christian9
Location: Hell Creek

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

by Christian9 » Post

Looks neat, but if this is for creating mobs is there a template for mob creation?

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.
Every time a mod API is left undocumented, a koala dies.

User avatar
Krock
Developer
Posts: 4648
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

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

by Krock » Post

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.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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".
Every time a mod API is left undocumented, a koala dies.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.
Every time a mod API is left undocumented, a koala dies.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

It's been a while, but I think I'm about ready to release. Any comments from anyone who is interested in the project?
Every time a mod API is left undocumented, a koala dies.

User avatar
Christian9
Member
Posts: 338
Joined: Fri Sep 19, 2014 20:29
In-game: Christian9
Location: Hell Creek

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

by Christian9 » Post

Excited to test it out

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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).
Every time a mod API is left undocumented, a koala dies.

User avatar
D00Med
Member
Posts: 949
Joined: Sat Feb 07, 2015 22:49
GitHub: D00Med
Location: Australia...somewhere

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

by D00Med » Post

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 :]
Look! I have a signature :]
My subgame: viewtopic.php?f=15&t=14051#p207242

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.
Every time a mod API is left undocumented, a koala dies.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.
Every time a mod API is left undocumented, a koala dies.

User avatar
Wuzzy
Member
Posts: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

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.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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)
Every time a mod API is left undocumented, a koala dies.

User avatar
Wuzzy
Member
Posts: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

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.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

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

by Byakuren » Post

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.
Every time a mod API is left undocumented, a koala dies.

User avatar
Wuzzy
Member
Posts: 4778
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

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

by Wuzzy » Post

Is this mod going to be finished one day?

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests