Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- OptimineMgr
- -- Bench test for mining Turtles
- -- 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("OptimineMgr require a Command Computer",-1)
- return
- end
- local settingsFile = "/.settings"
- debugMode = true
- turtleID = false
- tw,th = term.getSize()
- local sep = string.rep(string.char(131),tw-1)
- local function setColor(fg,bg,m)
- m = m or term
- m.setTextColor(fg) m.setBackgroundColor(bg)
- end
- local com_x,com_y,com_z = commands.getBlockPosition()
- local function sound_click()
- if _HOST=="ComputerCraft 1.78 (Minecraft 1.8.9)" then
- commands.playsound("gui.button.press","@p",com_x,com_y,com_z,0.1,0.6,0)
- end
- end
- if not os.getComputerLabel() then os.setComputerLabel("OptimineMgr") end
- outputPad = string.len(string.format("#%d %s",os.getComputerID(),os.getComputerLabel()))+2
- function output(str)
- if string.len(str) < tw - outputPad then
- str = str..string.rep(" ",tw-outputPad)
- elseif string.len(str) > tw - outputPad then
- str = string.sub(str,1,tw-outputPad)
- end
- term.setCursorPos(outputPad,1)
- setColor(colors.gray, colors.black)
- term.write(str)
- end
- function header()
- term.setCursorPos(1,1)
- term.clear()
- setColor(colors.lightGray,colors.black)
- print(string.format("#%d %s",os.getComputerID(),os.getComputerLabel()))
- print(sep)
- end
- header()
- --init Turtle
- local function giveTurtle(id)
- output("Give Turtle with ID: #"..id) --#
- commands.give("@p","computercraft:CC-TurtleAdvanced",1,0,"{"
- .."fuelLevel:"..(opt.turtleFuelLevel and opt.turtleFuelLevel or "100000")..","
- ..(opt.turtleEquipLeft and "leftUpgrade:\""..opt.turtleEquipLeft.."\"," or "leftUpgrade:\"minecraft:diamond_pickaxe\",")
- ..(opt.turtleEquipRight and "rightUpgrade:\""..opt.turtleEquipRight.."\"," or "")
- .."label:\"OptiMiner\","
- .."computerID:"..id..","
- .."id:\"turtleadv\"}")
- end
- local function initTurtleID()
- output("Init new Turtle") --#
- commands.setBlock(com_x,com_y+1,com_z,"computercraft:CC-TurtleAdvanced",0,"replace")
- sleep(.3)
- local t = peripheral.wrap("top")
- sleep(.3)
- t.turnOn()
- sleep(.3)
- turtleID = t.getID()
- output("New Turtle ID: #"..turtleID) --#
- commands.setBlock(com_x,com_y+1,com_z,"minecraft:air",0,"replace")
- settings.set("OptiMiner.turtleID",turtleID)
- settings.save(settingsFile)
- return turtleID
- end
- if fs.exists(settingsFile) then
- output("Load settings: "..settingsFile) --#
- settings.load(settingsFile)
- if not turtleID then
- turtleID = settings.get("OptiMiner.turtleCustomID",settings.get("OptiMiner.turtleID"))
- end
- elseif not turtleID then
- giveTurtle(initTurtleID())
- end
- -- src: http://minecraft.gamepedia.com/Chunk_format#Mobs
- --types:
- -- Item, XPOrb
- -- Blaze,CaveSpider,Creeper,Enderman,Ghast,Guardian,LavaSlime,PigZombie,Silverfish,Skeleton,Slime,Spider,Witch,Zombie
- -- Bat,Chicken,Cow,EntityHorse,MushroomCow,Ozelot,Pig,Rabbit,Sheep,Squid,Wolf
- local function kill(chunk,...)
- local entities= {...} or {"!Player"}
- local pos = ""
- if chunk then
- pos = string.format("x=%d,y=%d,z=%d,dx=%d,dy=%d,dz=%d,",
- chunk.x-1,chunk.y-1,chunk.z-1,16,16,16)
- end
- --summon LightningBolt
- local _,_e
- for _,_e in pairs(entities) do
- output("Killing Entity: type=".._e) --#
- commands.kill("@e["..pos.."type=".._e.."]")
- sleep(.1)
- end
- end
- output("Locate target chunk") --#
- local targetChunk = {
- x = com_x+16 - (com_x%16),
- y = com_y,
- z = com_z - (com_z%16),
- }
- output("Locate ref chunk") --#
- local refChunk = {
- x = targetChunk.x,
- y = targetChunk.y - 17,
- z = targetChunk.z,
- }
- function fillChunk(chunk,blockName)
- blockName = blockName or "minecraft:stone"
- commands.fill(chunk.x,chunk.y,chunk.z,chunk.x+15,chunk.y+15,chunk.z+15,blockName)
- end
- function clearChunk(chunk)
- output("Clear chunk") --#
- kill(chunk,"!Player","Item")
- fillChunk(chunk,"minecraft:air")
- end
- function markChunk(chunk,blockName)
- output("Mark chunk corners with: "..blockName) --#
- commands.setblock(chunk.x, chunk.y, chunk.z, blockName,0,"replace")
- commands.setblock(chunk.x, chunk.y+15,chunk.z, blockName,0,"replace")
- commands.setblock(chunk.x, chunk.y, chunk.z+15,blockName,0,"replace")
- commands.setblock(chunk.x, chunk.y+15,chunk.z+15,blockName,0,"replace")
- commands.setblock(chunk.x+15,chunk.y, chunk.z, blockName,0,"replace")
- commands.setblock(chunk.x+15,chunk.y+15,chunk.z, blockName,0,"replace")
- commands.setblock(chunk.x+15,chunk.y, chunk.z+15,blockName,0,"replace")
- commands.setblock(chunk.x+15,chunk.y+15,chunk.z+15,blockName,0,"replace")
- end
- function ore(x,y,z,base)
- local seed = math.random(16)
- local oreType
- if seed > 14 and y-base < 6 then oreType = "minecraft:diamond_ore"
- elseif seed > 12 and y-base < 6 then oreType = "minecraft:lapis_ore"
- elseif seed > 10 and y-base < 8 then oreType = "minecraft:redstone_ore"
- elseif seed > 10 and y-base < 10 then oreType = "minecraft:gold_ore"
- elseif seed > 8 and y-base < 12 then oreType = "minecraft:iron_ore"
- else oreType = "minecraft:coal_ore" end
- commands.fill(x,y,z,x+1,y+1,z+1,oreType,0,"replace")
- local _x,_y,_z
- for _x=0,1 do for _y=0,1 do for _z=0,1 do
- local chance = (seed+_x+_y+_z)%3
- if chance==0 then
- commands.setblock(x+_x,y+_y,z+_z,"minecraft:stone",0,"replace")
- end
- end end end
- end
- function ore_populate(chunk)
- output("Populate ores") --#
- local _x,_y,_z
- for _x=1,13 do for _y=0,12 do for _z=1,13 do
- output("Populate ores"..string.rep(".",_x%6)) --#
- if math.random(100)==1 then
- ore(chunk.x+_x,chunk.y+_y,chunk.z+_z,chunk.y)
- sleep(.1)
- end
- end end end
- commands.setblock(
- chunk.x+1+math.random(13),
- chunk.y+1+math.random(7),
- chunk.z+1+math.random(13),
- "minecraft:emerald_ore",0,"replace")
- end
- stoneDataValues = {0,1,3,5}
- function bubble(x,y,z, blockType, dataValue)
- local seed = math.random(16)
- local v = seed%3
- dataValue = dataValue or 0
- if not blockType then
- blockType = "minecraft:stone"
- if seed < 4 then blockType = "minecraft:gravel"
- elseif seed < 12 then blockType = "minecraft:dirt"
- else dataValue = stoneDataValues[(seed%4)+1]
- end
- end
- commands.fill(x+1,y,z+1,x+1+v,y+1+(v*2),z+1+v,blockType,dataValue,"replace")
- commands.fill(x,y+1,z+1,x+1+(v*2),y+1+v,z+1+v,blockType,dataValue,"replace")
- commands.fill(x+1,y+1,z,x+1+v,y+1+v,z+1+(v*2),blockType,dataValue,"replace")
- end
- function dirt_populate(chunk)
- output("Populate dirt") --#
- local skip,_x,_y,_z=false
- for _x=1,10 do for _y=0,9 do for _z=1,10 do
- output("Populate dirt"..string.rep(".",_x%5)) --#
- if not skip and math.random(60)==1 then
- bubble(chunk.x+_x,chunk.y+_y,chunk.z+_z)
- sleep(.1)
- skip = true
- end
- skip = false
- end end end
- end
- function hole_populate(chunk)
- output("Populate holes") --#
- local nb,i = math.random(2,8)
- for i=1,nb do
- local _x,_y,_z= math.random(2,9), math.random(1,9), math.random(2,9)
- bubble(chunk.x+_x,chunk.y+_y,chunk.z+_z,"minecraft:air")
- sleep(.1)
- end
- end
- function lava_lake(x,y,z,chunk)
- output("Generate lava lake") --#
- local space_x,space_z = (chunk.x+15-x), (chunk.z+15-z)
- local heigth = math.random(2,4)
- local deep = math.random(math.max(1,heigth-1))
- local h=1
- local y1 = y+h-1
- local x1,z1 = x+math.random(0,space_x-2), z+math.random(0,space_z-2)
- local x2,z2 = x+math.random(space_x-1), z+math.random(space_z-1)
- commands.fill(x1,y1,z1,x2,y1,z2,"minecraft:lava",0,"replace")
- for h=2,heigth do
- y1 = y+h-1
- local filler = h>deep and "air" or "lava"
- x1 = math.max(x,math.min(x+space_x-2, math.random(-2,2)+x1 ))
- z1 = math.max(z,math.min(z+space_z-2, math.random(-2,2)+z1 ))
- x2 = math.max(x,math.min(x+space_x-2, math.random(-2,2)+x2 ))
- z2 = math.max(z,math.min(z+space_z-2, math.random(-2,2)+z2 ))
- commands.fill(x1,y1,z1,x2,y1,z2,"minecraft:"..filler,0,"replace")
- end
- print("---")
- end
- function lava_populate(chunk)
- local nb,i = math.random(1,4)
- for i=1,nb do
- output("Populate lava") --#
- local _x,_y,_z= math.random(3,13), math.random(1,9), math.random(3,13)
- if _x<9 and _y<8 and _z<9 then lava_lake(chunk.x+_x,chunk.y+_y,chunk.z+_z,chunk)
- else liquid_source("lava",chunk,chunk.x+_x,chunk.y+_y,chunk.z+_z)
- end
- sleep(.1)
- end
- end
- function water_lake(chunk,x,y,z)
- output("Generate water lake") --#
- local space_x,space_z = math.min(8,chunk.x+15-x), math.min(8,chunk.z+15-z)
- local heigth = math.random(2,4)
- local deep = math.random(math.max(1,heigth-2))
- local h=1
- local y1,y2 = y+h-1, y+deep-1
- local x1,z1 = x+math.random(0,space_x-2), z+math.random(0,space_z-2)
- local x2,z2 = x+math.random(space_x-1), z+math.random(space_z-1)
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:water",0,"replace")
- for h=2,heigth do
- y1 = y+h-1
- y2 = h>deep and y1 or y+deep-1
- local filler = h>deep and "air" or "water"
- x1 = math.max(x,math.min(x+space_x-2, math.random(-1,1)+x1 ))
- z1 = math.max(z,math.min(z+space_z-2, math.random(-1,1)+z1 ))
- x2 = math.max(x,math.min(x+space_x-2, math.random(-1,1)+x2 ))
- z2 = math.max(z,math.min(z+space_z-2, math.random(-1,1)+z2 ))
- commands.fill(x1,y1,z1,x2,y2,z2,"minecraft:"..filler,0,"replace")
- end
- end
- function liquid_source(liquid,chunk,x,y,z)
- output("Generate source of "..liquid) --#
- local deep= y>chunk.y+2 and math.random(0,math.min(6,y-(chunk.y+1))) or 0
- local side = math.random(-1,1)
- local _x,_z = x,z
- if deep>0 and side~=0 then
- if math.random(2)==1 then _x=x+side
- else _z=z+side end
- commands.fill(_x,y,_z,_x,y-deep,_z,"minecraft:air",0,"replace")
- end
- commands.setblock(x,y,z,"minecraft:"..liquid,0,"replace")
- if deep>0 and side~=0 then
- commands.setblock(_x,y,_z,"minecraft:gravel",0,"replace")
- sleep(.1)
- kill(chunk,"FallingSand")
- end
- end
- function water_populate(chunk)
- local nb,i = math.random(1,4)
- for i=1,nb do
- output("Populate water") --#
- local _x,_y,_z= math.random(3,13), math.random(3,13), math.random(3,13)
- if _x<9 and _y<9 and _z<9 and math.random(0,1)==1 then water_lake(chunk,chunk.x+_x,chunk.y+_y,chunk.z+_z)
- else liquid_source("water",chunk,chunk.x+_x,chunk.y+_y,chunk.z+_z)
- end
- sleep(.1)
- end
- end
- --src: http://minecraft.gamepedia.com/Dungeon
- local function dungeon_loot()
- output("Generate dungeon loot") --#
- local loot = {}
- --Stack #1
- local slot,size=1,math.random(1,3)
- for slot=1,size do
- local chance = math.random(128)
- if chance > 107 then table.insert(loot,"id:\"minecraft:name_tag\",Count:1b")
- elseif chance > 87 then table.insert(loot,"id:\"minecraft:saddle\",Count:1b")
- elseif chance > 72 then table.insert(loot,"id:\"minecraft:record_13\",Count:1b")
- elseif chance > 57 then table.insert(loot,"id:\"minecraft:record_cat\",Count:1b")
- elseif chance > 42 then table.insert(loot,"id:\"minecraft:iron_horse_armor\",Count:1b")
- elseif chance > 27 then table.insert(loot,"id:\"minecraft:golden_apple\",Count:1b")
- elseif chance > 17 then table.insert(loot,"id:\"minecraft:enchanted_book\",Count:1b")
- elseif chance > 7 then table.insert(loot,"id:\"minecraft:golden_horse_armor\",Count:1b")
- elseif chance > 2 then table.insert(loot,"id:\"minecraft:diamond_horse_armor\",Count:1b")
- else table.insert(loot,"id:\"minecraft:golden_apple\",Count:1b,Damage:1s")
- end
- end
- --Stack #2
- slot,size=1,math.random(1,4)
- for slot=1,size do
- local chance,qty = math.random(116), math.random(4)
- if chance > 95 then table.insert(loot,"id:\"minecraft:wheat\",Count:"..qty.."b")
- elseif chance > 75 then table.insert(loot,"id:\"minecraft:bread\",Count:"..qty.."b")
- elseif chance > 60 then table.insert(loot,"id:\"minecraft:coal\",Count:"..qty.."b")
- elseif chance > 45 then table.insert(loot,"id:\"minecraft:redstone\",Count:"..qty.."b")
- elseif chance > 35 then table.insert(loot,"id:\"minecraft:melon_seeds\",Count:"..math.max(2,qty).."b")
- elseif chance > 25 then table.insert(loot,"id:\"minecraft:pumpkin_seeds\",Count:"..math.max(2,qty).."b")
- elseif chance > 15 then table.insert(loot,"id:\"minecraft:iron_ingot\",Count:"..qty.."b")
- elseif chance > 5 then table.insert(loot,"id:\"minecraft:bucket\",Count:1b")
- else table.insert(loot,"id:\"minecraft:gold_ingot\",Count:"..qty.."b")
- end
- end
- --Stack #3
- for slot=1,3 do
- local chance,qty = math.random(41), math.random(8)
- if chance > 30 then table.insert(loot,"id:\"minecraft:bone\",Count:"..qty.."b")
- elseif chance > 20 then table.insert(loot,"id:\"minecraft:gunpowder\",Count:"..qty.."b")
- elseif chance > 10 then table.insert(loot,"id:\"minecraft:rotten_flesh\",Count:"..qty.."b")
- else table.insert(loot,"id:\"minecraft:string\",Count:"..qty.."b")
- end
- end
- return loot
- end
- local function shuffle( t )
- output("Shuffle dungeon chest") --#
- local iterations = #t
- local j
- for i = iterations, 2, -1 do
- j = math.random(i)
- t[i], t[j] = t[j], t[i]
- end
- return t
- end
- local function chest_data(loot)
- local data,slotSet,s,slot = "",{},""
- --Add empty slots
- for slot=1,27 do loot[slot] = loot[slot] or false end
- --Randomize
- loot = shuffle(loot)
- --Compile
- for slot=1,27 do
- if loot[slot] then
- data = data..s..(slot-1)..":{Slot:"..(slot-1).."b,"..loot[slot].."}"
- s = ","
- end
- end
- return "Items:["..data.."]"
- end
- --id: Zombie, Spider, Skeleton, CaveSpider, Blaze, Silverfish
- local function mobspawner_data(id)
- output("Setup "..id.." mobspawner") --#
- id = id or "Pig"
- return "{EntityId:\""..id.."\"}"
- end
- function dungeon(x,y,z)
- output("Generate dungeon") --#
- local i
- local Entiy = {"Zombie","Zombie","Spider","Skeleton"}
- local wx,wz = 7+(math.random(0,1)*2),7+(math.random(0,1)*2)
- --clear space and walls
- commands.fill(x,y,z, x+wx-1,y+4,z+wz-1, "minecraft:air",0,"replace")
- commands.fill(x,y,z, x+wx-1,y+4,z+wz-1, "minecraft:cobblestone",0,"outline")
- commands.fill(x+1,y+4,z+1, x+wx-2,y+4,z+wz-2, "minecraft:air",0,"replace")
- --floor
- commands.fill(x,y,z, x+wx-1,y,z+wz-1, "minecraft:mossy_cobblestone",0,"replace")
- for i=1,math.ceil(wx*wz/3) do
- output("Generate dungeon"..string.rep(".",i%5)) --#
- local _x,_z = math.random(0,wx-1),math.random(0,wz-1)
- commands.setblock(x+_x,y,z+_z,"minecraft:cobblestone",0,"replace")
- sleep(.1)
- end
- --Break wall
- for i=1,math.random(3,7) do
- bubble(math.random(x-1,x+wx-4),y+1,math.random(z-1,z+wz-4), "minecraft:air", 0)
- sleep(.1)
- end
- --Place mob spawner
- commands.setblock(x+math.ceil((wx-1)/2),y+1,z+math.ceil((wz-1)/2),
- "minecraft:mob_spawner",0,"replace",
- mobspawner_data(Entiy[math.random(1,4)]))
- --Chests
- if math.random(32)~=1 then
- local place_seed = math.random(1,5)*2
- local place = string.sub("121314232434",place_seed,place_seed+1)
- local chance = math.random(1,2)
- for i=1,chance do
- local side = string.sub(place,i,i)
- local dmg,_x,_z
- --North -z
- if side=="1" then dmg,_x,_z = 3,math.random(1,wx-2),1
- --East +x
- elseif side=="2" then dmg,_x,_z = 4,wx-2,math.random(1,wz-2)
- --South +z
- elseif side=="3" then dmg,_x,_z = 2,math.random(1,wx-1),wz-2
- --West -x
- elseif side=="4" then dmg,_x,_z = 5,1,math.random(1,wz-2)
- end
- commands.setblock(x+_x,y+1,z+_z,
- "minecraft:chest",dmg,"replace",
- "{"..chest_data(dungeon_loot()).."}")
- sleep(.1)
- end
- end
- end
- function clone()
- output("Clone ref to target chunk ref chunk") --#
- commands.clone(refChunk.x,refChunk.y,refChunk.z,
- refChunk.x+15,refChunk.y+15,refChunk.z+15,
- targetChunk.x,targetChunk.y,targetChunk.z, "replace")
- end
- local function getSwitchStoneSate()
- local data = commands.getBlockInfo(refChunk.x+8,refChunk.y-3,refChunk.z+8)
- if data.name=="minecraft:glass" then return false
- elseif data.name=="minecraft:stone" then return true
- else
- commands.setblock(refChunk.x+8,refChunk.y-3,refChunk.z+8,"minecraft:stone",0,"replace")
- return true
- end
- end
- settings.load(settingsFile)
- opt = {
- stone=getSwitchStoneSate(),
- lava=settings.get("OptiMiner.lava",true),
- water=settings.get("OptiMiner.water",true),
- bedrock=settings.get("OptiMiner.bedrock",true),
- dungeon=settings.get("OptiMiner.dungeon",false),
- turtleCustomID=settings.get("OptiMiner.CustomID",turtleID),
- turtleFuelLevel=settings.get("OptiMiner.turtleFuelLevel",100000),
- turtleEquipLeft=settings.get("OptiMiner.turtleEquipLeft","minecraft:diamond_pickaxe"),
- turtleEquipRight=settings.get("OptiMiner.turtleEquipRight",false),
- }
- function save_params()
- settings.set("OptiMiner.turtleID",turtleID)
- local k,v
- for k,v in pairs(opt) do
- if k~="stone" then
- settings.set("OptiMiner."..k,v)
- end
- end
- settings.save(settingsFile)
- end
- save_params()
- function bedrockLayer(state)
- local blockType = state and "minecraft:bedrock" or "minecraft:air"
- commands.fill(
- refChunk.x, refChunk.y+16,refChunk.z,
- refChunk.x+15, refChunk.y+16,refChunk.z+15,
- blockType,0,"replace")
- end
- function generate()
- output("Generate ref chunk") --#
- bedrockLayer(opt.bedrock)
- fillChunk(refChunk, opt.stone and "minecraft:stone" or "minecraft:glass")
- if opt.water then water_populate(refChunk) end
- dirt_populate(refChunk)
- ore_populate(refChunk)
- hole_populate(refChunk)
- if opt.lava then lava_populate(refChunk) end
- if opt.dungeon then
- dungeon(
- refChunk.x+math.random(5),
- refChunk.y+math.random(8),
- refChunk.z+math.random(5))
- end
- end
- function clearRefChunk()
- output("Clear ref chunk") --#
- commands.fill(
- refChunk.x, refChunk.y+16,refChunk.z,
- refChunk.x+15, refChunk.y+16,refChunk.z+15,
- "minecraft:air",0,"replace")
- clearChunk(refChunk)
- end
- function clearTargetChunk()
- output("Clear target chunk") --#
- commands.fill(
- targetChunk.x, targetChunk.y+16,targetChunk.z,
- targetChunk.x+15, targetChunk.y+16,targetChunk.z+15,
- "minecraft:air",0,"replace")
- clearChunk(targetChunk)
- end
- --fill <x1> <y1> <z1> <x2> <y2> <z2> <TileName> <dataValue> replace [replaceTileName] [replaceDataValue]
- function switchStone()
- output(opt.stone and "Switch Glass to Stone" or "Switch Stone to Glass") --#
- commands.fill(refChunk.x,refChunk.y,refChunk.z,
- targetChunk.x+15,targetChunk.y+15,targetChunk.z+15,
- opt.stone and "minecraft:stone" or "minecraft:glass",
- 0, "replace", opt.stone and "minecraft:glass" or "minecraft:stone")
- commands.setblock(refChunk.x+8,refChunk.y-3,refChunk.z+8, opt.stone and "minecraft:stone" or "minecraft:glass",0,"replace")
- end
- function highlightChunk(chunk)
- output("Highlight target chunk") --#
- commands.summon("LightningBolt",chunk.x+8, chunk.y+32,chunk.z+8)
- local i
- for i=-0,16 do
- commands.summon("XPOrb",chunk.x+i, chunk.y+18,chunk.z-1, "{Age:5900,Value:0}")
- commands.summon("XPOrb",chunk.x+i, chunk.y+18,chunk.z+16,"{Age:5900,Value:0}")
- commands.summon("XPOrb",chunk.x-1, chunk.y+18,chunk.z+i, "{Age:5900,Value:0}")
- commands.summon("XPOrb",chunk.x+16,chunk.y+18,chunk.z+i, "{Age:5900,Value:0}")
- end
- end
- local function btn(str,x,y,state,w)
- state = state or false
- local pad1,pad2 = " "," "
- if not w then
- w = string.len(str)+2
- else
- if string.len(str)>=w then
- str = string.sub(str,1,w)
- pad1,pad2 = "",""
- else
- pad1 = string.rep(" ",math.floor(w-string.len(str)/2))
- pad2 = string.rep(" ",math.ceil(w-string.len(str)/2))
- end
- end
- term.setCursorPos(x,y)
- setColor(colors.black,state and colors.black or colors.lightGray)
- term.write(string.rep(string.char(143),w))
- term.setCursorPos(x,y+1)
- setColor(colors.black,state and colors.white or colors.lightGray)
- term.write(pad1..str..pad2)
- setColor(state and colors.white or colors.gray,colors.black)
- term.setCursorPos(x,y+2)
- term.write(string.rep(string.char(131),w))
- end
- local function onclick_btn(_x,_y,str,bx,by)
- local w = string.len(str)+1
- return _x >= bx-1 and _x <= bx+w
- and _y >= by and _y <= by+1
- end
- local function btn_list(tItems,x,y,w)
- local k,v
- for k,v in pairs(tItems) do
- local last = k >= #tItems
- local str = v
- local pad1,pad2 = " "," "
- if not w then
- w = string.len(str)+2
- else
- if string.len(str)>=w then
- str = string.sub(str,1,w)
- pad1,pad2 = "",""
- else
- local len = (w-string.len(str))/2
- pad1 = string.rep(" ",math.floor(len))
- pad2 = string.rep(" ",math.ceil(len))
- end
- end
- if k == 1 then
- term.setCursorPos(x,y)
- setColor(colors.black,state and colors.black or colors.lightGray)
- term.write(string.rep(string.char(143),w))
- y = y+1
- end
- term.setCursorPos(x,y)
- setColor(colors.black,state and colors.white or colors.lightGray)
- term.write(pad1..str..pad2)
- term.setCursorPos(x,y+1)
- if last then
- setColor(colors.gray,colors.black)
- term.write(string.rep(string.char(131),w))
- else
- setColor(colors.black,colors.lightGray)
- term.write(string.rep(string.char(140),w))
- end
- y=y+2
- end
- end
- function display()
- header()
- term.setCursorPos(3,4)
- setColor(colors.yellow,colors.black)
- term.write("Chunk:")
- btn("Generate",9,3)
- btn("Clone",20,3)
- btn("Clear",28,3)
- btn(opt.stone and "Stone" or "Glass",36,3)
- term.setCursorPos(2,7)
- setColor(colors.yellow,colors.black)
- term.write("Option:")
- btn(opt.lava and string.char(26).."Lava" or "-Lava",9,6)
- btn(opt.water and string.char(26).."Water" or "-Water",17,6)
- btn(opt.bedrock and string.char(26).."Bedrock" or "-Bedrock",26,6)
- btn(opt.dungeon and string.char(26).."Dungeon" or "-Dungeon",37,6)
- term.setCursorPos(3,10)
- setColor(colors.yellow,colors.black)
- term.write("Utils:")
- btn("Turtle",11,9)
- btn("Clear Mobs",20,9)
- btn("Highlight chunk",33,9)
- --Credits
- btn(string.char(1),2,16)
- end
- function turtle_submenu()
- local editTurtleParams = true
- while editTurtleParams do
- --Clear
- term.setBackgroundColor(colors.black)
- local i
- for i=12,th do
- term.setCursorPos(1,i)
- term.clearLine()
- end
- --Display submenu
- term.setCursorPos(3,13)
- setColor(colors.yellow,colors.black)
- term.write("Turtle:{")
- term.setCursorPos(10,18)
- term.write("}")
- --GIVE
- btn("Give ",2,14)
- --
- btn("Close",2,17)
- btn_list({
- "ID"..string.char(16)..string.rep(" ",8),
- "Fuel"..string.char(16)..string.rep(" ",6),
- "Equip",
- },12,12,13)
- --Edit Turtle ID
- term.setCursorPos(16,13)
- local strID = "#"..(opt.turtleCustomID and opt.turtleCustomID or turtleID)
- setColor(colors.black,colors.white)
- term.write(string.sub(strID,1,8)..string.rep(" ",math.max(0,8-string.len(strID))))
- --Edit fuel level
- term.setCursorPos(18,15)
- local fuelLevel = tostring(opt.turtleFuelLevel)
- setColor(colors.black,colors.white)
- term.write(string.sub(fuelLevel,1,6)..string.rep(" ",math.max(0,6-string.len(fuelLevel))))
- --Select Equip left/right
- --btn("Equip",12,18)
- setColor(colors.yellow,colors.black)
- local e,b,x,y = os.pullEvent("mouse_click")
- -- output(string.format("Click %d x[%d],y[%d]",b,x,y)) --#
- if b==1 then
- if y<11 then
- editTurtleParams = false
- return false
- elseif x>=2 and x<=8 then
- --Close
- if y==18 or y==19 then
- sound_click()
- output("Close Turtle submenu") --#
- editTurtleParams = false
- return false
- --Give
- elseif y==15 or y==16 then
- giveTurtle(opt.turtleCustomID and opt.turtleCustomID or turtleID)
- return true
- end
- elseif x>=12 and x<=24 then
- --Edit ID
- if y==13 then
- output("Input Turtle ID") --#
- sound_click()
- local confirm=false
- while not confirm do
- term.setCursorPos(15,13)
- term.setBackgroundColor(colors.white)
- term.write(string.rep(" ",9))
- term.setBackgroundColor(colors.lightGray)
- term.write(" ")
- term.setBackgroundColor(colors.black)
- term.write(string.rep(" ",tw))
- setColor(colors.black,colors.white)
- term.setCursorPos(15,13)
- local input = tonumber(read())
- setColor(colors.white,colors.black)
- if input and input>=0 then
- if input == os.getComputerID() then
- output("ID #"..input.." used by "..os.getComputerLabel()) --#
- else
- confirm = true
- opt.turtleCustomID = input
- save_params()
- return true
- end
- else
- output("Turtle ID: number >= 0") --#
- end
- end
- --Edit fuel
- elseif y==15 then
- output("Input Turtle Fuel level") --#
- sound_click()
- local confirm=false
- while not confirm do
- term.setCursorPos(17,15)
- term.setBackgroundColor(colors.white)
- term.write(string.rep(" ",7))
- term.setBackgroundColor(colors.lightGray)
- term.write(" ")
- term.setBackgroundColor(colors.black)
- term.write(string.rep(" ",tw))
- setColor(colors.black,colors.white)
- term.setCursorPos(17,15)
- local input = tonumber(read())
- setColor(colors.white,colors.black)
- if input and input>=0 and input<=100000 then
- output("Fuel level set: "..input) --#
- confirm = true
- opt.turtleFuelLevel = input
- save_params()
- return true
- elseif input and input<0 then
- output("Fuel level: number >= 0") --#
- elseif input and input>100000 then
- output("Fuel level limit: 100000") --#
- else
- output("Fuel level should be a number") --#
- end
- end
- --Equip config
- elseif y==17 or y==18 then
- output("Config Turtle equipement") --#
- sound_click()
- --List (7 rows)
- local turtleEquipement = {
- { name ="pickaxe", id="minecraft:diamond_pickaxe", },
- { name ="shovel", id="minecraft:diamond_shovel", },
- { name ="sword", id="minecraft:diamond_sword", },
- { name ="crafting table", id="minecraft:crafting_table", },
- { name ="modem", id="computercraft:wireless_modem"},
- { name ="ender modem", id="computercraft:advanced_modem"},
- }
- local sideEquipement = "L"
- local selectEquipment = true
- while selectEquipment do
- --Clear
- term.setBackgroundColor(colors.black)
- local i
- for i=12,th do
- term.setCursorPos(12,i)
- term.write(string.rep(" ",tw))
- end
- --Display
- btn_list({
- "Equip",
- (sideEquipement=="L" and " Left "..string.char(26) or"Left"),
- (sideEquipement=="R" and " Right "..string.char(26) or"Right"),
- string.char(17),
- },12,12,13)
- local alt,k,item=false
- for k,item in pairs(turtleEquipement) do
- alt = not alt
- local cur = " "
- if (sideEquipement=="L" and opt.turtleEquipLeft==item.id )
- or (sideEquipement=="R" and opt.turtleEquipRight==item.id) then
- cur = " "..string.char(26)
- end
- term.setCursorPos(26,k+12)
- setColor(
- cur==" " and colors.black or colors.red,
- alt and colors.white or colors.yellow)
- term.write(cur..item.name..string.rep(" ",math.max(0,tw-29-string.len(item.name))))
- end
- setColor(colors.white,colors.black)
- local e,b,x,y = os.pullEvent("mouse_click")
- output(string.format("Click %d x[%d],y[%d]",b,x,y)) --#
- if b==1 then
- --Give Turtle
- if x>=2 and x<=8 and (y==15 or y==16) then
- giveTurtle(opt.turtleCustomID and opt.turtleCustomID or turtleID)
- --Close Turtle submenu
- elseif x>=2 and x<=8 and (y==18 or y==19) then
- output("Close Turtle submenu") --#
- sound_click()
- selectEquipment = false
- return false
- --Equipment submenu
- elseif x>=12 and x<=24 and y>=15 and y<=19 then
- --Select Left equipment
- if y==15 then
- output("Equip left") --#
- sound_click()
- sideEquipement="L"
- --Select Right equipment
- elseif y==17 then
- output("Equip right") --#
- sound_click()
- sideEquipement="R"
- --Close Equipment selection
- elseif y==19 then
- output("Close equipment selection") --#
- sound_click()
- selectEquipment = false
- break
- end
- --Equipment list
- elseif x>=26 and x<=49 and y>=13 and y<=18 then
- local selected = y-12
- sound_click()
- if sideEquipement=="L" then
- if opt.turtleEquipLeft==turtleEquipement[selected].id then
- output("Unequip left side") --#
- opt.turtleEquipLeft=false
- else
- output("Equip left side: "..turtleEquipement[selected].name) --#
- opt.turtleEquipLeft=turtleEquipement[selected].id
- end
- else
- if opt.turtleEquipRight==turtleEquipement[selected].id then
- output("Unequip right side") --#
- opt.turtleEquipRight=false
- else
- output("Equip right side: "..turtleEquipement[selected].name) --#
- opt.turtleEquipRight=turtleEquipement[selected].id
- end
- end
- save_params()
- end
- end
- sleep(.1)
- if not selectEquipment then
- break
- end
- end
- end
- end
- end
- sleep(.1)
- end
- end
- local function display_credits()
- --Clear
- term.setBackgroundColor(colors.black)
- local i
- for i=12,th do
- term.setCursorPos(1,i)
- term.clearLine()
- end
- setColor(colors.yellow,colors.black)
- term.setCursorPos(3,17) term.write(string.char(2))
- setColor(colors.white,colors.black)
- term.write(string.char(17))
- setColor(colors.black,colors.white)
- term.setCursorPos(5,16) term.write(string.rep(string.char(143),33))
- term.setCursorPos(5,17) term.write(" OptimineMgr by SukaiPoppuGo ")
- term.setCursorPos(5,18) term.write(" Credits: 2016 - CC BY-NC-SA 4.0 ")
- setColor(colors.white,colors.black)
- term.setCursorPos(5,19) term.write(string.rep(string.char(131),33))
- sleep(.5)
- os.pullEvent("mouse_click")
- end
- while true do
- display()
- local e,b,_x,_y = os.pullEvent("mouse_click")
- term.setCursorPos(18,1)
- setColor(colors.gray, colors.black)
- --Credits
- if onclick_btn(_x,_y,"c",2,16) then
- output("Display credits "..string.char(3)) --#
- sound_click()
- display_credits()
- output(string.char(3)) --#
- --Chunk
- elseif onclick_btn(_x,_y,"Generate",9,3) then
- output("Click: Generate chunk") --#
- sound_click()
- btn("Generate",9,3,true)
- clearRefChunk()
- generate(refChunk)
- output("Done") --#
- elseif onclick_btn(_x,_y,"Clone",20,3) then
- output("Click: Clone chunk") --#
- sound_click()
- btn("Clone",20,3,true)
- clone()
- output("Done") --#
- elseif onclick_btn(_x,_y,"Clear",28,3) then
- output("Click: Clear chunk") --#
- sound_click()
- btn("Clear",28,3,true)
- clearTargetChunk()
- output("Done") --#
- elseif onclick_btn(_x,_y,"Stone",36,3) then
- output("Toggle Stone/Glass") --#
- sound_click()
- opt.stone = not opt.stone
- btn(opt.stone and "Stone" or "Glass",36,3,true)
- switchStone()
- --Options
- elseif onclick_btn(_x,_y,"-Lava",9,6) then
- output("Click: Lava") --#
- sound_click()
- opt.lava = not opt.lava
- btn(opt.lava and string.char(26).."Lava" or "-Lava",9,6,true)
- save_params()
- elseif onclick_btn(_x,_y,"-Water",16,6) then
- output("Click: Water") --#
- sound_click()
- opt.water = not opt.water
- btn(opt.water and string.char(26).."Water" or "-Water",17,6,true)
- save_params()
- elseif onclick_btn(_x,_y,"-Bedrock",24,6) then
- output("Toggle Bedrock") --#
- sound_click()
- opt.bedrock = not opt.bedrock
- btn(opt.bedrock and string.char(26).."Bedrock" or "-Bedrock",26,6,true)
- bedrockLayer(opt.bedrock)
- save_params()
- elseif onclick_btn(_x,_y,"-Dungeon",34,6) then
- output("Toggle Dungeon") --#
- sound_click()
- opt.dungeon = not opt.dungeon
- btn(opt.dungeon and string.char(26).."Dungeon" or "-Dungeon",37,6,true)
- save_params()
- --Utils
- elseif onclick_btn(_x,_y,"Turtle",11,9) then
- output("Click: Turtle") --#
- sound_click()
- btn("Turtle",11,9,true)
- while turtle_submenu() do
- sleep(.1)
- end
- elseif onclick_btn(_x,_y,"Clear Mobs",20,9) then
- output("Click: Clear Mobs") --#
- sound_click()
- btn("Clear Mobs",20,9,true)
- kill(refChunk,"!Player")
- kill(targetChunk,"!Player")
- elseif onclick_btn(_x,_y,"Highlight chunk",33,9)then
- output("Click: Highlight chunk") --#
- sound_click()
- btn("Highlight chunk",33,9,true)
- highlightChunk(targetChunk)
- end
- sleep(.1)
- end
Add Comment
Please, Sign In to add comment