Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MenuBg=colors.lightGray
- MenuBtn=colors.green
- Chunk=colors.black
- ActiveChunk=colors.lightBlue
- p = peripheral.wrap('bottom')
- w = p.getWorld(p.getPeripheralWorldID())
- --w={}
- --w.map={[0]={[0]=true,[10]=true},[5]={[5]=true},[10]={[10]=true}}
- --w.isChunkLoaded=function(x,z)
- -- if w.map[z] then return w.map[z][x] end
- --end
- inifilename='cscan.ini'
- term.clear()
- inifile=fs.open(inifilename,'r')
- if inifile then
- cx,cz=string.match(inifile.readLine(),'cx=(%d+)%s+cz=(%d+)')
- inifile.close()
- else
- cx=0 cz=0
- end
- local work=true
- local eventKey={}
- local scantimer
- local buttons={}
- local function AddButton(name,x,y,proc)
- table.insert(buttons,{name=name, x1=x, x2=x+#name-1, y=y, proc=proc})
- end
- local function scan()
- term.setBackgroundColor(MenuBg)
- term.clear()
- term.setTextColor(Chunk)
- for i=1,19 do
- z=cz+i-10
- term.setCursorPos(1,i)
- for x=cx-9,cx+9 do
- if w.isChunkLoaded(x, z) then term.setBackgroundColor(ActiveChunk)
- else term.setBackgroundColor(Chunk) end
- if x==cx and z==cz then
- term.setTextColor(colors.red)
- end
- write('[]')
- term.setTextColor(Chunk)
- end
- -- sleep(0)
- end
- term.setTextColor(colors.black)
- term.setBackgroundColor(MenuBg)
- term.setCursorPos(40,1) write('x='..16*cx..','..cx*16+15)
- term.setCursorPos(40,2) write('z='..16*cz..','..cz*16+15)
- term.setBackgroundColor(MenuBtn)
- for i=1,#buttons do
- term.setCursorPos(buttons[i].x1,buttons[i].y) write(buttons[i].name)
- end
- -- term.setCursorPos(43,4) write('Go to')
- scantimer=os.startTimer(10)
- end
- eventKey[keys.left]=function()
- cx=cx-5 scan()
- end
- eventKey[keys.right]=function()
- cx=cx+5 scan()
- end
- eventKey[keys.up]=function()
- cz=cz-5 scan()
- end
- eventKey[keys.down]=function()
- cz=cz+5 scan()
- end
- eventKey[keys.f10]=function()
- work=false
- end
- function goto()
- term.setCursorPos(40,5) write('x=') cx=math.floor((tonumber(read()) or 0)/16)
- term.setCursorPos(40,6) write('z=') cz=math.floor((tonumber(read()) or 0)/16)
- scan()
- end
- function jamp()
- term.setCursorPos(40,7) write('Name ')
- pl=p.getPlayerByName(read())
- if pl then
- term.setCursorPos(40,8) write('y=')
- ent=pl.asEntity()
- ent.setPosition(cx*16+15,tonumber(read()),cz*16+7)
- end
- scan()
- end
- AddButton('Go to',43,4,goto)
- AddButton('Jamp to',43,6,jamp)
- scan()
- while work do
- local event,p1,mx,my=os.pullEvent()
- if event=='key' then
- if eventKey[p1]~=nil then eventKey[p1]() end
- elseif event=='mouse_click' then
- if mx>38 then
- term.setTextColor(colors.black)
- term.setBackgroundColor(MenuBg)
- for i=1,#buttons do
- if my==buttons[i].y and mx>=buttons[i].x1 and mx<=buttons[i].x2 then
- buttons[i].proc()
- end
- end
- else
- mx=math.ceil(mx/2)
- cx=cx+mx-10
- cz=cz+my-10
- scan()
- end
- -- elseif event=='mouse_drag' then
- elseif event=='timer' then
- if p1==scantimer then scan() end
- end
- end
- inifile=fs.open(inifilename,'w')
- inifile.writeLine('cx='..cx..' cz='..cz)
- inifile.close()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement