TenPlus1 wrote:Having a single mob api keeps the size of additional mobs mods to a minimum not having to include their own api each time, also it is a LOT easier to spot and fix bugs instead of going through each mod if one ever does conflict with the other, and new features and improvements are spread across each mob using the api...
What you're talking about is strictly speaking not an API but a library. The API is the interface a program/mod offers to the outside, with function names and parameters, but without regard to the actual implementation. The
doc/lua_api.txt file describes the lua API Minetest itshelf provides. The mobs api would look something like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
mobs:register_mob(name, def) registers a new mob (the meaning of "name" and "def" ought to be explained here; especially the values the table def may contain and which meaning each has)
mobs.spawning_mobs = {} supposedly a list of mobs that will be spawned? global variables are part of the api as well
mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height)
mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height)
effect(pos, amount, texture, max_size)
mobs:explosion(pos, radius, fire, smoke, sound)
check_for_death(self)
calc_velocity(pos1, pos2, old_vel, power)
entity_physics(pos, radius)
mobs:register_arrow(name, def)
process_weapon(player, time_from_last_punch, tool_capabilities)
mobs:register_egg(mob, desc, background, addegg)
Local functions are not part of the api. Each function has to be described (what does it do? what does it return?). Each parameter passed has to be described in a similar way. But apart from the documentation (which is essential to an api), the list of functions above ought to be the complete api of the mobs(redo) mod.
The actual implementation of these functions is independent from the api and happens in what we usually call a library. They're just not very popular amongst Minetest modders, those libraries, because mods need to depend on them - making installation slightly more difficult for players and creating the fear that players may shy away from installing the mod because they've got to install something else first.
The reason why there are libraries in a programming environment is precisely what you stated above - there are no longer thousands of copies in 10000 of versions lying around, but only a single library, which can be updated, improved and changed wihtout regard to the programs (in our case: mods) using it - provided the api stays the same.
There are other functions I'd love to see beeing added to Minetest as libraries - we even talked about a possible "standard library" which could be shipped with Minetest. Such functions as save/restore a lua table in the world folder are what my own mods definitely need as a library instead of copies in each mod. The implementation (=actual working programming code) of the mobs mod, in this case
api.lua (which, despite its name, contains what ought to be called a library), ought to be part of such a standard library.
However, I'm afraid the mobs' implementation is not ready for inclusion in a standard library yet. The main function of the mobs library - register_mob - is almost a thousand lines long. To make it worse, most of it is just a call to another function, with a list of parameters that spawns those almost thousand lines. That needs to be broken up into smaller functions that do just one job and which would have the additional benefit (if not beeing local but beeing part of the api) that other mods might change part of the behaviour of a mob without having to be a complete copy of the identical rest.
twoelk wrote:Easy for the user would be some GUI with some funny mugshots of each mob as icon that I could just punch to activate or deactivate.
But then again that would not be quite so trivial for the coder to provide.
Sapiers mobf has such an interface. It's more suitable to programmers and server maintainers than inexperienced tablet users. A nice gui that allows to selectively en- or disable installed mobs the way you describe it would be something that could reside well withhin the mobs library itshelf. The major problem I see here is to create a nice, convenient formspec - and to get tiny(!) screenshots showing each mob. Other than that, mobs like skins mod or just about any craft guide out there achieve more or less the same with formspecs.
TeTpaAka wrote:It could be a little problematic that there are multiple different backends. There are, at least:
simple mobs by Pilzadam (+some forks that don't change the api much)
mobs redo by TenPlus1
creatures by BlockMen
creatures by MirceaKitsune
... (probably some more)
There's Sapiers animals modpack, and there's npcf, peaceful_ncp...and probably others I forgot.
TePpaAka wrote:The difficulty isn't the amount of backends, but the different API. That way, these aren't interchangeable. Maybe this could be solved by adding a middleware that communicates with the backends and the individual mobs?
Simple mobs by PilzAdam is what TenPlus1's mobs_redo is derived from. Creating a common api for both might be possible. BlockMen's approach is a diffrent implementation with a completely diffrent api. It might be possible to re-use models and textures, but that'd be about it I think. MirceaKitsunes mobs seem diffrent again. And then there's Sapiers mobs - which require models to be rotated by 270 degree. But you're right - a common mobs api would be highly welcome! Each mod author/creator of a model could provide an interface for his mod that'd just have to work together with the common mobs api - which would at least allow re-usage of models and textures.
TenPlus1 wrote:I've re-worked the Mobs Redo mod to be more modular so players can easily enable/disable any of the mobs inside... Make sure the actual 'mobs' mod is enabled though in the pack otherwise nothing will work :)
Creating a library goes one step further. What you did was to split your mod up into a modpack with individual mods which can now be selectively installed an deinstalled using the functions Minetest provides for mod installation/activation/deactivation. That's not bad as such - Mesecons takes the same approach. But it may still not be the best choice. The list of mods installed gets very long that way and is more difficult to check.
It would be great if there could be such a common mod api and library as part of a standard library for Minetest.