Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------ToolBox------
- function file_exists(name)
- local f=io.open(name,"r")
- if f~=nil then io.close(f) return true else return false end
- end
- function AnitaRead(var_name)
- if not file_exists("Anita/Anitas.last") then
- InitializeAnitaLast()
- end
- local fileHandle = fs.open ("Anita/Anitas.last", 'r')
- _table = textutils.unserialize (fileHandle.readAll())
- fileHandle.close()
- if var_name == nil then
- return _table
- else
- return _table[var_name]
- end
- end
- function AnitaWrite(Var_name,Var)
- if not file_exists("Anita/Anitas.last") then
- InitializeAnitaLast()
- end
- local fileHandle = fs.open ("Anita/Anitas.last", 'r')
- _table = textutils.unserialize (fileHandle.readAll())
- fileHandle.close()
- _table[Var_name] = Var
- local fileHandle = fs.open ("Anita/Anitas.last", 'w')
- fileHandle.write (textutils.serialize (_table))
- fileHandle.close()
- end
- function InitializeAnitaLast()
- local QuarryData = {
- ["Rednet"] = false,
- ["Check Fuel"] = true,
- ["EnderChest"] = 0,
- ["Original Day"] = 0,
- ["Original Time"] = 0,
- ["Position"] = {0,0,0},
- ["Orientation"] = 1,
- ["Size"] = {0,0,0},
- ["Type de minage"] = "Quarry",
- ["Block miné"] = 0,
- ["Pierre miné"] = 0,
- ["Charbon miné"] = 0,
- ["Couche miné"] = 0,
- ["Progression"] = 0,
- ["Mouvement"] = 0,
- ["Total Fuel"] = 0,
- ["Fuel Level"] = 0,
- ["Last turn"] = false
- }
- local fileHandle = fs.open ("Anita/Anitas.last", 'w')
- fileHandle.write (textutils.serialize (QuarryData))
- fileHandle.close()
- end
- function round(x)
- return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
- end
- function Draw(ActiveItemList)
- for k,Button in pairs(ActiveItemList) do
- fill(Button["text"],Button["backcolor"],Button["textcolor"],Button)
- end
- end
- function WriteText(ColorList, TextList)
- for key,value in pairs(TextList) do
- term.setTextColor(ColorList[key])
- term.write(value)
- end
- end
- function fill(text, color,textcolor, bData)
- term.setTextColor(textcolor)
- term.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- term.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- term.write(text)
- else
- term.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- term.write(" ")
- end
- end
- end
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.black)
- end
- function MoveRight()
- local dir = AnitaRead("Orientation")
- turtle.turnRight()
- dir = math.mod(dir + 1,5)
- if dir == 0 then
- dir = 1
- end
- AnitaWrite("Orientation",dir)
- end
- function MoveLeft()
- local dir = AnitaRead("Orientation")
- turtle.turnLeft()
- dir = math.mod(dir- 1,5)
- if dir == 0 then
- dir = 1
- end
- AnitaWrite("Orientation",dir)
- end
- function MoveDown()
- local pos = AnitaRead("Position")
- while turtle.down() == false do
- turtle.digDown()
- end
- pos[3] = pos[3] - 1
- AnitaWrite("Position",pos)
- end
- function MoveUp()
- local pos = AnitaRead("Position")
- while turtle.up() == false do
- turtle.digUp()
- end
- pos[3] = pos[3] + 1
- AnitaWrite("Position",pos)
- end
- function MoveForward()
- local pos = AnitaRead("Position")
- local dir = AnitaRead("Orientation")
- while turtle.forward() == false do
- turtle.dig()
- end
- if dir == 1 then
- pos[1] = pos[1] + 1
- elseif dir == 2 then
- pos[2] = pos[2] + 1
- elseif dir == 3 then
- pos[1] = pos[1] - 1
- else
- pos[2] = pos[2] - 1
- end
- AnitaWrite("Position",pos)
- end
- function MoveBack()
- local pos = AnitaRead("Position")
- local dir = AnitaRead("Orientation")
- while turtle.back() == false do
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if dir == 1 then
- pos[1] = pos[1] - 1
- elseif dir == 2 then
- pos[2] = pos[2] - 1
- elseif dir == 3 then
- pos[1] = pos[1] + 1
- else
- pos[2] = pos[2] + 1
- end
- AnitaWrite("Position",pos)
- end
Add Comment
Please, Sign In to add comment