4ndertheker

[CC XP Melee Turtle] XP/Cow Farm

Dec 21st, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. local autoCollect = true
  2. local active = true
  3. local noBooks = false
  4.  
  5. local function drop()
  6.  if turtle.getItemCount(1) >= 60 then
  7.   turtle.select(1)
  8.   turtle.dropUp(turtle.getItemCount(1)-1)
  9.  elseif turtle.getItemCount(2) >= 60 then
  10.   turtle.select(2)
  11.   turtle.dropUp(turtle.getItemCount(2)-1)
  12.   turtle.select(1)
  13.  elseif turtle.getItemCount(15)>0 then
  14.   for i = 3, 15 do
  15.    turtle.select(i)
  16.    turtle.dropUp()
  17.   end
  18.   turtle.select(1)
  19.  end
  20. end
  21.  
  22. local function getBook()
  23.  turtle.select(16)
  24.  if not turtle.suckDown() then
  25.   turtle.dropUp()
  26.   if not turtle.suckDown() then
  27.    noBooks = true
  28.   else
  29.    noBooks = false
  30.   end
  31.  else
  32.   turtle.dropDown(turtle.getItemCount(16)-1)
  33.  end
  34.  turtle.select(1)
  35. end
  36.  
  37. local function init()
  38.  drop()
  39.  xp = peripheral.wrap("right")
  40.  xp.setAutoCollect(autoCollect)
  41.  getBook()
  42. end
  43.  
  44. local function enchant()
  45.  if xp.getLevels()>=30 and not noBooks then
  46.   turtle.select(16)
  47.   xp.enchant(30)
  48.   turtle.dropUp()
  49.   getBook()
  50.  elseif noBooks then
  51.   getBook()
  52.  end
  53. end
  54.  
  55. local function output()
  56.  term.clear()
  57.  term.setCursorPos(1,1)
  58.  print("Momentaner Level: ", xp.getLevels())
  59.  if autoCollect then
  60.   print("")
  61.   print("XP-Autocollecting ist aktiviert,")
  62.   print("zum Deaktivieren [A] druecken.")
  63.  else
  64.   print("")
  65.   print("XP-Autocollecting ist deaktiviert,")
  66.   print("zum Aktivieren [A] druecken.")
  67.  end
  68.  if active then
  69.   print("")
  70.   print("Wartungsmodus ist inaktiv,")
  71.   print("zum Aktivieren [W] druecken.")
  72.  else
  73.   print("")
  74.   print("Wartungsmodus ist aktiv,")
  75.   print("zum Deaktivieren [W] druecken.")
  76.  end
  77.  if noBooks then
  78.   print("")
  79.   print("Keine Buecher mehr")
  80.  end
  81.  
  82. end
  83.  
  84. local function wait()
  85.  while true do
  86.   if active then
  87.    turtle.attack()
  88.    drop()
  89.    enchant()
  90.   end
  91.   output()
  92.   sleep(.2)
  93.  end
  94. end
  95.  
  96. local function keypress()
  97.  while true do
  98.   local event, key = os.pullEvent("key")
  99.   if key == 30 then
  100.    autoCollect = not autoCollect
  101.    xp.setAutoCollect(autoCollect)
  102.    output()
  103.   elseif key == 17 then
  104.    active = not active
  105.    output()
  106.   end
  107.  end
  108. end
  109.  
  110. init()
  111. parallel.waitForAny(wait, keypress)
Advertisement
Add Comment
Please, Sign In to add comment