Advertisement
Guest User

CC TreeMgr

a guest
Aug 17th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. --
  2. -- TreeMgr
  3. -- Utility for Tree growing/remove
  4. -- ComputerCraft 1.78
  5. -- Require Command Computer
  6. --
  7. -- author: SukaiPoppuGo
  8. -- licence: CC BY-NC-SA 4.0
  9. -- https://creativecommons.org/licenses/by-nc-sa/4.0/
  10. --
  11.  
  12. if not commands then
  13.     error("TreeMgr require a command computer",-1)
  14.     return
  15. end
  16.  
  17. local delay = .2
  18.  
  19. x,y,z = commands.getBlockPosition()
  20. x1,z1 = x-(x%16), z-(z%16)
  21. x2,z2 = x1+15, z1+15
  22. y1,y2 = math.max(1,y-1), math.min(255,y+90)
  23.  
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. print("Chunk coords:")
  27. print(string.format([[X: %d / %d
  28. Y: %d / %d
  29. Z: %d / %d
  30.   Press any key]],x1,x2,y1,y2,z1,z2))
  31. os.pullEvent("key")
  32. local w,h = term.getSize()
  33.  
  34. local function printLine(str,line)
  35.     term.setCursorPos(1,line)
  36.     term.clearLine()
  37.     term.write(str)
  38. end
  39.  
  40. local function chunk()
  41.     local data = commands.getBlockInfo(x1,y,z1)
  42.     local blockName = data.name=="minecraft:redstone_block" and "minecraft:air" or "minecraft:redstone_block"
  43.     commands.setblock(x1,y,z1,blockName)
  44.     commands.setblock(x1,y,z2,blockName)
  45.     commands.setblock(x2,y,z2,blockName)
  46.     commands.setblock(x2,y,z1,blockName)
  47. end
  48.  
  49. local function give()
  50.     local dmg
  51.     for dmg=0,5 do
  52.         commands.give("@p","minecraft:sapling",1,dmg)
  53.         sleep(delay)
  54.     end
  55.     commands.give("@p","minecraft:dye",1,15) --bone meal
  56. end
  57.  
  58. local function clearLeaves()
  59.     commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:leaves")
  60.     sleep(delay)
  61.     commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:leaves2")
  62.     sleep(delay)
  63. end
  64. local function clearLogs()
  65.     commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:log")
  66.     sleep(delay)
  67.     commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:log2")
  68.     sleep(delay)
  69. end
  70.  
  71. local menu = {
  72.     "chunk",
  73.     "give saplings/bonemeal",
  74.     "clear trees",
  75.     "clear leaves",
  76.     "clear logs",
  77. }
  78.  
  79. local onclick = {
  80.     function() chunk() end,
  81.     function() give() end,
  82.     function() clearLeaves() clearLogs() end,
  83.     function() clearLeaves() end,
  84.     function() clearLogs() end,
  85. }
  86.  
  87. local function printMenu(sel,prefix)
  88.     prefix = prefix or ">"
  89.     local i,m
  90.     for i,m in ipairs(menu) do
  91.         local p = (sel==i) and prefix or "-"
  92.         printLine(
  93.             string.format("%s %s %s",p,m,
  94.                 (sel~=i) and ""
  95.                 or string.rep(
  96.                     string.char(127),
  97.                     math.max(0,w-string.len(p..m)+2)
  98.                 )
  99.             )
  100.         ,i+1)
  101.     end
  102. end
  103.  
  104. term.clear()
  105. printLine(string.format("#%d %s - press[T]",os.getComputerID(), os.getComputerLabel()),1)
  106. local selection=0
  107. while true do
  108.     printMenu(0)
  109.     local e,p,_x,_y = os.pullEvent()
  110.     if e=="key" and p==keys.t then
  111.         local e,p = os.pullEvent("key_up")
  112.         if p==keys.t then break end
  113.     elseif e=="mouse_click" and p==1 then
  114.         selection = _y-1
  115.         printMenu(selection)
  116.         if type(onclick[selection])=="function" then
  117.             onclick[selection]()
  118.         end
  119.         sleep(1)
  120.     end
  121.     sleep(delay)
  122. end
  123. printLine("Terminated\n",#menu+2)
  124. sleep(.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement