Advertisement
Guest User

cscan

a guest
Dec 18th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. MenuBg=colors.lightGray
  2. MenuBtn=colors.green
  3. Chunk=colors.black
  4. ActiveChunk=colors.lightBlue
  5. p = peripheral.wrap('bottom')
  6. w = p.getWorld(p.getPeripheralWorldID())
  7. --w={}
  8. --w.map={[0]={[0]=true,[10]=true},[5]={[5]=true},[10]={[10]=true}}
  9. --w.isChunkLoaded=function(x,z)
  10. --  if w.map[z] then return w.map[z][x] end
  11. --end
  12.  
  13. inifilename='cscan.ini'
  14. term.clear()
  15. inifile=fs.open(inifilename,'r')
  16. if inifile then
  17.   cx,cz=string.match(inifile.readLine(),'cx=(%d+)%s+cz=(%d+)')
  18.   inifile.close()
  19. else
  20.   cx=0 cz=0
  21. end
  22. local work=true
  23. local eventKey={}
  24. local scantimer
  25. local buttons={}
  26. local function AddButton(name,x,y,proc)
  27.   table.insert(buttons,{name=name, x1=x, x2=x+#name-1, y=y, proc=proc})
  28. end
  29.  
  30. local function scan()
  31.   term.setBackgroundColor(MenuBg)
  32.   term.clear()
  33.   term.setTextColor(Chunk)
  34.   for i=1,19 do
  35.     z=cz+i-10
  36.     term.setCursorPos(1,i)
  37.     for x=cx-9,cx+9 do
  38.       if w.isChunkLoaded(x, z) then term.setBackgroundColor(ActiveChunk)
  39.       else term.setBackgroundColor(Chunk) end
  40.       if x==cx and z==cz  then
  41.         term.setTextColor(colors.red)
  42.       end
  43.       write('[]')
  44.       term.setTextColor(Chunk)
  45.     end
  46. --    sleep(0)
  47.   end
  48.   term.setTextColor(colors.black)
  49.   term.setBackgroundColor(MenuBg)
  50.   term.setCursorPos(40,1) write('x='..16*cx..','..cx*16+15)
  51.   term.setCursorPos(40,2) write('z='..16*cz..','..cz*16+15)
  52.   term.setBackgroundColor(MenuBtn)
  53.   for i=1,#buttons do
  54.     term.setCursorPos(buttons[i].x1,buttons[i].y) write(buttons[i].name)
  55.   end
  56. --  term.setCursorPos(43,4) write('Go to')
  57.   scantimer=os.startTimer(10)
  58. end
  59.  
  60. eventKey[keys.left]=function()
  61.   cx=cx-5 scan()
  62. end
  63.  
  64. eventKey[keys.right]=function()
  65.   cx=cx+5 scan()
  66. end
  67.  
  68. eventKey[keys.up]=function()
  69.   cz=cz-5 scan()
  70. end
  71.  
  72. eventKey[keys.down]=function()
  73.   cz=cz+5 scan()
  74. end
  75.  
  76. eventKey[keys.f10]=function()
  77.   work=false
  78. end
  79.  
  80. function goto()
  81.   term.setCursorPos(40,5) write('x=') cx=math.floor((tonumber(read()) or 0)/16)
  82.   term.setCursorPos(40,6) write('z=') cz=math.floor((tonumber(read()) or 0)/16)
  83.   scan()
  84. end
  85. function jamp()
  86.   term.setCursorPos(40,7) write('Name ')
  87.   pl=p.getPlayerByName(read())
  88.   if pl then
  89.     term.setCursorPos(40,8) write('y=')
  90.     ent=pl.asEntity()
  91.     ent.setPosition(cx*16+15,tonumber(read()),cz*16+7)
  92.   end
  93.   scan()
  94. end
  95.  
  96. AddButton('Go to',43,4,goto)
  97. AddButton('Jamp to',43,6,jamp)
  98. scan()
  99. while work do
  100.   local event,p1,mx,my=os.pullEvent()
  101.   if event=='key' then
  102.     if eventKey[p1]~=nil then eventKey[p1]() end
  103.   elseif event=='mouse_click' then
  104.     if mx>38 then
  105.       term.setTextColor(colors.black)
  106.       term.setBackgroundColor(MenuBg)
  107.       for i=1,#buttons do
  108.         if my==buttons[i].y and mx>=buttons[i].x1 and mx<=buttons[i].x2 then
  109.           buttons[i].proc()
  110.         end
  111.       end
  112.     else
  113.       mx=math.ceil(mx/2)
  114.       cx=cx+mx-10
  115.       cz=cz+my-10
  116.       scan()
  117.     end
  118. --  elseif event=='mouse_drag' then
  119.   elseif event=='timer' then
  120.     if p1==scantimer then scan() end
  121.   end
  122. end
  123.  
  124. inifile=fs.open(inifilename,'w')
  125. inifile.writeLine('cx='..cx..' cz='..cz)
  126. inifile.close()
  127. term.setTextColor(colors.white)
  128. term.setBackgroundColor(colors.black)
  129. term.clear()
  130. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement