Advertisement
UNOBTANIUM

Fireworks Crafting Helper

Jul 29th, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.53 KB | None | 0 0
  1. -- Fireworks Crafting Helper by UNOBTANIUM
  2. -- VERSION 1.0.0
  3.  
  4. local w, h = term.getSize()
  5. local fancy = term.isColor and term.isColor()
  6. local color = {"white","orange","magenta","light blue", "yellow","lime","pink","gray","light gray","cyan","purple","blue","brown","green","red","black"}
  7. local colorName = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black}
  8. local dye = {"bonemeal","orange dye","magenta dye","light blue dye", "dandelion yellow","lime dye ","pink dye","gray dye","light gray dye","cyan dye","purple dye","blue dye","cocoa bean","cactus green","rose red","ink sac"}
  9. local ingredient = {"bone from skeleton","red rose + dandelion yellow","purple dye + pink dye","lapis lazuli + bone meal", "yellow dandelion (flower)","cactus green + bone meal ","rose red + bone meal","ink sac + bonemeal","ink sac + 2 bone meal","lapis lazuli + cactus green","rose red + lapis lazuli","lapis lazuli","cocoa plant on jungle trees","cactus (furnace)","rose (flower)","squid"}
  10.  
  11. function clear()
  12.  term.clear()
  13.  term.setCursorPos(1,1)
  14. end
  15.  
  16. function clearLine(y)
  17.  term.setCursorPos(1,y)
  18.  term.clearLine()
  19. end
  20.  
  21. function printHeader(text,y)
  22.  centered(text,y)
  23.  centered(string.rep("-", w), y+1)
  24. end
  25.  
  26. function centered(text,y,c)
  27.  c = c or colors.white
  28.  term.setCursorPos(math.ceil(w/2)-math.ceil(#tostring(text)/2)+1,y)
  29.  if fancy then
  30.   if c == colors.black then
  31.    term.setBackgroundColor(colors.white)
  32.   end
  33.   term.setTextColor(c)
  34.  end
  35.  term.write(tostring(text))
  36.  if fancy then
  37.   term.setBackgroundColor(colors.black)
  38.  end
  39. end
  40.  
  41. function left(text,x,y,c)
  42.  c = c or colors.white
  43.  term.setCursorPos(x,y)
  44.  if fancy then
  45.   if c == colors.black then
  46.    term.setBackgroundColor(colors.white)
  47.   end
  48.   term.setTextColor(c)
  49.  end
  50.  term.write(text)
  51.  if fancy then
  52.   term.setBackgroundColor(colors.black)
  53.  end
  54. end
  55.  
  56. function drop(slot)
  57.  slot = slot or 0
  58.  for i=1,16 do
  59.   if turtle.getItemCount(i) > 0 and not i == slot then
  60.    turtle.select(i)
  61.    turtle.drop()
  62.   end
  63.  end
  64. end
  65.  
  66.  
  67.  
  68.  
  69. function mainMenu()
  70.  while true do
  71.   clear()
  72.   printHeader("FIREWORKS CRAFTING HELPER",1)
  73.   centered("Navigate with your keyboard keys", 4)
  74.   left("S - Create Firework Star", 7, 7)
  75.   left("R - Create Rocket", 7, 9)
  76.   left("Q - Exit", 7, 11)
  77.   term.setCursorPos(w-13,h)
  78.   term.write("by UNOBTANIUM")
  79.   local event = {os.pullEvent("char")}
  80.   if event[2] == "s" then
  81.    createStar()
  82.   elseif event[2] == "r" then
  83.    drop()
  84.    createRocket()
  85.   elseif event[2] == "q" then
  86.    clear()
  87.    term.write(os.version())
  88.    term.setCursorPos(1,2)
  89.    return
  90.   end
  91.  end
  92. end
  93.  
  94. function placeInv(var)
  95.  if var <= 3 then slot = var
  96.  elseif var == 4 then slot = 5
  97.  elseif var == 5 then slot = 6
  98.  elseif var == 6 then slot = 7
  99.  elseif var == 7 then slot = 9
  100.  elseif var == 8 then slot = 10
  101.  elseif var == 9 then slot = 11
  102.  end
  103.  turtle.select(slot)
  104.  while true do
  105.   sleep(0.1)
  106.   if turtle.getItemCount(slot) > 0 then
  107.    break
  108.   end
  109.  end
  110. end
  111.  
  112. function info()
  113.  centered("First line says which item you have",3)
  114.  centered("to place into the selected slot.",4)
  115.  centered("The second line explains, where",5)
  116.  centered("you get the item from.",6)
  117. end
  118.  
  119. function countArray(a)
  120.  local amount = 0
  121.  for k,v in pairs(a) do
  122.   amount = amount + 1
  123.  end
  124.  return amount
  125. end
  126.  
  127. function createStar()
  128.  local slot = 3
  129.  clear()
  130.  printHeader("CREATING FIREWORK STAR",1)
  131.  printHeader("SELECT SHAPE",3)
  132.  left("W - Small Ball", 7, 7)
  133.  left("A - Large Ball", 7, 8)
  134.  left("S - Star-shaped", 7, 9)
  135.  left("D - Burst", 7, 10)
  136.  left("C - Creeper Shaped", 7, 11)
  137.  local shapeName = "Shape: Small Ball"
  138.  local shape = 0
  139.  while true do
  140.   local event = {os.pullEvent("char")}
  141.   if event[2] == "w" then
  142.    slot = slot - 1
  143.    break
  144.   elseif event[2] == "a" then
  145.    shapeName = "Shape: Large Ball"
  146.    shape = 1
  147.    break
  148.   elseif event[2] == "s" then
  149.    shapeName = "Shape: Star"
  150.    shape = 2
  151.    break
  152.   elseif event[2] == "d" then
  153.    shapeName = "Shape: Burst"
  154.    shape = 3
  155.    break
  156.   elseif event[2] == "c" then
  157.    shapeName = "Shape: Creeper Face"
  158.    shape = 4
  159.    break
  160.   end
  161.  end
  162.  
  163.  clear()
  164.  printHeader("CREATING FIREWORK STAR",1)
  165.  printHeader("SELECT EFFECT (optional)",3)
  166.  left("W - No effect", 10, 7)
  167.  left("A - Trail", 10, 9)
  168.  left("S - Twinkle", 10, 11)
  169.  local effect = 0
  170.  local effectName = "No Effect"
  171.  while true do
  172.   local event = {os.pullEvent("char")}
  173.   if event[2] == "w" then
  174.    slot = slot - 1
  175.    break
  176.   elseif event[2] == "a" then
  177.    effectName = "Effect: Trail"
  178.    effect = 1
  179.    break
  180.   elseif event[2] == "s" then
  181.    effectName = "Effect: Twinkle"
  182.    effect = 2
  183.    break
  184.   end
  185.  end
  186.  
  187.  clear()
  188.  local number = 1
  189.  local counter = 1
  190.  local selectedColors = {}
  191.  printHeader("CREATING FIREWORK STAR",1)
  192.  left("Q - Back to the main menu", 10, 13)
  193.  while true do
  194.   clearLine(2)
  195.   if counter+slot < 9 then
  196.    printHeader("SELECT " .. counter .. ". COLOR",2)
  197.   else
  198.    printHeader("REACHED MAXIMUM COLOR AMOUNT",2)
  199.   end
  200.   centered("<(A)                         (D)>",5)
  201.   centered(color[number], 5, colorName[number])
  202.   if slot+counter <= 9 then
  203.    left("W - Add color", 10, 10)
  204.   else
  205.    clearLine(10)
  206.   end
  207.   local x,y = 9,7
  208.   local str = {}
  209.   local length = {}
  210.   local colori = {}
  211.   clearLine(7) clearLine(8) clearLine(9)
  212.   for k,v in pairs(selectedColors) do
  213.    table.insert(str,k,color[v]..", ")
  214.    table.insert(length,k,#str[k])
  215.    table.insert(colori,k,colorName[v])
  216.   end
  217.   left("Colors:",1,7)
  218.   for i=1, countArray(selectedColors) do
  219.    if x+length[i] > 39 then y = y + 1 x = 1 end
  220.    term.setCursorPos(x,y)
  221.    left(str[i],x,y,colori[i])
  222.    x = x + length[i]
  223.   end
  224.   if counter >= 2 then
  225.    left("S - No more color", 10, 11)
  226.    left("R - Delete last color",10,12)
  227.   else
  228.    clearLine(11)
  229.   end
  230.   local event = {os.pullEvent("char")}
  231.   if event[2] == "w" and slot+counter <= 9 then
  232.    table.insert(selectedColors, countArray(selectedColors)+1, number)
  233.    counter = counter + 1
  234.   elseif event[2] == "s" and counter >= 2 then
  235.    break
  236.   elseif event[2] == "r" and counter >= 2 then
  237.    table.remove(selectedColors)
  238.    counter = counter - 1
  239.   elseif event[2] == "q" then
  240.    return
  241.   elseif event[2] == "d" then
  242.    number = number + 1
  243.   elseif event[2] == "a" then
  244.    number = number - 1
  245.   end
  246.   if number <= 0 then
  247.    number = 16
  248.   elseif number >= 17 then
  249.    number = 1
  250.   end
  251.  end
  252.  
  253.  clear()
  254.  printHeader("CREATING FIREWORK STAR",1)
  255.  printHeader("SELECT FADE COLOR (optional)",3)
  256.  left("W - Select", 10, 11)
  257.  left("S - No fade color!!!", 10 ,12)
  258.  local fadeColor = 1
  259.  while true do
  260.   centered("<(A)                         (D)>",8)
  261.   centered(color[fadeColor], 8,colorName[fadeColor])
  262.   local event = {os.pullEvent("char")}
  263.   if event[2] == "w" then
  264.    break
  265.   elseif event[2] == "s" then
  266.    fadeColor = 0
  267.    break
  268.   elseif event[2] == "d" then
  269.    fadeColor = fadeColor + 1
  270.   elseif event[2] == "a" then
  271.    fadeColor = fadeColor - 1
  272.   end
  273.   if fadeColor <= 0 then
  274.    fadeColor = 16
  275.   elseif fadeColor >= 17 then
  276.    fadeColor = 1
  277.   end
  278.  end
  279.  
  280.  drop()
  281.  while true do
  282.   clear()
  283.   printHeader("CREATING FIREWORK STAR",1)
  284.   printHeader("FINAL OVERVIEW",2)
  285.   local str = {}
  286.   local length = {}
  287.   local colori = {}
  288.   local x,y = 14,5
  289.   for k,v in pairs(selectedColors) do
  290.    table.insert(str,k,color[v]..", ")
  291.    table.insert(length,k,#str[k])
  292.    table.insert(colori,k,colorName[v])
  293.   end
  294.   left("Colors: ",6,5)
  295.   for i=1, countArray(selectedColors) do
  296.    if x+length[i] > 39 then y = y + 1 x = 1 end
  297.    term.setCursorPos(x,y)
  298.    left(str[i],x,y,colori[i])
  299.    x = x + length[i]
  300.    if y >= 8 then term.setCursorPos(35,y-1) term.write(" ect.") break end
  301.   end
  302.   if fadeColor == 0 then
  303.    left("No Fade Color",6,y+1)
  304.   else
  305.    left("Fade Color:",6,y+1)
  306.    left(color[fadeColor],18,y+1,colorName[fadeColor])
  307.   end
  308.   left(shapeName,6,y+2)
  309.   left(effectName,6,y+3)
  310.  
  311.   left("W - Craft", 10, y+4)
  312.   left("S - Back To The Main Menu", 10 , y+5)
  313.   while true do
  314.    local event = {os.pullEvent("char")}
  315.    if event[2] == "w" then
  316.     break
  317.    elseif event[2] == "s" then
  318.     return
  319.    end
  320.   end
  321.   clear()
  322.   printHeader("CREATING FIREWORK STAR",1)
  323.   info()
  324.   centered("Gunpowder",8)
  325.   centered("Creeper (Mob)",9)
  326.   placeInv(1)
  327.   clearLine(8) clearLine(9)
  328.   for k,v in pairs(selectedColors) do
  329.    centered(dye[v],8)
  330.    centered(ingredient[v],9)
  331.    placeInv(k+1)
  332.    clearLine(8) clearLine(9)
  333.   end
  334.   if shape > 0 then
  335.    if shape == 1 then
  336.     centered("Fire Charge",8)
  337.     centered("Blaze Powder + Coal + Gun Powder",9)
  338.    elseif shape == 2 then
  339.     centered("Gold Nugget",8)
  340.     centered("Gold Ingot",9)
  341.    elseif shape == 3 then
  342.     centered("Feather",8)
  343.     centered("Chicken",9)
  344.    elseif shape == 4 then
  345.     centered("Any Head",8)
  346.     centered("From Mobs (Wither Skelet)",9)
  347.    end
  348.    placeInv(countArray(selectedColors)+2)
  349.    clearLine(8) clearLine(9)
  350.   end
  351.   if effect > 0  then
  352.    if effect == 1 then
  353.     centered("Diamond",8)
  354.     centered("Underground/Mining",9)
  355.    elseif effect == 2 then
  356.     centered("Glowstone Dust",8)
  357.     centered("Glowstone from the Nether",9)
  358.    end
  359.    placeInv(countArray(selectedColors)+3)
  360.    clearLine(8) clearLine(9)
  361.   end
  362.   turtle.select(16)
  363.   clear()
  364.   printHeader("CREATING FIREWORK STAR",1)
  365.   centered("Hit any key to create the star(s)!",8)
  366.   os.pullEvent("char")
  367.   if not turtle.craft() then
  368.    clear()
  369.    centered("Something went wrong!",5)
  370.    sleep(1.6)
  371.    return
  372.   end
  373.   if fadeColor > 0 then
  374.    clear()
  375.    drop(16)
  376.    turtle.select(16)
  377.    turtle.transferTo(1)
  378.    printHeader("CREATING FIREWORK STAR",1)
  379.    info()
  380.    centered(dye[fadeColor],8)
  381.    centered(ingredient[fadeColor],9)
  382.    placeInv(2)
  383.    clearLine(8) clearLine(9)
  384.    turtle.select(16)
  385.    clear()
  386.    printHeader("CREATING FIREWORK STAR",1)
  387.    centered("Hit any key to create the star(s)!",8)
  388.    os.pullEvent("char")
  389.    turtle.craft()
  390.   end
  391.   clear()
  392.   centered("FINISHED",5)
  393.   centered("Take out your firework star(s)!",6)
  394.   left("W - Create Again",10,7)
  395.   left("S - Back To The Main Menu",10,8)
  396.   sleep(0.5)
  397.   while true do
  398.    local event = {os.pullEvent("char")}
  399.    if event[2] == "w" then
  400.     break
  401.    elseif event[2] == "s" then
  402.     return
  403.    end
  404.   end
  405.  end
  406. end
  407.  
  408. function increaseSlot(s)
  409.  s = s + 1
  410.  if s == 4 or s == 8 then
  411.   s = s + 1
  412.  end
  413.  return s
  414. end
  415.  
  416. function createRocket()
  417.  clear()
  418.  printHeader("CREATING ROCKET",1)
  419.  info()
  420.  centered("Paper",8)
  421.  centered("Sugar Cane",9)
  422.  placeInv(1)
  423.  clearLine(8) clearLine(9) clearLine(3) clearLine(4) clearLine(5) clearLine(6)
  424.  centered("Flight Height:",5)
  425.  centered("A - ~16 blocks",6)
  426.  centered("S - ~28 blocks",7)
  427.  centered("D - ~48 blocks",8)
  428.  local slots = 1
  429.  while true do
  430.   local event = {os.pullEvent("char")}
  431.   if event[2] == "a" then
  432.    slots = 2
  433.    break
  434.   elseif event[2] == "s" then
  435.    slots = 3
  436.    break
  437.   elseif event[2] == "d" then
  438.    slots = 4
  439.    break
  440.   end
  441.  end
  442.  clearLine(5) clearLine(6) clearLine(7) clearLine(8)
  443.  info()
  444.  centered("Gunpowder",8)
  445.  centered("Creeper (Mob)",9)
  446.  for i=2,slots do
  447.   if i == 4 then i = 5 end
  448.   placeInv(i)
  449.  end
  450.  clearLine(8) clearLine(9) clearLine(3) clearLine(4) clearLine(5) clearLine(6)
  451.  centered("Place your firework stars",6)
  452.  centered("into the selected slot.",7)
  453.  centered("Hold any key if you dont want",8)
  454.  centered("to add any more firework stars.",9)
  455.  local slot = slots + 1
  456.  if slot == 4 then slot = 5 end
  457.   local delay = os.startTimer(0.11)
  458.  while true do
  459.   turtle.select(slot)
  460.   local event = {os.pullEvent()}
  461.   if event[1] == "timer" then
  462.    if turtle.getItemCount(slot) > 0 then
  463.     slot = increaseSlot(slot)
  464.     if slot == 12 then break end
  465.    end
  466.    delay = os.startTimer(0.11)
  467.   elseif event[1] == "key" then
  468.    break
  469.   end
  470.  end
  471.  turtle.select(16)
  472.  clear()
  473.  if not turtle.craft() then
  474.   centered("Something went wrong!",5)
  475.   sleep(1.7)
  476.   return
  477.  end
  478.  centered("FINISHED",5)
  479.  centered("Take out your rocket(s)!",6)
  480.  left("W - Create Again",10, 7)
  481.  left("S - Back To The Main Menu",10,8)
  482.  sleep(0.5)
  483.  while true do
  484.   local event = {os.pullEvent("char")}
  485.   if event[2] == "w" then
  486.    createRocket()
  487.    return
  488.   elseif event[2] == "s" then
  489.    return
  490.   end
  491.  end
  492. end
  493.  
  494.  
  495.  
  496. -- ERROR CHECK
  497.  
  498. clear()
  499. if not turtle then
  500.  print(os.version())
  501.  print("You have to use a crafty turtle!")
  502.  return
  503. end
  504. local ok, val = pcall(turtle.craft)
  505. if not ok then
  506.  print(os.version())
  507.  print("You have to use a crafty turtle!")
  508.  return
  509. end
  510.  
  511. -- RUN
  512.  
  513. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement