Page 1 of 1

Drop mod: advanced drops from nodes [for mod developers]

PostPosted: Tue Jan 17, 2012 20:30
by xyz
That mod is in upstream since 0.4.dev-20120122-1. No need to use it in newest Minetest versions.
Here is replacement for dug_item and extra_dug_item. Just some examples to start with:
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
 minetest.register_node("default:stone", {
     tile_images = {"default_stone.png"},
     inventory_image = minetest.inventorycube("default_stone.png"),
     paramtype = "mineral",
     is_ground_content = true,
     often_contains_mineral = true, -- Texture atlas hint
     material = minetest.digprop_stonelike(1.0),
     --dug_item = 'node "default:cobble" 1',
     dug_item = "",
     drop = {
         items = {
             {   
                 items = {'node "default:cobble" 1'},
                 tools = {'~pick'}
             }   
         }   
     }   
 })

Here player will get cobble after digging stone only if he dug it with somewhat that has "pick" as a substring (default:wood_pick, for example)

Another example, with leaves:
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
 minetest.register_node("default:leaves", {
     drawtype = "allfaces_optional",
     visual_scale = 1.3,
     tile_images = {"default_leaves.png"},
     inventory_image = minetest.inventorycube("default_leaves.png"),
     paramtype = "light",
     material = minetest.digprop_leaveslike(1.0),
     -- drop mod will handle everything =)
     dug_item = "",
     --extra_dug_item = 'node "default:sapling" 1',
     --extra_dug_item_rarity = 20,
     furnace_burntime = 1,
     -- just example of drop mod
     drop = {
         max_items = 1,
         items = {
             {
                 -- player will get sapling with 1/20 chance
                 items = {'node "default:sapling" 1'},
                 rarity = 20
             },
             {
                 -- player will get leaves only if he got no sapling, this is because max_items is 1
                 items = {'node "default:leaves" 1'},
             }
         }
     }
 })

Everything is obvious from comments: player will get leaves only if he got no sapling. That's easy now :) Try this in your mods.

PostPosted: Wed Jan 18, 2012 05:41
by Hackeridze
GOOD, VERY GOOD!

PostPosted: Wed Jan 18, 2012 07:24
by kahrl
Nice. Mind if I put a modified version of this into the itemdef patch?

PostPosted: Wed Jan 18, 2012 08:09
by Hackeridze
kahrl wrote:Nice. Mind if I put a modified version of this into the itemdef patch?

ADD IT QUICKLY PLEASE! He approve it!

PostPosted: Wed Jan 18, 2012 12:02
by xyz
kahrl wrote:Nice. Mind if I put a modified version of this into the itemdef patch?

Yes, that would be nice. But what do you want to modify?

PostPosted: Wed Jan 18, 2012 13:45
by sfan5
+1337

PostPosted: Wed Jan 18, 2012 16:53
by kahrl
Not much. In itemdef I added a per-item on_place callback. It's currently nil for nodes, but I'm in the process of moving node placement from C++ to that Lua callback. So, for symmetry, it would be nice if nodes had an on_dig callback that would be called like on_dignode, but would also be responsible for removing the node from the world, and giving the player the "default" drop if nothing else is defined. I would also remove the dug_item and extra_dug_item... fields. Everything else will stay the same.

It would be used 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
 minetest.register_node("default:stone", {
     tile_images = {"default_stone.png"},
     is_ground_content = true,
     material = minetest.digprop_stonelike(1.0),
     drop = {
         items = {
             {   
                 items = {'default:cobble 1'},
                 tools = {'~pick'}
             }   
         }   
     },
     on_dig = minetest.node_dig,   -- This line is optional, since it's set by default.
 })

PostPosted: Wed Jan 18, 2012 21:01
by xyz
Pretty serious bug with game crashing when player uses bare hand fixed.

PostPosted: Thu Jan 19, 2012 12:11
by xyz
Also there is still not-so-serious bug: when digging with tool that disappear after digging node my mod will think that you dug this node with bare hand. I think that could be fixed either by using on_punch and saving last wielded item for every player or (preferably) by modifying code that on_dig will be called before damaging wielded item.

PostPosted: Thu Jan 19, 2012 13:16
by kahrl
xyz wrote:Also there is still not-so-serious bug: when digging with tool that disappear after digging node my mod will think that you dug this node with bare hand. I think that could be fixed either by using on_punch and saving last wielded item for every player or (preferably) by modifying code that on_dig will be called before damaging wielded item.


Will fix it when adding this to itemdef, because on_dig will then be responsible for damaging the tool, and therefore knows what it was before it (possibly) disappeared.