Advertisement
Agent_Silence

Painter

Jan 26th, 2015 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.37 KB | None | 0 0
  1. local x,y,z = commands.getBlockPosition()
  2. local info = commands.getBlockInfo(x,y,z)
  3. local direct = 0
  4. local dir = "y"
  5.  
  6. if info.metadata == 2 then
  7.   direct = 5
  8.   dir = "z"
  9. elseif info.metadata == 3 then  
  10.   direct = -5
  11.   dir = "z"
  12. elseif info.metadata == 4 then
  13.   direct = 5
  14.   dir = "x"
  15. elseif info.metadata == 5 then
  16.   direct = -5
  17.   dir = "x"
  18. end
  19.  
  20. local draw
  21. for i,v in pairs(peripheral.getNames()) do
  22.   if peripheral.getType(v) == "openperipheral_selector" then
  23.     draw = peripheral.wrap(v)
  24.     break
  25.   end
  26. end
  27.  
  28. function discern(sSide,sDir)
  29.   if sSide == "left" then
  30.     if sDir == "x" then
  31.       if direct == -5 and dir == "z" then
  32.         return "~-1"
  33.       elseif direct == 5 and dir == "z" then
  34.         return "~1"
  35.       elseif direct == -5 and dir == "x" then
  36.         return "~-5"
  37.       elseif direct == 5 and dir == "x" then
  38.         return "~5"
  39.       end
  40.     elseif sDir == "z" then
  41.       if direct == -5 and dir == "x" then
  42.         return "~1"
  43.       elseif direct == 5 and dir == "x" then
  44.         return "~-1"
  45.       elseif direct == -5 and dir == "z" then
  46.         return "~-5"
  47.       elseif direct == 5 and dir == "z" then
  48.         return "~5"
  49.       end
  50.     end
  51.   elseif sSide == "right" then
  52.     if sDir == "x" then
  53.       if direct == -5 and dir == "z" then
  54.         return "~1"
  55.       elseif direct == 5 and dir == "z" then
  56.         return "~-1"
  57.       elseif direct == -5 and dir == "x" then
  58.         return "~-5"
  59.       elseif direct == 5 and dir == "x" then
  60.         return "~5"
  61.       end
  62.     elseif sDir == "z" then
  63.       if direct == -5 and dir == "x" then
  64.         return "~-1"
  65.       elseif direct == 5 and dir == "x" then
  66.         return "~1"
  67.       elseif direct == -5 and dir == "z" then
  68.         return "~-5"
  69.       elseif direct == 5 and dir == "z" then
  70.         return "~5"
  71.       end
  72.     end
  73.   end
  74. end
  75.  
  76. function middle(sDir)
  77.   if sDir == "x" then
  78.     if dir == "x" then
  79.       if direct == -5 then
  80.         return "~-5"
  81.       elseif direct == 5 then
  82.         return "~5"
  83.       end
  84.     else
  85.       return "~"
  86.     end
  87.   elseif sDir == "z" then
  88.     if dir == "z" then
  89.       if direct == -5 then
  90.         return "~-5"
  91.       elseif direct == 5 then
  92.         return "~5"
  93.       end
  94.     else
  95.       return "~"
  96.     end
  97.   end
  98. end
  99.  
  100. function drawSlot(nSlot)
  101.   if nSlot == 1 then
  102.     local data = draw.getSlot(nSlot)
  103.     if not data then data = {id = "minecraft:air", dmg = 0} end
  104.     commands.exec("setblock "..discern("left","x").." ~1 "..discern("left","z").." "..data.id.." "..data.dmg)
  105.   elseif nSlot == 2 then
  106.     local data = draw.getSlot(nSlot)
  107.     if not data then data = {id = "minecraft:air", dmg = 0} end
  108.     commands.exec("setblock "..middle("x").." ~1 "..middle("z").." "..data.id.." "..data.dmg)
  109.   elseif nSlot == 3 then
  110.     local data = draw.getSlot(nSlot)
  111.     if not data then data = {id = "minecraft:air", dmg = 0} end
  112.     commands.exec("setblock "..discern("right","x").." ~1 "..discern("right","z").." "..data.id.." "..data.dmg)
  113.   elseif nSlot == 4 then
  114.     local data = draw.getSlot(nSlot)
  115.     if not data then data = {id = "minecraft:air", dmg = 0} end
  116.     commands.exec("setblock "..discern("left","x").." ~ "..discern("left","z").." "..data.id.." "..data.dmg)
  117.   elseif nSlot == 5 then
  118.     local data = draw.getSlot(nSlot)
  119.     if not data then data = {id = "minecraft:air", dmg = 0} end
  120.     commands.exec("setblock "..middle("x").." ~ "..middle("z").." "..data.id.." "..data.dmg)
  121.   elseif nSlot == 6 then
  122.     local data = draw.getSlot(nSlot)
  123.     if not data then data = {id = "minecraft:air", dmg = 0} end
  124.     commands.exec("setblock "..discern("right","x").." ~ "..discern("right","z").." "..data.id.." "..data.dmg)
  125.   elseif nSlot == 7 then
  126.     local data = draw.getSlot(nSlot)
  127.     if not data then data = {id = "minecraft:air", dmg = 0} end
  128.     commands.exec("setblock "..discern("left","x").." ~-1 "..discern("left","z").." "..data.id.." "..data.dmg)
  129.   elseif nSlot == 8 then
  130.     local data = draw.getSlot(nSlot)
  131.     if not data then data = {id = "minecraft:air", dmg = 0} end
  132.     commands.exec("setblock "..middle("x").." ~-1 "..middle("z").." "..data.id.." "..data.dmg)
  133.   elseif nSlot == 9 then
  134.     local data = draw.getSlot(nSlot)
  135.     if not data then data = {id = "minecraft:air", dmg = 0} end
  136.     commands.exec("setblock "..discern("right","x").." ~-1 "..discern("right","z").." "..data.id.." "..data.dmg)
  137.   end
  138. end
  139.  
  140. while true do
  141.   os.pullEvent("slot_click")
  142.   for i=1,9 do
  143.     drawSlot(i)
  144.   end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement