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

User avatar
xyz
Member
 
Posts: 450
Joined: Thu Nov 10, 2011 14:25

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

by xyz » Tue Jan 17, 2012 20:30

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:
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:
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.
 

User avatar
Hackeridze
Member
 
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Wed Jan 18, 2012 05:41

GOOD, VERY GOOD!
My game: RTMG
GENTOO USER
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51
Location: Rös̓̇chenhof

by kahrl » Wed Jan 18, 2012 07:24

Nice. Mind if I put a modified version of this into the itemdef patch?
 

User avatar
Hackeridze
Member
 
Posts: 310
Joined: Thu Nov 03, 2011 13:35

by Hackeridze » Wed Jan 18, 2012 08:09

kahrl wrote:Nice. Mind if I put a modified version of this into the itemdef patch?

ADD IT QUICKLY PLEASE! He approve it!
My game: RTMG
GENTOO USER
 

User avatar
xyz
Member
 
Posts: 450
Joined: Thu Nov 10, 2011 14:25

by xyz » Wed Jan 18, 2012 12:02

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?
 

User avatar
sfan5
Moderator
 
Posts: 3810
Joined: Wed Aug 24, 2011 09:44
Location: Germany
GitHub: sfan5
IRC: sfan5

by sfan5 » Wed Jan 18, 2012 13:45

+1337
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51
Location: Rös̓̇chenhof

by kahrl » Wed Jan 18, 2012 16:53

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:
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.
 })
 

User avatar
xyz
Member
 
Posts: 450
Joined: Thu Nov 10, 2011 14:25

by xyz » Wed Jan 18, 2012 21:01

Pretty serious bug with game crashing when player uses bare hand fixed.
 

User avatar
xyz
Member
 
Posts: 450
Joined: Thu Nov 10, 2011 14:25

by xyz » Thu Jan 19, 2012 12:11

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.
 

kahrl
Member
 
Posts: 236
Joined: Fri Sep 02, 2011 07:51
Location: Rös̓̇chenhof

by kahrl » Thu Jan 19, 2012 13:16

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.
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 4 guests