Advertisement
authorblues

Untitled

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