recipe with random result

Post Reply
Mowgli
Member
Posts: 12
Joined: Sun May 28, 2023 22:30

recipe with random result

by Mowgli » Post

Is it somehow possible to create an recipe that produce random stuff from a list?

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: recipe with random result

by Blockhead » Post

Yes, you can register a function to run when the player crafts something, and replace the output with what you decide instead. minetest.register_on_craft.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Mowgli
Member
Posts: 12
Joined: Sun May 28, 2023 22:30

Re: recipe with random result

by Mowgli » Post

Is it possible to return more than one type of items?

What I want to archive is, a user has converted some group:minegeld_note to currency:minegeld_bundle and is crying that he cannot use the later one for anything. I want to allow him to craft them back to 9 possible different currency:minegeld_* selected randomly.

I could modify the inventory directly but when exactly is that redister_on_craft executed? when A user click on the result? When it is showed or when he dropped the result into his inventory?

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: recipe with random result

by Blockhead » Post

Mowgli wrote:
Fri Jun 09, 2023 10:02
Is it possible to return more than one type of items?

What I want to archive is, a user has converted some group:minegeld_note to currency:minegeld_bundle and is crying that he cannot use the later one for anything. I want to allow him to craft them back to 9 possible different currency:minegeld_* selected randomly.
How about making the random choice happen when the bundle is held in the hand and the user left (or right) clicks? And think about the effects of letting players play the lottery/scratch tickets this way too.
Mowgli wrote:
Fri Jun 09, 2023 10:02
I could modify the inventory directly but when exactly is that redister_on_craft executed? when A user click on the result? When it is showed or when he dropped the result into his inventory?
Either every time the crafting grid changes, to show a new result; or when the user clicks the result. I'm not sure right now. I think the former not the latter, because it has an itemstack argument, which is the output stack. But you could just go test it for yourself, you know. It's probably quicker than asking questions and waiting hours for a response. Maybe a documentation improvement pull request is in order, once you figure it out.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: recipe with random result

by Skamiz Kazzarch » Post

https://github.com/minetest/minetest/bl ... 0-L5572C64

Code: Select all

* `minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv))`
    * Called when `player` crafts something
    * `itemstack` is the output
    * `old_craft_grid` contains the recipe (Note: the one in the inventory is
      cleared).
    * `craft_inv` is the inventory with the crafting grid
    * Return either an `ItemStack`, to replace the output, or `nil`, to not
      modify it.
* `minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv))`
    * The same as before, except that it is called before the player crafts, to
      make craft prediction, and it should not change anything.
Haven't used them myself but the documentation seems clear enough?
First one can be used to change the result, when you click on it and later one can be used to change what appears in the output before the crafting action happens.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests