Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- rednet.open("right")
- glasses=peripheral.find("openperipheral_bridge")
- local draw={}
- draw.box1={["type"]="box",["x"]=0,["y"]=0,["width"]=300,["height"]=200,["color"]=0,["opacity"]=0.2}
- draw.edit1={["type"]="memo",["x"]=0,["y"]=0,["width"]=200,["height"]=200,["color"]=colors.black,["lines"]={}}
- draw.edit2={["type"]="memo",["x"]=0,["y"]=200,["width"]=200,["height"]=50,["color"]=colors.black,["lines"]={}}
- draw.box2={["type"]="box",["x"]=0,["y"]=200,["width"]=300,["height"]=50,["color"]=0,["opacity"]=0.2}
- draw.turtleInventory={["type"]="inventory",["x"]=300,["y"]=0,["width"]=150,["height"]=100,["color"]=0,["items"]={},["opacity"]=0.2,["visible"]=false,}
- local inventory={}
- function main()
- id,message,protocol=rednet.receive()
- print(protocol)
- if protocol~=nil and string.find(protocol,"position")~=nil then
- draw.edit2.lines["position"]=message
- elseif protocol~=nil and string.find(protocol,"facing")~=nil then
- draw.edit2.lines["facing"]=message
- elseif protocol~=nil and string.find(protocol,"powerLevel")~=nil then
- draw.edit2.lines["powerLevel"]=message
- elseif protocol~=nil and string.find(protocol,"inventory")~=nil then
- for i=1,16 do
- local itemString=splitString(message,"|",i)
- local itemName=splitString(itemString,",",1)
- local itemCount=splitString(itemString,",",2)
- local itemDamage=splitString(itemString,",",3)
- inventory[i]={["name"]=itemName,["count"]=itemCount,["damage"]=itemDamage,}
- end
- draw.turtleInventory.items=inventory
- draw.turtleInventory.visible=true
- else
- draw.edit1.lines[#draw.edit1.lines+1]=message
- if #draw.edit1.lines>20 then
- draw.edit1.y=((#draw.edit1.lines)-20)*-10
- end
- end
- drawFunction()
- end
- function drawFunction()
- glasses.clear()
- for id,data in pairs(draw) do
- if data.type=="box" then
- glasses.addBox(data.x,data.y,data.width,data.height,data.color,data.opacity)
- elseif data.type=="memo" then
- local index=1
- for id,line in pairs(data.lines) do
- local width=glasses.getStringWidth(line)
- local line="["..id.."] "..line
- if width>data.width then
- line=string.sub(line,1,string.len(line)/width*375)
- end
- glasses.addText(data.x,data.y+(index-1)*10,line,data.color)
- index=index+1
- end
- elseif data.type=="inventory" then
- if data.visible==true then
- glasses.addBox(data.x,data.y,data.width,data.height,data.color,data.opacity)
- for i=1,16 do
- local item=inventory[i]
- if item~=nil and item.count~=nil then
- if i<=4 then
- glasses.addIcon(data.x+data.width/4*(i-1),data.y+data.height/4*0,item.name,0)
- glasses.addText(data.x+data.width/4*(i-1)+20,data.y+data.height/4*0+10,item.count,1000000000000000000)
- elseif i<=8 then
- glasses.addIcon(data.x+data.width/4*(i-1)-data.width,data.y+data.height/4*1,item.name,0)
- glasses.addText(data.x+data.width/4*(i-1)-data.width+20,data.y+data.height/4*1+10,item.count,1000000000000000000)
- elseif i<=12 then
- glasses.addIcon(data.x+data.width/4*(i-1)-data.width*2,data.y+data.height/4*2,item.name,0)
- glasses.addText(data.x+data.width/4*(i-1)-data.width*2+20,data.y+data.height/4*2+10,item.count,1000000000000000000)
- elseif i<=16 then
- glasses.addIcon(data.x+data.width/4*(i-1)-data.width*3,data.y+data.height/4*3,item.name,0)
- glasses.addText(data.x+data.width/4*(i-1)-data.width*3+20,data.y+data.height/4*3+10,item.count,1000000000000000000)
- end
- end
- end
- end
- end
- end
- glasses.sync()
- end
- function splitString(sourceString,splittingChar,index)
- results={}
- currentWord=""
- for i=1,string.len(sourceString) do
- letter=string.sub(sourceString,i,i)
- if letter==splittingChar then
- results[#results+1]=currentWord
- currentWord=""
- else
- currentWord=currentWord..letter
- end
- end
- results[#results+1]=currentWord
- return results[index]
- end
- drawFunction()
- while true do
- main()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement