Advertisement
nccn12

lol

Feb 22nd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. -- @param attacks between inventory dump
  2. local t = 256
  3.  
  4. -- @param level to do enchantments
  5. local enchantLevel = 30
  6.  
  7. -- @param monitor direction (can be nil if no monitor)
  8. local monitorSide = back
  9.  
  10. -- @param experience per kill (use 0 if you don't know)
  11. -- this will be used to estimate the number of kills
  12. local XPperKill = 0
  13.  
  14. -- wrap all peripherals
  15. local xp = peripheral.wrap("right")
  16. local mtr = term
  17.  
  18. -- if the monitor side was set, wrap it
  19. if monitorSide ~= nil then
  20. mtr = peripheral.wrap(monitorSide)
  21. if mtr == nil then mtr = term end
  22. end
  23.  
  24. local color = mtr.isColor()
  25.  
  26. local name = "Tim the Enchanter v1.0"
  27. local enchants = 0
  28. local totalXP = xp.get()
  29.  
  30. xp.setAutoCollect(false)
  31. mtr.setCursorBlink(false)
  32.  
  33. local function display()
  34. local level = xp.getLevels()
  35. local W,H = mtr.getSize()
  36.  
  37. local row = 4
  38.  
  39. if color then
  40. mtr.setBackgroundColor(colors.black)
  41. end
  42. mtr.clear()
  43.  
  44. -- write program name and decoration
  45. mtr.setCursorPos((W-#name)/2, 1)
  46. mtr.write(name)
  47.  
  48. mtr.setCursorPos(1,2)
  49. mtr.write(string.rep("-", W))
  50.  
  51. -- get the length of the progress bar
  52. local barWidth = W-7
  53. local barFill = (level * barWidth) / enchantLevel
  54. if barFill > barWidth then barFill = barWidth end
  55.  
  56. -- write the level progress bar
  57. mtr.setCursorPos(2, row)
  58. mtr.write("L")
  59.  
  60. mtr.setCursorPos(W-2, row)
  61. mtr.write(string.format("%02d", level))
  62.  
  63. if color then
  64. mtr.setCursorPos(4, row)
  65. mtr.setBackgroundColor(colors.lightGray)
  66. mtr.write(string.rep(" ", barWidth))
  67.  
  68. mtr.setCursorPos(4, row)
  69. mtr.setBackgroundColor(colors.red)
  70. mtr.write(string.rep(" ", barFill))
  71.  
  72. -- reset background color
  73. mtr.setBackgroundColor(colors.black)
  74. else
  75. mtr.setCursorPos(4, row)
  76. mtr.write(string.rep("-", barWidth))
  77.  
  78. mtr.setCursorPos(4, row)
  79. mtr.write(string.rep("#", barFill))
  80. end
  81.  
  82. row = row + 2
  83.  
  84. -- write the enchantment info
  85. mtr.setCursorPos(2, row)
  86. mtr.write("E")
  87.  
  88. local enchantInfo = string.format("%d enchants", enchants)
  89. mtr.setCursorPos(W-(#enchantInfo), row)
  90. mtr.write(enchantInfo)
  91.  
  92. row = row + 2
  93.  
  94. if XPperKill > 0 then
  95. -- write the kill info
  96. mtr.setCursorPos(2, row)
  97. mtr.write("K")
  98.  
  99. local killInfo = string.format("~ %d kills", math.floor(totalXP / XPperKill))
  100. mtr.setCursorPos(W-(#killInfo), row)
  101. mtr.write(killInfo)
  102.  
  103. row = row + 2
  104. end
  105.  
  106. -- write the experience info
  107. mtr.setCursorPos(2, row)
  108. mtr.write("XP")
  109.  
  110. local xpInfo = string.format("%d total XP", totalXP)
  111. mtr.setCursorPos(W-(#xpInfo), row)
  112. mtr.write(xpInfo)
  113.  
  114. row = row + 2
  115. end
  116.  
  117. while true do
  118. display()
  119.  
  120. -- attack and pick up items
  121. for i=1,t do
  122. turtle.attack()
  123. turtle.suck()
  124. totalXP = totalXP + xp.collect()
  125. end
  126.  
  127. -- empty contents of turtle inventory
  128. for i=14,1,-1 do
  129. turtle.select(i)
  130. turtle.dropDown()
  131. end
  132.  
  133. -- if we have enough levels to enchant
  134. if xp.getLevels() >= enchantLevel
  135. then
  136. -- toss buffered enchant
  137. turtle.select(16)
  138. turtle.dropDown()
  139.  
  140. -- get more of whatever we are enchanting
  141. turtle.select(15)
  142. if turtle.getItemCount(15) == 0 then turtle.suckUp() end
  143. turtle.transferTo(16, 1)
  144.  
  145. -- select the enchant slot and do it
  146. turtle.select(16)
  147. xp.enchant(enchantLevel)
  148. enchants = enchants + 1
  149.  
  150. -- hold on to item to "buffer" (so we can see it)
  151. turtle.select(1)
  152. end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement