Skip to main content

I will be streaming February sixth, 14:00 UTC.

Also watch on these platforms:

There are a variety of ways to change something in an inventory, in the video I cover two methods, but I discovered a third method after the recording which I'll include here as well.

The simplest way if you only have one or two items that can be changed is to do something like this:

if input == 'toaster:bread' then
         inv:set_stack('input', 1 ,'toaster:toast1')

​In code you need to manually define all the available inputs and outputs, not great if you have a lot of items you can change.

The second method will only work if you are registering all the nodes/craftitems that can be changed with your machine and adds a new line to the registration that looks something like this:

   returns = 'toaster:toast2',

returns can be any variable name you want, and the value that is assigned can of course also be anything you'd like. To use that data you just need to use a bit of code like this:

local return_product = minetest.registered_items[instack:get_name()]
      inv:set_stack('input', 1 ,return_product.returns)

Check out the full code in the provided download to get a more full example. In a nutshell we're just referencing the table of the registered items and pulling the 'returns' value. If you assigned a different name to the variable you'd need to use that in place of .returns.

The third method uses a table and table lookup like the previous example, but the table is created independently of the nodes, so you don't have to override or register the nodes to add data to the table. The table looks something like this:[key] = value

the key would be the name of the expected input and the value would be the name of the output. The table can either be created manually or be placed into a function that automatically populates the table while registering items. To pull the data you'd use something similar to the previous example.

local return_product = minetest.registered_items[instack:get_name()]
      inv:set_stack('input', 1 ,[return_product])

The only difference is the table lookup is being done on the table you created rather than the registered items table that Minetest creates when loading all the nodes and items. I used this method in my tombs mod after much bashing my head into the wall to try and figure out how I could control many input/output combinations.