Nodedef confusion

Post Reply
giriko
New member
Posts: 1
Joined: Fri Feb 09, 2018 22:10
GitHub: giriko

Nodedef confusion

by giriko » Post

Hey there. I have a question, obviously. I'm making a mod and I want a node to drop a random amount of an item (food, specifically).
I've tried to trawl the source code as much as I can, but I can't figure out how drops are handled, let alone how to implement such a mechanic. The documentation is a little lacking with nodedefs.
I've tried using a for loop to add a random amount to an ItemStack with little success. Have any of you done this before? How is this mechanic handled, anyway? If someone is familiar with the code, I'd like to look at it, even if there is another solution, so I can understand it better. I may be able to add documentation as well.

Chem871
Member
Posts: 999
Joined: Sat Aug 19, 2017 21:49
GitHub: Chemguy99
In-game: Chem Nyx
Location: My Basement's Attic

Re: Nodedef confusion

by Chem871 » Post

Why not take a look at the farming_redo mod? The nodes have a chance to drop items, and the code might be handy to you.
What is SCP-055?

User avatar
sorcerykid
Member
Posts: 1847
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Nodedef confusion

by sorcerykid » Post

Perhaps my GiftBox mod might offer some insight.

viewtopic.php?f=9&t=19133&hilit=giftbox

Scroll down to the section that begins "Item drops for gift boxes are selected at random..." and you'll see the code in question. The giftbox drops are in the same format required for nodedef drops (they populate the "items" table below). However, you might want to change the max_items if you want to drop more than one set of items.

Code: Select all

minetest.register_node( "giftbox:giftbox_" .. color, {
        :
        drop = { max_items = 1, items = giftbox.giftbox_drops },
        :
} )
I included comments and an explanation of the algorithm as well, so feel free to experiment. Hope this helps.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests