Advertisement
zachdyer

ComputerCraft Block Area Calculator

Dec 9th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --Find the area and perimeter
  2. tArgs = {...}
  3. local mode = tArgs[1]
  4. local length = tArgs[2]
  5. local width = tArgs[3]
  6. local height = tArgs[4]
  7.  
  8. local area = 0
  9. local stack64 = 0
  10. local stack16 = 0
  11.  
  12. function calcArea3d(l,w,h)
  13.   area = l * w * h
  14.   stack64 = math.ceil(area / 64)
  15.   stack16 = math.ceil(area / 16)
  16. end
  17. function calcArea2d(l,w)
  18.     area = l * w
  19.     stack64 = math.ceil(area / 64)
  20.     stack16 = math.ceil(area / 16)
  21. end
  22. function report()
  23.   local biggest = 0
  24.   if #tostring(length) > biggest then biggest = #tostring(length) end
  25.   if #tostring(width) > biggest then biggest = #tostring(width) end
  26.   if #tostring(height) > biggest then biggest = #tostring(height) end
  27.   print("================================")
  28.   print("  Length: " .. string.rep(" ", biggest-#tostring(length)) .. length)
  29.   print("  Width:  " .. string.rep(" ", biggest-#tostring(width)) .. width)
  30.   print("  Height: " .. string.rep(" ", biggest-#tostring(height)) .. height)
  31.   print(" ------------------------------")
  32.  
  33.   biggest = 0
  34.   local tmpArea = area .. " Blocks"
  35.   local tmpStack64 = "~" .. stack64 .. " (x64)"
  36.   local tmpStack16 = "~" .. stack16 .. " (x16)"
  37.  
  38.   if #tmpArea > biggest then biggest = #tmpArea end
  39.   if #tmpStack64 > biggest then biggest = #tmpStack64 end
  40.   if #tmpStack16 > biggest then biggest = #tmpStack16 end  
  41.  
  42.   print("  Blocks Required: " .. string.rep(" ",biggest - #tmpArea ) .. tmpArea )
  43.   print("  Stacks Required: " .. string.rep(" ",biggest - #tmpStack64) .. tmpStack64 )
  44.   print("  Stacks Required: " .. string.rep(" ",biggest - #tmpStack16) .. tmpStack16 )
  45.   print("================================")
  46.   print("By zachdyer and da404lewzer.")
  47. end
  48. function help()
  49.  
  50. end
  51.  
  52. if mode == nil then
  53.   print("help")
  54. elseif mode == "area3d" then
  55.     if length == nil then
  56.        help()
  57.     elseif width == nil then
  58.       width = length
  59.       height = length
  60.       calcArea3d(length,width,height)
  61.       report()
  62.     elseif height == nil then
  63.       help()
  64.     else
  65.        calcArea3d(length,width,height)
  66.        report()
  67.     end
  68. elseif mode == "area2d" then
  69.   if length == nil then
  70.     help()
  71.   elseif width == nil then
  72.     width = length
  73.     calcArea2d(length, width)
  74.     report()
  75.   else
  76.     calcArea2d(length, width)
  77.     report()
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement