Git Product home page Git Product logo

crafting's Introduction

Crafting

Adds semi-realistic crafting with unlockable recipes to Minetest, and removes the craft grid.

Created by rubenwardy.
License: LGPLv2.1+

Screenshot

Image Licenses

rubenwardy (CC BY-SA 3.0): crafting_slot_*.png

Neuromancer (CC BY-SA 3.0): crafting_furnace_*.png

BlockMen (CC BY-SA 3.0): gui_*.png

paramat (CC BY-SA 3.0) creative_trash_icon.png (derived from a texture by kilbith, same license)

Limitations

Any recipes must be designed such that any particular item can only be used as one of the ingredients.

For example, you can't have the following recipe as default:wood could be used twice: default:wood, group:wood.

API

  • crafting.register_type(name)

    • Register a type type used when searching for recipes
  • crafting.register_recipe(def)

    • Returns id.
    • def a table with the following fields:
      • type - one of the registered types.
      • output - the result of the craft, eg: default:stone 3.
      • items - A list of ingredients, eg: {"stone", "wood 3"}.
      • level - level of station required.
      • always_known - If true, this recipe will never need to be unlocked.
  • crafting.get_recipe(id)

    • Get recipe by ID
  • crafting.get_unlocked(name)

    • name is the player's name
    • Returns a dictionary of recipe output to boolean.
  • crafting.unlock(name, v)

    • name is the player's name
    • v is a single output or list of outputs
  • crafting.get_all_for_player(player, type, level)

    • Returns a list of results, each a table
      • items - a key-value table, key being item name and value being a table:
        • have - how many the player has
        • need - how many of this item needed
      • recipe - the recipe
      • craftable - is craftable?
    • craftable is a table of the items the player can craft with the items they have.
    • uncraftable is a table of items the player knows about, but is missing items for.
  • crafting.get_all(type, level, item_hash, unlocked)

    • Returns same as above.
    • item_hash - a table with keys being item names or group names (eg: group:wood) and the value being the number required.
    • unlocked - a list of outputs the player has unlocked.
  • crafting.set_item_hashes_from_list(inv, listname, item_hash)

    • Iterates through the list and adds or updates entries in item_hash representing the number of items for each names and group.
  • crafting.find_required_items(inv, listname, recipe)

    • Returns a list of stacks to take, or nil if the required items could not be found.
  • crafting.has_required_items(inv, listname, recipe)

    • Returns true if the "main" list in inv contains the required items.
  • crafting.perform_craft(name, inv, listname, outlistname, recipe)

    • Will try to take itemsfrom listname and put output in the outlistname list in inv.
    • Returns true on success.
  • crafting.make_result_selector(player, type, level, size, context)

    • Generates a paginated form which a search box.
    • type - craft type.
    • size - how many slots to show on a page.
    • context - server-side storage between show and submit, can be {}.
      • crafting_page - page to show
  • crafting.result_select_on_receive_results(player, type, level, context, fields)

    • Handles form submissions for the result selector.
    • Returns true if the formspec should be shown again.
  • crafting.make_on_rightclick(type, level, inv_size)

    • Returns a function to be used as on_rightclick for node work stations.
  • crafting.create_async_station(name, type, level, def_inactive, def_active)

    • Makes a station which players put items into and then leave to craft.
    • Registers two nodes - inactive and active versions of the station.

Development

Installation:

# Dependencies for linter and test framework
sudo apt install luarocks
sudo luarocks install luacheck
sudo luarocks install busted

# Set up git hook to disallow commiting when linter or tests fail
./utils/setup.sh

crafting's People

Contributors

amaz1 avatar derixithy avatar jeremyshannon avatar lonewolfht avatar panquesito7 avatar rubenwardy avatar savilli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crafting's Issues

Context menus for alternatives

It's silly to have a button for each type of tool. Making it so you can click a generic icon then see options would be better - like in terraria

crafting/util.lua:537: attempt to get length of local 'recipes' (a nil value)

under server 5.2.0
client : unknown
story : not known, there is no clear action could explain who or what

mod : cf1ad1b/09.05.2017

guessing, typical client change IP or just disappeared gamer during mod started ...

2022-02-21 22:16:38: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'crafting' in callback nodemeta_inventory_OnTake(): /home/thomas/.minetest/mods/crafting/util.lua:537: attempt to get length of local 'recipes' (a nil value) 2022-02-21 22:16:38: ERROR[Main]: stack traceback: 2022-02-21 22:16:38: ERROR[Main]: /home/thomas/.minetest/mods/crafting/util.lua:537: in function 'get_crafting_result' 2022-02-21 22:16:38: ERROR[Main]: /home/thomas/.minetest/mods/crafting/table.lua:78: in function 'take_craft' 2022-02-21 22:16:38: ERROR[Main]:

Recipe unlock issues

When you change the output amount, for example unlocks_crafts = { "crafts:plant_fibre" } to unlocks_crafts = { "crafts:plant_fibre" 3 }, you create a potential domino effect where the next recipe in a chain might not set always_known = true, and instead depend on an award to unlock it.

If the award in question has unlocks_crafts = { "crafts:plant_fibre" } in the trigger, all of a sudden it's broken and needs to be changed to unlocks_crafts = { "crafts:plant_fibre 3" }, due to the change in the crafting registration.

This could easily lead to unintentional breakages when trying to edit recipes for game balance.

A second issue due to this is that if you define two different crafting recipes for an item and making x amount of that item is the unlock for another recipe, you can't make sure the total needed for the unlock increments with each item made.

A better system would be to have crafting recipes unlock based on total made, not based on total uses of a given recipe.

Add support for 0.4.16

2018-04-04 10:29:18: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sfinv' in callback ScriptApiPlayer::on_joinplayer(): ...\minetest-0.4.16-win32-msvc\bin\..\mods\crafting/api.lua:218: attempt to call field 'sha1' (a nil value)
2018-04-04 10:29:18: ERROR[Main]: stack traceback:
2018-04-04 10:29:18: ERROR[Main]: 	...\minetest-0.4.16-win32-msvc\bin\..\mods\crafting/api.lua:218: in function 'calc_inventory_list_hash'
2018-04-04 10:29:18: ERROR[Main]: 	...test-0.4.16-win32-msvc\bin\..\mods\crafting/stations.lua:27: in function 'get_formspec'
2018-04-04 10:29:18: ERROR[Main]: 	...win32-msvc\bin\..\games\minetest_game\mods\sfinv/api.lua:111: in function 'set_player_inventory_formspec'
2018-04-04 10:29:18: ERROR[Main]: 	...win32-msvc\bin\..\games\minetest_game\mods\sfinv/api.lua:132: in function <...win32-msvc\bin\..\games\minetest_game\mods\sfinv/api.lua:130>
2018-04-04 10:29:18: ERROR[Main]: 	...etest-0.4.16-win32-msvc\bin\..\builtin\game\register.lua:412: in function <...etest-0.4.16-win32-msvc\bin\..\builtin\game\register.lua:392>

Crafting with full inventory

It has happend to me twice. I had full inventory with 4 mese or more. Then I dug something and forgot that I have full inventory and I pressed "craft mese sword" button. And yay mese sword disappeared unknown where, so I didn't get it.
I think this is a bug because sword should be dropped and not wasted when you have full inventory.

Reduce mouse clicking for bulk crafting

It's currently only possible to complete a recipe once per click, which can quickly get less than user friendly.

Can we please add alternatives for bulk crafting? For example, either hold down to complete multiple times or have right/left/middle click trigger the recipe different numbers of times.

Crafting skill and quality

Players have a crafting level which effects how fast and how good what they make is.

Maybe not for simple inventory / workbench crafts, but for more skilled tasks such as sword smithing, clothes, furniture, and art.

Add craft station levels

For example, furnaces could have the levels:

  1. basic station - level 1 recipes only
  2. station - level 2 recipes plus the recipes of the above level 1 station
  3. alien station - level 3 recipes plus the recipes of the above level 2 station

or whatever.

Recipes would then be defined like:

crafting.register_craft({
    type = "furnace",
    level = 2,   -- can be made on Level 2 or 3 furnaces
    output = "default:iron_ingot",
    items = { "default:iron_ore" }
})

Output grouping

I'd like to ask for a feature to group output items so that multiple recipes with the same output gets only one entry in the crafts table.

Like this, as an example:

group 2

Now, obviously I didn’t manage to combine several identical ingredients into one so with better code the tooltip will of course be much shorter.

crash due to https://github.com/minetest/minetest/commit/0b8d3f99a5424113178329e56c2ebe4b38fd2b46

log:

2020-02-24 08:53:55: ERROR[Main]: ModError: Failed to load and run script from /root/.minetest/games/ctf/mods/other/crafting/init.lua:
2020-02-24 08:53:55: ERROR[Main]: /root/.minetest/games/ctf/mods/other/crafting/stations.lua:55: bad argument #1 to 'pairs' (value expected)
2020-02-24 08:53:55: ERROR[Main]: stack traceback:
2020-02-24 08:53:55: ERROR[Main]: 	[C]: in function 'pairs'
2020-02-24 08:53:55: ERROR[Main]: 	/root/.minetest/games/ctf/mods/other/crafting/stations.lua:55: in function 'check_for_changes'
2020-02-24 08:53:55: ERROR[Main]: 	/root/.minetest/games/ctf/mods/other/crafting/stations.lua:67: in main chunk
2020-02-24 08:53:55: ERROR[Main]: 	[C]: in function 'dofile'
2020-02-24 08:53:55: ERROR[Main]: 	/root/.minetest/games/ctf/mods/other/crafting/init.lua:22: in main chunk

(minetest/minetest#9428)

Top player inventory row not visible in crafting bench

Something happened with the top player inventory row in crafting when using the crafting bench and similar stations. It's still visible in the sfinv tab but not in stations. Take a look at this clip (sfinv tab first, station second)

What could be causing this?

I've tried it both in 0.4.17.1 and in 0.5.0-dev with the same results.

Add furnace

Should support multiple inputs for alloying, and a fuel slot, and have multiple outputs
One of the only machines you can leave running

Inventory window optimisation

Actual for version 75c9240
As far as I understand, function crafting.make_result_selector is called on each update of player inventory: on opening, on filtering and on switching pages.
It does a lot of string concatenation, which can be avoided.

I propose to store inventory formspecs in special array in crafting object for each filtering query and for each inventory page.
It will take more server memory at the cost of speed of construction inventory screen window

Add ability to unlock recipes

Not sure how to do this. Games may want tech trees or just random unlocks, it's better to provide a nice API for this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.