Tip on Lua controlled Tube (use for sorting)

Ruggila
New member
 
Posts: 4
Joined: Fri Aug 31, 2018 09:29
In-game: Ruggila

Tip on Lua controlled Tube (use for sorting)

by Ruggila » Sat Sep 01, 2018 14:51

When playing minetest, I like to have an automatic sorter:

    * I put all my mined thing into a chest
    * a stackwise Filter-Injector pulls them out, powered by a blinky plant
    * then things go into a sorter network
    * exits are of course grinder, furnace, centrifuge, battery box (to recharge), workshop
    * and of course lots of chests

I've seen similar setups by other players. However, most of the other players just used the "Sorting Pneumatic Tube Segment". I use them, too. But I also use "Lua controlled Tube". And here is how:

The tubes are event driven, so I need to react to events. Here is an example of my first Lua controlled tube after my incoming chest:

Code: Select all
if event.type == "item" then
   local s = event.item.name

   -- grinder
   if s == "default:copper_lump" or
      s == "default:gold_lump" or
      s == "default:iron_lump" or
      s == "forge:slag" or
      s == "moreores:mithril_lump" or
      s == "moreores:silver_lump" or
      s == "moreores:tin_lump" or
      s == "technic:chromium_lump" or
      s == "technic:uranium_lump" or
      s == "technic:zinc_lump" or
      s == "technic_aluminum:alumina_lump" then
       return "green"
   end

   -- furnace
   if s == "forge:slag" or
      s == "mobs:rotten_flesh" or
      s == "technic:chromium_dust" or
      s == "technic:copper_dust" or
      s == "technic:gold_dust" or
      s == "technic:mithril_dust" or
      s == "technic:silver_dust" or
      s == "technic:tin_dust" or
      s == "technic:wrought_iron_dust" or
      s == "technic:zinc_dust" or
      s == "technic_aluminum:aluminum_dust" or
      s == "technic_aluminum:bauxite_lump" then
       return "black"
   end

   -- small centrifuge
   if s == "technic_aluminum:alumina_dust" then
       return "yellow"
   end

   return "red"
end


The Lua controlled tubes have colored connections, and you simply return the color of where you want the specific item to end up.

The second Lua controlled tube is done like this:

Code: Select all
if event.type == "item" then
   local s = event.item.name

   -- workshop
   if s == "bones:bone_scythe" or
      s == "cottages:hammer" or
      s == "default:axe_diamond" or
      s == "default:axe_mese" or
      s == "default:pick_diamond" or
      s == "default:pick_mese" or
      s == "default:axe_diamond" or
      s == "default:axe_mese" or
      s == "default:hoe_diamond" or
      s == "default:hoe_mese" or
      s == "default:shovel_diamond" or
      s == "default:shovel_mese" or
      s == "default:sword_diamond" or     
      s == "default:sword_mese" or
      s == "technic:treetap" or
      s == "technic_aluminum:sword_aluminum" or
      s == "screwdriver:screwdriver" or
      s:sub(1,8) == "3d_armor" or
      s:sub(1,6) == "shield" or
      s:sub(1,9) == "stairpick" then
       return "black"
   end

   -- charger
   if s == "technic:chainsaw" or
      s == "technic:prospector" or
      s == "technic:sonic_screwdriver" or
      s == "teletool:teletool_technic" or
      s:sub(1,13) == "technic:laser" or
      s:sub(1,20) == "technic:mining_drill" then
      return "yellow"
   end

   -- go-box
   if s == "bridgetool:bridge_tool" or
      s == "carts:cart" or
      s == "default:torch" or
      s == "default:ladder_wood" or
      s == "farming:corn" or
      s == "landrush:landclaim" or
      s == "more_chests:wifi" or
      s == "protector:protect" or
      s == "travelnet:elevator" or
      s:sub(1,11) == "bridgetool:" then
       return "white"
   end

   --- sort1
   return "red"
end


Here you already see the use of
Code: Select all
s:sub(start,end)
idiom to test on substrings. I use this because them item name sometimes changes, e.g. the drill has several modes of operation. So I only search at the start of the string for the decision if the item should go to the battery box for recharging.

Substrings can also be used to have chests that get items from a whole mod. With normal pneumatic sorter tubes this is almost impossible, they only can select by 6 items. But to check if an item is from a mod is a single instruction in Lua:

Code: Select all
if event.type == "item" then
   local s = event.item.name

   if s:sub(1,7) == "technic" then
     return "black"
   end

   return "red"
end
 

silvery_magnus
New member
 
Posts: 1
Joined: Wed May 11, 2016 10:29
 

User avatar
DS-minetest
Member
 
Posts: 1026
Joined: Thu Jun 19, 2014 19:49
Location: in front of my pc (which is at home)
GitHub: DS-Minetest
In-game: DS

Re: Tip on Lua controlled Tube (use for sorting)

by DS-minetest » Sun Nov 11, 2018 09:41

Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 


Return to General Discussion



Who is online

Users browsing this forum: No registered users and 6 guests