This post will be moved to a new modding section in due course.
It proved to be trickier than expected. Both Quest Test and Experience had bugs.
This post provides fixes for the bugs as well as the code needed for the requested feature. It also outlines, for novice Minetest modders, how I approach issues of this type.
The first step was to create a test world.
It was clear in advance that I was going to be modifying Quest Test and that the modified Quest Test was going to depend on Experience. So, I added an experience line to Quest Test's depends.txt file.
I didn't include TenPlus1's Mobs Redo API.
TenPlus1's Mobs Redo API has a hook for mob death named on_die that would work well for the desired purpose.
But the request was to make this work for Quest Test, which has its own Mobs API.
I omitted a few of Quest Test's dependencies. In practice, world hosts would need to add all of them.
I booted the test world and ran into a problem. The world crashed repeatedly with this error message:
ServerError: Lua: Invalid float vector dimension range 'x' (expected -2.14748e+06 < x < 2.14748e+06 got -nan
This problem turned out to be related to Quest Test Mobs API code that had been inherited from older mods.
Simple fixes didn't work. In the end, I rewrote parts of the function involved. The patch is provided further down.
The next step was to try to get Quest Test mob deaths to create Experience Orbs.
Quest Test's Mobs API code was in a file named qt_mobs/api.lua.
The code omitted on_die or similar hooks but did include a standard Minetest on_punch function. And the on_punch function included code to implement object drops on mob deaths.
Eureka. In theory, this was all that I needed. I implemented the requested feature by adding new code to that part of on_punch. The new code was just two lines long:
local pos = self.object:getpos()
minetest.env:add_entity (pos, "experience:orb")
At the point where the code was added, self.object was guaranteed to be the entity object associated with a dying mob.
I spawned some Quest Test mobs and battled them to the death. But nothing special happened. The new code simply wasn't called.
I'd added the new code to the mobs code that implemented drop objects on death. So why wasn't it called at the same time that objects were dropped?
The answer was simple. A test showed that Quest Test's mobs didn't actually drop objects on death. The code for this was present, but it didn't line up with the Minetest Lua API.
I fixed that issue. The patch is provided further down.
Quest Test mob deaths spawned Experience Orbs. Success. Except for the fact that Experience Orbs caused crashes when I asked a player to test the new code.
The Experience Orbs crashes occurred because the Experience mod didn't create a required data file in some cases. So, I patched that issue. The result was a working _game.
Screenshots of a Quest Test mob and Experience Orbs created by battles with such mobs are shown below. Patches and ZIP files are provided after the jump.
This particular mob is the deadly Crystal Man. Quest Test includes a few additional creatures, such as the Nether Zombie, the QT Alien, and Quest Test's versions of the Pig and the Snowman.
To browse or download a patch file for the Experience changes discussed above, click here.
To browse or download a patch file for the Quest Test changes discussed above, click here.
The patch files are in standard Linux patch-file format. Note: They won't display well on phones.
My versions of the mods are not necessarily synced with upstream. They'll work with copies of Mineville downloaded at the same time. However, they may not be compatible with minetest_game.
Note that minetest_game is deprecated.