Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- TreeMgr
- -- Utility for Tree growing/remove
- -- ComputerCraft 1.78
- -- Require Command Computer
- --
- -- author: SukaiPoppuGo
- -- licence: CC BY-NC-SA 4.0
- -- https://creativecommons.org/licenses/by-nc-sa/4.0/
- --
- if not commands then
- error("TreeMgr require a command computer",-1)
- return
- end
- local delay = .2
- x,y,z = commands.getBlockPosition()
- x1,z1 = x-(x%16), z-(z%16)
- x2,z2 = x1+15, z1+15
- y1,y2 = math.max(1,y-1), math.min(255,y+90)
- term.clear()
- term.setCursorPos(1,1)
- print("Chunk coords:")
- print(string.format([[X: %d / %d
- Y: %d / %d
- Z: %d / %d
- Press any key]],x1,x2,y1,y2,z1,z2))
- os.pullEvent("key")
- local w,h = term.getSize()
- local function printLine(str,line)
- term.setCursorPos(1,line)
- term.clearLine()
- term.write(str)
- end
- local function chunk()
- local data = commands.getBlockInfo(x1,y,z1)
- local blockName = data.name=="minecraft:redstone_block" and "minecraft:air" or "minecraft:redstone_block"
- commands.setblock(x1,y,z1,blockName)
- commands.setblock(x1,y,z2,blockName)
- commands.setblock(x2,y,z2,blockName)
- commands.setblock(x2,y,z1,blockName)
- end
- local function give()
- local dmg
- for dmg=0,5 do
- commands.give("@p","minecraft:sapling",1,dmg)
- sleep(delay)
- end
- commands.give("@p","minecraft:dye",1,15) --bone meal
- end
- local function clearLeaves()
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:leaves")
- sleep(delay)
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:leaves2")
- sleep(delay)
- end
- local function clearLogs()
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:log")
- sleep(delay)
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:air",0,"replace","minecraft:log2")
- sleep(delay)
- end
- local menu = {
- "chunk",
- "give saplings/bonemeal",
- "clear trees",
- "clear leaves",
- "clear logs",
- }
- local onclick = {
- function() chunk() end,
- function() give() end,
- function() clearLeaves() clearLogs() end,
- function() clearLeaves() end,
- function() clearLogs() end,
- }
- local function printMenu(sel,prefix)
- prefix = prefix or ">"
- local i,m
- for i,m in ipairs(menu) do
- local p = (sel==i) and prefix or "-"
- printLine(
- string.format("%s %s %s",p,m,
- (sel~=i) and ""
- or string.rep(
- string.char(127),
- math.max(0,w-string.len(p..m)+2)
- )
- )
- ,i+1)
- end
- end
- term.clear()
- printLine(string.format("#%d %s - press[T]",os.getComputerID(), os.getComputerLabel()),1)
- local selection=0
- while true do
- printMenu(0)
- local e,p,_x,_y = os.pullEvent()
- if e=="key" and p==keys.t then
- local e,p = os.pullEvent("key_up")
- if p==keys.t then break end
- elseif e=="mouse_click" and p==1 then
- selection = _y-1
- printMenu(selection)
- if type(onclick[selection])=="function" then
- onclick[selection]()
- end
- sleep(1)
- end
- sleep(delay)
- end
- printLine("Terminated\n",#menu+2)
- sleep(.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement