Advertisement
cmoa

ComputerCraft Builder

Feb 20th, 2020
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.52 KB | None | 0 0
  1. --                              File: Builder
  2. --                              Author: cmoa
  3. --                              Version: 0.1
  4. --                       Required mod: Computercraft
  5. --
  6. --                   This is currently an alpha version.
  7. --                   The creator AND ONLY HIM is allowed
  8. --                     to distribute this document. If
  9. --                     you got it from a third person,
  10. --                     you need to ask the creator the
  11. --                       permission to use this file.
  12.  
  13.  
  14.  
  15.  
  16.  
  17. --[[
  18.  
  19.    Initialisation
  20.  
  21. ]]--
  22.  
  23. w,h = term.getSize()
  24. init_args = { ... }
  25. init_command = init_args[1]
  26. init_parameter = init_args[2]
  27. builds_names = {"wood_house","tower","dog_house","cobble_castle"}
  28. builds_names_village = {"small_1","small_2","small_3","big_1","big_2","library","forge","church","light_post","weel","farm"}
  29. builds_materials = {{{57,"planks",0},{12,"log",0},{64,"oak_stairs"},{6,"oak_stairs"},{6,"wooden_slab",0},{8,"glass_pane"},{1,"wooden_door"},{1,"crafting_table"},{2,"furnace"},{2,"chest"},{1,"bed"},{4,"torch"},{1,"wooden_pressure_plate"}},{{59,"cobblestone"},{4,"stone_stairs"},{4,"stone_slab",3},{1,"iron_door"},{2,"stone_button"},{5,"ladder"},{1,"crafting_table"},{1,"chest"},{2,"torch"}},{{2,"log"},{3,"planks",0},{5,"oak_stairs"},{5,"wooden_slab",0},{2,"wool"},{1,"torch"},{1,"item_frame"},{1,"bone"}},{{7,"cobblestone"},{1,"water_bucket"},{1,"lava_bucket"}},{}}
  30. builds_materials_village = {{},{},{},{},{},{},{},{},{{3,"fence"},{1,"wool",15},{4,"torch"}},{{60,"cobblestone"},{8,"fence"},{1,"water_bucket"},{1,"water_bucket"}},{{28,"log",0},{28,"dirt",0},{1,"water_bucket"},{1,"water_bucket"},{1,"water_bucket"},{1,"water_bucket"}}}
  31.  
  32. castle_blueprint = "[j(#022~)]q[j(#009~)]np0gpgpglq1gn0gpgpgpgo2ijr0[[[(:~).(#005j.k~)](:~)]s(#005~)]ojqghpgpglnhs[>^(#016~)]q0[[[(:~).(#005j.k~)](:~)]s(#886~)]pjjjjpjjjjjr[[[(!,^)hj(#024~)]jqjj(#004~)](#009~)n][j(#024~)]ooooooq[j(#013~)]psmsmoslslslsosmsmsmsoslslslsp[j(#011~)][[nh(#009~)]pjooooooooo[j(#023~)](#004~)j]p[j(#019~)]nll0[(#016~)>^]r0[[[(:~).(#005j.k~)](:~)]s(#864~)]pjoojjjjjnnpjjjjjr[[[(!,^)hj(#024~)]jjjqjjjj(#004~)](#009~)n]jjjjjqjjjoooooooojjjq0[(#016~)>^]r0[[[[(:~).(#005j.k~)](:~)]s(#064~)](#016~)]rjjjjjjoojjjqjjjjjj[[kg(#031~)]pkgp[kg(#031~)]q(#016~)kgq^]nh5jp[j(#014~)]psmsmsmsnslslslsnsmsmsmsnlslsr[j(#022~)]qjjjjjjjjjoo[>^(#016~)]0qj[[[(:~).(#005j.k~)](:~)]s(#722~)]rjjjjjjjjjjqojj[jjhjhjhjqjhjhjhj(#004qjjjsjurjjjjq)o[nhpjpjhjhjhljhpjmhjhjhljhpjjpjjh(#010~)jjqjj]qjjqjgpn[jjh(#006~)](#002pjooooooooooljjqhjhjhjhqjjpnjhjhjhrnjhjhnhnjhnjhjoooojjhjhjhrnjhjhnhnjhnjhnnnnnm)[jhj(#006~)]pjjjq(#004~)[o(#010~)]][jhljjhjjqjhljjhjjqjhjp[jjh(#006~)][jhj(#006~)]l(#004~)]qjjpoooo[ooooo(#005~)jjj(#002p)(#004p)jrgq(#002r)(#004r)[hgn(#004~)np(:qjjq)rlj]plgpgpgo(#002q)(#004q)gqgmgmgqgqgoijpjsiqjiqjipjirjpjipjsiqjiqjipjiqjp[ijijpsqij(#008~)]i]rjjqvrjjrvr[>^(#016~)]0jjjjjj[[[(:~).(#005j.k~)](:~)]s(#873~)]"
  33. castle_next = "ljjjjjj[[hj(#011~)]q[hj(#008~)]qhjhjhjhjhjqhjhjhjp[hj(#006~)]qhjhjhjhjh(#008~)njq]   qjoooooooqijqsilsipjilsilsipjihpjihrgqjijiqjijiqjijihqjigrg   pjnnhjgnghpjjjqsqjjjpnghnhpjjpgrgmgpgpglgqgqgmgkgkg   "
  34. castle_next2= "nhnq[hgm(#)]"
  35.  
  36. builds_blueprints = {"jhjhjhjhjhqjhqjhjhjhpjhpjhjhjhjqjnr1hj0hjhjhj1hpj0hjhjhjhj1hpjj0hjhj1hpj0hjhjhjhjnp1hj5hjhjhj1hpj0hj5hjhj0hj1hpjj0hj5hj1hpj0hj5hjhj0hjnp1hj0hjhjhj1hpj0hjhjhjhj1hpj0hjhjhj1hpj0hjhjhjhnl3hlhlhplhlhpjhl2hlhplhlhrjooqbgrjgoorjq9glgqjr7grjl8gmgmj6grjagrcglnnnnljj0hqjhjhrglglglglglhjhjhrgn4glglglglglgljop2ioriqjjjoorimimimimimimimijnnnlghlghlghlghlghlghlgooioriknirjbijjnnr2glghlghlghlghlghlghljjpiorilqijjriorirjbij2ijriorirjjjjnriorijrimimimimimimimjjnrijriorijrijjpo","mjjjrgnhnhgnhgnhgkgqjrgoigoigoigoigkgqjrgnhgnhgnhgnhgkgkgogogogk4goj0gmjjr0hjh3gr5gngngng0hnh5gnj7grj6hjnp0hjhj2hpj0hjhjhj2hpj0hjhjhj2hpj0hjhjhj2hk0grjjgrgpjjp0gqjr8gqm0grjjgrgpjjpgmjooioqjqjjq1ipjjqjjqipjjqjjqipjjqjjqi8hmoojp4gpjr0grjqjqo","j4hjhq1gpgpgpjqjn0hnr2hpjjorh3gpjjrgpg2hnjqjqhrj3hlqgoojq5gqjr6g7gn0hn2hljqoo",castle_blueprint,castle_next,castle_next2}
  37. builds_blueprints_village = {"jj3hjhjhqjqhjhjhj2hqjhjhqjhjhjhjhqjhjhjhqjhjhjhjhn0hqj1hjj0hqj1hjhjhj0hqj1hjhj0hqj1hjhjhjn0hqj1hjj0hqj1hj5hj1hj0hqj1hjhj0hqj1hj5hj1hjn0hqj1hjhj0hqj1hjhjhj0hqj1hjhj0hqj1hjhjhjnrj0hjhjhjpjphjhjhjhjhqjqhjhjhjooo6hn7hnn0hjhpjpjhjhjhljjoooor4g","j0hqjhjhpjhjhjhjhpjhjhjhjhpjhjhjhjhpjhpjhjhjhqjhjhqjhqjhpjhpjhmn1hj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjjnhj0hpj1hj3hj1hj0hpj1hj3hj1hj0hpj1hj3hj1hj0hpj1hjjnhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhlq4hjnp2hjhjhpjhjhjhjhpjhjhjhjhpjhjhjhjhpjhpj1hjhjhqjhqjhjhpjhpjhjhrmjjjjroooo","j0hqjhjhpjhjhjhjhpjhjhjhjhpjhjhjhjhpjhpjhjhjhqjhjhqjhqjhpjhpjhmn1hj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjjnhj0hpj1hj3hj1hj0hpj1hj3hj1hj0hpj1hj3hj1hj0hpj1hjjnhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhjhj0hpj1hjhlq4hjnp2hjhjhpjhjhjhjhpjhjhjhjhpjhjhjhjhpjhpj1hjhjhqjhqjhjhpjhpjhjooo5hnhnhnrhrnjq6hjqhjhjhjhjqhjhjhjhjqhjhjhjhjqhjhjhqjjjjjrooooo","j1hqjhjhpjhjhjhjhj0hpjhjhqjhjhjhjhjhpjhjhjhjhjhjhpjhjhjhjhjhjhjhjhjhjhpjhjhjhjhjhjnjhjhpjhjhjhjhjhpjhjhqjhjhjhjhjhpjhjhjhjhjhjhpjhjhjhjhjhjhjhjhjhjhpjhjhjhjhjhn4hjjhj1hpj7hj8hjhj7hj1hpj2hjhqj7hj8hjhj7hj1hpjhjhjhjhjhjphj7hj8hjhj7hj4hj7hj8hjhj7hj1hpj4hj7hj8hj7hjnjjjp1hjhjhjhjhjphj2hjhqj1hjhjhjhjphjhjhjhjhjhjphjhjhjhjhjhjhjhjhjhjphj2hjhjhjhjhjhjloqgqagosoq2hjhjhjhpjhpjhjhjhqjhqjhjhjhjhjhjhjhjhpjhpjhjhjhjhjhjhjhjhqjhqjhjhjhjhjhjhjhjhpjhpjhjhjhjhjhjhjhjhqjhqjhjhjhjhjhjhjhjh   mnnnjp3glgilgilgilgilgilgilgilglgmpgilgilgilgilgilglgmpgilglgmpgilgilgilijijqgilgilgilgilgilgn7hrj8hj7hrj3grgnhnhpjhjhjhjhjhjhjohnhpjjjjjo4hqjhqjjjjjjjjloqhjhjhjhnrjhjhpjhpjhjjor5gmghpglghlghlghlghlghnjgmgmgmgmgmgqmjglglgnphjjjjjlllooooqglgqgmgmgmgnnjjghlghlghlghlghljpglqgpghlghlghnjgmgmgmgmglqgmgmgmgmgmgmgnpjjjjjjjjjpjjjopglglglgl6glglglglgkoghmghmghmghmghmghmghmghmghrjjrooglglglglglglglglgojoqjjjjjjp9g","","","","","gngngn1gn2hljqhljqhljqhloooojq","pjjqhjhjhjhjhjhqjqhjhjhjhjhjhpjphjhj2hjtj0hjhqjqhjhj3hjtj0hjhpjphjhjhjhjhjhqjqhjhjhjhjhjhqjqjnhjhjhjhpjhjhjhpjhjhjhpjhjh1gngrjgogqjjjpgngrjgognnnjq0hjhjhjhqjqhjhjhjhpjphjhjhjhqjqhjhjhjhrjjjjpjpoooo","njphjhjhjhjhqjhjhjhjhjhjhqjhjhjhjhjhjhjhjhqjhjhjhjhjhjhqjhjhjhrjjpjp1hjhjhjhjhjhjhqjqhjhjhjhjhjhjhpjjphjhjhjhjhjhjhqjqhjhjhjhjhjhjhqjjq2hjtj3hjtj4hjtj5hpjjjjpjjjpo"}
  38.  
  39.  
  40.  
  41.  
  42.  
  43. --[[
  44.  
  45.   Blueprint help
  46.  
  47.     0-f = select slot
  48.     g = break and place
  49.     h = break and place down
  50.     i = break and place up
  51.     j = break and move forward
  52.     k = break and move back
  53.     l = break and move left
  54.     m = break and move right
  55.     n = break and move up
  56.     o = break and move down
  57.     p = turn left
  58.     q = turn right
  59.     r = half turn
  60.     s = break
  61.     t = break down
  62.     u = break up
  63.     v = place
  64.     w = place down
  65.     x = place up
  66.  
  67.     . = wait 1s
  68.     < = suck
  69.     > = drop
  70.     ^ = select next slot
  71.     ? = select random slot
  72.  
  73.     ( = if x then ...
  74.       ! = NOT
  75.       # = loop counter is xxx
  76.       : = block in front
  77.       _ = refuel
  78.       , = block in slot
  79.  
  80.     ) = if end
  81.     [ = loop ...
  82.     ] = end loop
  83.     ~ = break loop
  84.  
  85. ]]--
  86.  
  87.  
  88.  
  89.  
  90.  
  91. --[[
  92.  
  93.    Sub fonctions
  94.  
  95. ]]--
  96.  
  97. function mid(mid_string, mid_place)
  98.   return string.sub(string.reverse(string.sub(string.reverse(mid_string),string.len(mid_string)-mid_place+1)),mid_place)
  99. end
  100.  
  101. function inString(instr_string, instr_item)
  102.   for instr_i = 1,string.len(instr_string) do
  103.     if(mid(instr_string,instr_i) == instr_item) then
  104.       return instr_i
  105.     end
  106.   end
  107.   return false
  108. end
  109.  
  110. function lenth(len_item)
  111.   if(type(len_item) == "string") then
  112.     return string.len(len_item)
  113.   else
  114.     return table.maxn(len_item)
  115.   end
  116. end
  117.  
  118. function index(index_list, index_item)
  119.   for index_i = 1,lenth(index_list) do
  120.     if index_list[index_i] == index_item then
  121.       return index_i
  122.     end
  123.   end
  124.   return nil
  125. end
  126.  
  127. function online(onl_url)
  128.   if(type(onl_url) ~= "string") then error("Called function online() but got "..onl_url.."instead of an URL string.") return end
  129.   onl_blueprint = ""
  130.   onl_materials = {}
  131.   return onl_blueprint,onl_materials
  132. end
  133.  
  134.  
  135.  
  136. function refuel(refuel_blueprint)
  137.   turtle.select(1)
  138.   refuel_fuel = 0
  139.   for refuel_i = 1,string.len(refuel_blueprint) do
  140.     if(inString("jklmno",mid(refuel_blueprint,refuel_i))) then refuel_fuel = refuel_fuel +1 end
  141.   end
  142.   if(refuel_fuel > turtle.getFuelLevel()) then
  143.     print("Need "..math.ceil((refuel_fuel-turtle.getFuelLevel())/80).." coal (="..refuel_fuel.." levels.)")
  144.     repeat
  145.       sleep(0)
  146.       turtle.refuel(1)
  147.     until turtle.getFuelLevel() >= refuel_fuel
  148.     if(turtle.getItemCount() > 0) then
  149.       print("Please remove fuel.")
  150.       repeat until turtle.getItemCount() == 0
  151.     end
  152.   end
  153. end
  154.  
  155. function wait_materials(mat_build,mat_type)
  156.   turtle.select(1)
  157.   if mat_type == 1 then
  158.     if mat_build > 0 then
  159.       mat_list = builds_materials[mat_build]
  160.     else
  161.       mat_list = builds_materials_village[-mat_build]
  162.     end
  163.   end
  164.   if(turtle.getItemCount() ~= 0) then
  165.     if(turtle.getItemDetail().name == "minecraft:coal") then
  166.       print("Please remove fuel.")
  167.       repeat until turtle.getItemDetail().name ~= "minecraft:coal"
  168.     end
  169.   end
  170.   if(mat_list == nil) then
  171.     print("WARNING: No material list found. Running blind! You have 10 seconds to feed the correct materials.")
  172.     os.sleep(10)
  173.     return
  174.   end
  175.   print("Please give the folowing materials:")
  176.   for mat_i = 1,lenth(mat_list) do
  177.     turtle.select(mat_i)
  178.     mat_count = mat_list[mat_i][1]
  179.     mat_name = mat_list[mat_i][2]
  180.     mat_damage = mat_list[mat_i][3]
  181.     if mat_damage == nil then
  182.       print("Slot "..mat_i..": "..mat_count.."x "..mat_name)
  183.     else
  184.       print("Slot "..mat_i..": "..mat_count.."x "..mat_name..":"..mat_damage)
  185.     end
  186.     repeat
  187.       repeat
  188.         while turtle.getItemCount() == 0 do
  189.           os.queueEvent("turtle_inventory")
  190.           os.pullEvent()
  191.         end
  192.       until turtle.getItemDetail().name == "minecraft:"..mat_name
  193.     until turtle.getItemDetail().count == mat_count
  194.   end
  195. end
  196.  
  197. function empty()
  198.   empty_remaining = false
  199.   for empty_i=1,16 do
  200.     turtle.select(empty_i)
  201.     if turtle.getItemCount() ~= 0 then empty_remaining = true end
  202.   end
  203.   if empty_remaining then
  204.     print("Emptying items!")
  205.     turtle.turnLeft()
  206.     turtle.turnLeft()
  207.     for empty_i=1,16 do
  208.       turtle.select(empty_i)
  209.       turtle.drop()
  210.     end
  211.     turtle.turnRight()
  212.     turtle.turnRight()
  213.   end
  214.   turtle.select(1)
  215. end
  216.  
  217.  
  218.  
  219.  
  220.  
  221. --[[
  222.  
  223.    Here are all the functions that
  224.    you can use.
  225.  
  226. ]]--
  227.  
  228. function help()
  229.   term.clear()
  230.   textutils.pagedPrint('Use "builder build <number|name|url>" to start building.\nUse "builder list ["village"]" to get a list of the possible builds.\nUse "builder materials <number|name|url>" to get the list of the required resources.\nUse "builder tutorial" to get a tutorial on how to use this program.\nUse "builder infos" for more informations/credits.',h-3)
  231. end
  232.  
  233. function credits()
  234.   term.clear()
  235.   term.setCursorPos(1,1)
  236.   print("This program is supposed to help you construct a large quantity of builds automatically.")
  237.   print("The turtle knows the required amount of fuel and items.")
  238.   print("Just give it, sit back and relax while it build you the build of your dreams.")
  239.   print()
  240.   print()
  241.   print("Created by cmoa. V0.1 (under construction)")
  242.   term.setCursorPos(1,h)
  243. end
  244.  
  245. function list()
  246.   if(init_parameter ~= "village") then
  247.     lst_len = lenth(builds_names)
  248.     print("There are "..lst_len.." builds availiable")
  249.     for lst_i = 1,lst_len do
  250.       print(lst_i..": "..builds_names[lst_i])
  251.     end
  252.     print('You can download custom ones using "builder build <url>".')
  253.   else
  254.     print("There are 11 village houses availiable")
  255.     for lst_i = 1,11 do
  256.       print("-"..lst_i..": "..builds_names_village[lst_i])
  257.     end
  258.   end
  259. end
  260.  
  261. function materials(materials_build,materials_type)
  262.   if materials_type == 1 then
  263.     if materials_build > 0 then
  264.       print("Materials for "..builds_names[materials_build]..":")
  265.       materials_list = builds_materials[materials_build]
  266.     else
  267.       print("Materials for village house "..builds_names[-materials_build]..":")
  268.       materials_list = builds_materials_village[-materials_build]
  269.     end
  270.   end
  271.   if materials_type == 2 then
  272.     print("Materials for online build:")
  273.     materials_list,a = online(materials_build)
  274.   end
  275.   materials_to_print = ""
  276.   for materials_i = 1,lenth(materials_list) do
  277.     materials_count = materials_list[materials_i][1]
  278.     materials_name = string.lower(materials_list[materials_i][2])
  279.     materials_damage = materials_list[materials_i][3]
  280.     if materials_damage == nil then
  281.       materials_to_print = materials_to_print..materials_count.."x "..materials_name.."\n"
  282.     else
  283.       materials_to_print = materials_to_print..materials_count.."x "..materials_name..":"..materials_damage.."\n"
  284.     end
  285.   end
  286.   materials_to_print = string.reverse(string.sub(string.reverse(materials_to_print),2))
  287.   textutils.pagedPrint(materials_to_print,h-3)
  288. end
  289.  
  290. function move()
  291.   print("Under construction")
  292.   return
  293. end
  294.  
  295. function tutorial()
  296.   print("Under construction")
  297.   return
  298. end
  299.  
  300. function build(build_build,build_type)
  301.   build_blueprint = nil
  302.   if(build_type == 1 or build_type == 3) then
  303.     if build_build > 0 then
  304.       build_blueprint = builds_blueprints[build_build]
  305.     else
  306.       build_blueprint = builds_blueprints_village[-build_build]
  307.     end
  308.   else
  309.     if(build_type == 2) then
  310.       build_blueprint = build_build
  311.       print("building: "..build_build)
  312.     else
  313.      
  314.     end
  315.   end
  316.   build_len = string.len(build_blueprint)
  317.   refuel(build_blueprint)
  318.   wait_materials(build_build,build_type)
  319.   turtle.select(1)
  320.   build_progress = true
  321.   loop_start,loop_end,loop_counter = {},{},{}
  322.   loop_number = 0
  323.   if_start,if_end = {},{}
  324.   if_number = 0
  325.   if(inString(build_blueprint,"[") or inString(build_blueprint,"(")) then
  326.     print("Warning: Build contains loops or/and conditions which changes the amount of steps. This is why progress messages won't be desplayed. Also make sure to have enough fuel!")
  327.     build_progress = false
  328.   end
  329.   print("Building...")
  330.   os.sleep(2)
  331.   build_i = 0
  332.   step_i = 0
  333.   stats_moves,stats_turns,stats_place = 0,0,0
  334.   repeat
  335.     sleep(0)
  336.     build_i = build_i + 1
  337.     if build_progress then if(math.fmod(build_i,10) == 0) then print(build_i.."/"..build_len) end end
  338.     build_char = string.lower(mid(build_blueprint,build_i))
  339.     print(build_char.." "..build_i)
  340.     local slot = inString("0123456789abcdef",build_char)
  341.     if(slot) then turtle.select(slot) end
  342.     if(inString("ghivwx",build_char) and turtle.getItemCount()==0) then turtle.select(turtle.getSelectedSlot()%16+1) print(switched) end
  343.     if(build_char == "g") then turtle.dig() turtle.place() stats_place=stats_place+1 end
  344.     if(build_char == "h") then turtle.digDown() turtle.placeDown() stats_place=stats_place+1 end
  345.     if(build_char == "i") then turtle.digUp() turtle.placeUp() stats_place=stats_place+1 end
  346.     if(build_char == "j") then turtle.dig() turtle.forward() stats_moves=stats_moves+1 end
  347.     if(build_char == "k") then turtle.turnLeft() turtle.turnLeft() turtle.dig() turtle.forward() turtle.turnRight() turtle.turnRight() stats_moves=stats_moves+1 stats_turns=stats_turns+4 end
  348.     if(build_char == "l") then turtle.turnLeft() turtle.dig() turtle.forward() turtle.turnRight() stats_moves=stats_moves+1 stats_turns=stats_turns+2 end
  349.     if(build_char == "m") then turtle.turnRight() turtle.dig() turtle.forward() turtle.turnLeft() stats_moves=stats_moves+1 stats_turns=stats_turns+2 end
  350.     if(build_char == "n") then turtle.digUp() turtle.up() stats_moves=stats_moves+1 end
  351.     if(build_char == "o") then turtle.digDown() turtle.down() stats_moves=stats_moves+1 end
  352.     if(build_char == "p") then turtle.turnLeft() stats_turns=stats_turns+1 end
  353.     if(build_char == "q") then turtle.turnRight() stats_turns=stats_turns+1 end
  354.     if(build_char == "r") then turtle.turnLeft() turtle.turnLeft() stats_turns=stats_turns+2 end
  355.     if(build_char == "s") then turtle.dig() end
  356.     if(build_char == "t") then turtle.digDown() end
  357.     if(build_char == "u") then turtle.digUp() end
  358.     if(build_char == "v") then turtle.place() stats_place=stats_place+1 end
  359.     if(build_char == "w") then turtle.placeDown() stats_place=stats_place+1 end
  360.     if(build_char == "x") then turtle.placeUp() stats_place=stats_place+1 end
  361.  
  362.     -- Special characters
  363.     if(build_char == ".") then os.sleep(1) end
  364.     if(build_char == "<") then turtle.suck() end
  365.     if(build_char == ">") then turtle.drop() end
  366.     if(build_char == "^") then turtle.select(turtle.getSelectedSlot()%16+1) end
  367.     if(build_char == "?") then turtle.select(math.random(16)) end
  368.     if(build_char == "[") then
  369.       sleep(0)
  370.       table.insert(loop_start,build_i)
  371.       table.insert(loop_counter,1)
  372.       loop_index = 1
  373.       loop_i = 0
  374.       for loop_j = build_i+1,build_len do
  375.         loop_char = mid(build_blueprint,loop_j)
  376.         if(loop_char=="[") then
  377.           loop_index = loop_index + 1
  378.         end
  379.         if(loop_char=="]") then
  380.           loop_index = loop_index - 1
  381.           if(loop_index==0) then loop_i = loop_j break end
  382.         end
  383.       end
  384.       table.insert(loop_end,loop_i)
  385.       loop_number = loop_number + 1
  386.     end
  387.     if(build_char == "]") then
  388.       build_i = loop_start[lenth(loop_start)]
  389.       loop_counter[loop_number] = loop_counter[loop_number] + 1
  390.     end
  391.     if(build_char == "~") then
  392.       while true do
  393.         if(if_number == 0) then break end
  394.         if(if_end[if_number] > loop_end[loop_number]) then break end
  395.         table.remove(if_start,if_number)
  396.         table.remove(if_end,if_number)
  397.         if_number = if_number - 1
  398.       end
  399.       build_i = loop_end[loop_number]
  400.       table.remove(loop_start,loop_number)
  401.       table.remove(loop_end,loop_number)
  402.       table.remove(loop_counter,loop_number)
  403.       loop_number = loop_number - 1
  404.     end
  405.     if(build_char == "(") then
  406.       if_index = 1
  407.       if_i = 0
  408.       for if_j = build_i+1,build_len do
  409.         if_char = mid(build_blueprint,if_j)
  410.         if(if_char=="(") then
  411.           if_index = if_index + 1
  412.         end
  413.         if(if_char==")") then
  414.           if_index = if_index - 1
  415.           if(if_index==0) then if_i = if_j - 1 break end
  416.         end
  417.       end
  418.       build_i = build_i + 1
  419.       if_condition = false
  420.       if_not = false
  421.       if(mid(build_blueprint,build_i) == "!") then if_not = true build_i = build_i + 1 end
  422.       if_char = mid(build_blueprint,build_i)
  423. --      print(if_char)
  424.       if(if_char == "#") then
  425.         if(tonumber(string.reverse(string.sub(string.reverse(string.sub(build_blueprint,build_i+1)),build_len-build_i-2))) == loop_counter[loop_number]) then
  426.           if_condition = true
  427.         end
  428.         build_i = build_i + 3
  429.       end
  430.       if(if_char == ":") then if(turtle.detect()) then if_condition = true end end
  431.       if(if_char == "_") then if(turtle.refuel()) then if_condition = true end end
  432.       if(if_char == ",") then if(turtle.getItemCount() ~= 0) then if_condition = true end end
  433. --      print(if_condition)
  434.       if if_condition ~= if_not then
  435.         table.insert(if_start,build_i)
  436.         table.insert(if_end,if_i)
  437.       else
  438.         build_i = if_i
  439.       end
  440.       if_number = if_number + 1
  441.     end
  442.     if(build_char == ")") then
  443.       table.remove(if_start,if_number)
  444.       table.remove(if_end,if_number)
  445.       if_number = if_number - 1
  446.     end
  447.  
  448. --    os.sleep(0.5)
  449.   until build_i >= build_len
  450. --  empty()
  451.   print()
  452.   print("Success !")
  453.   print()
  454.   print("Moves: "..stats_moves..", Turns: "..stats_turns.." Place: "..stats_place)
  455. end
  456.  
  457.  
  458.  
  459.  
  460.  
  461. --[[
  462.  
  463.    Calling the correct function.
  464.  
  465. ]]--
  466.  
  467. if(init_command == nil) then print('You need to specify a command. To see the complete list use "builder help"') return end
  468. local init_build,init_type
  469. if(init_parameter ~= nil) then
  470.   init_build = tonumber(init_parameter)
  471.   if(init_build == nil) then init_build = index(builds_names, init_parameter) end
  472.   if(init_build == nil) then init_build = index(builds_names_village, init_parameter) if(init_build) then init_build = -init_build end end
  473.   --if(init_build == nil) then init_build = online(init_parameter) end
  474.   if(init_build == nil) then print('Building "'..init_parameter..'" not found. Please use "builder list" to get the list of all the possible buildings') end
  475.   if(type(init_build) == "number") then
  476.     init_type = 1
  477.     if(init_build >= 0) then
  478.       if(init_build == 0 or init_build > lenth(builds_blueprints)) then
  479.         print('Building "'..init_parameter..'" not found. Please use "builder list" to get the list of all the possible buildings.')
  480.         return
  481.       end
  482.     else
  483.       if(init_build < -11) then
  484.         print('Village house "'..init_parameter..'" not found. Please use "builder list village" to get the list of all the possible houses.')
  485.         return
  486.       end
  487.     end
  488.   else
  489.     init_type = 2
  490.   end
  491. end
  492. if init_command == "help" then help() return end
  493. if init_command == "build" then build(init_build,init_type) return end
  494. if init_command == "custom" then build(init_parameter,2) return end
  495. if init_command == "list" then list() return end
  496. if init_command == "materials" then materials(init_build,init_type) return end
  497. if init_command == "move" then move() return end
  498. if init_command == "tuto" or init_command == "tutorial" or init_command == "start" or init_command == "started" then tutorial() return end
  499. if init_command == "infos" or init_command == "credits" then credits() return end
  500. if init_command == "refuel" then for i=1,16 do turtle.select(i) repeat until not turtle.refuel() end turtle.select(1) return end
  501. if init_command == "empty" then empty() return end
  502. print('No command with the name "'..init_command..'" found. Use "builder help" to get a list of all possible commands.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement