Advertisement
osmarks

Þoŧaŧopłex

Aug 16th, 2018
3,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.25 KB | None | 0 0
  1. -- POTATOPLEX: The best potatOS feature
  2.  
  3. local args = {...}
  4. local targs = table.concat(args, " ")
  5. local text
  6.  
  7. if args[1] and fs.exists(args[1]) then
  8.     local f = fs.open(args[1], "r")
  9.     text = f.readAll()
  10.     f.close()
  11. end
  12.  
  13. local function randpick(l)
  14.     if #l == 1 then return l[1] end
  15.     return l[math.random(1, #l)]
  16. end
  17.  
  18. local function potatoplex_is_installed()
  19.     if fs.isDir "startup" then return false end
  20.     local f = fs.open("startup", "r")
  21.     if not f then return false end
  22.     return f.readAll():match "POTATOPLEX"
  23. end
  24.  
  25. if commands then
  26.     print "Enabling Command Potatoplex mode. Do not attempt to resist."
  27.     _G.os.pullEvent = coroutine.yield
  28.    
  29.     if not potatoplex_is_installed() then
  30.         print "Installing as startup"
  31.         settings.set("shell.allow_startup", true)
  32.         settings.set("shell.allow_disk_startup", false)
  33.         settings.save ".settings"
  34.         if fs.exists "startup" then fs.delete "startup" end
  35.         local f = fs.open("startup", "w")
  36.         f.write([[
  37. -- POTATOPLEX!!!!!
  38. _G.os.pullEvent = coroutine.yield
  39. local h = http.get "https://pastebin.com/raw/wYBZjQhN"
  40. local t = h.readAll()
  41. h.close()
  42. local fn, err = load(t, "=potatoplex")
  43. if not fn then error(err)
  44. else fn() end
  45.         ]])
  46.     end
  47.  
  48.     local items = {
  49.         "minecraft:diamond_block",
  50.         "minecraft:emerald_block",
  51.         "minecraft:redstone_block",
  52.         "minecraft:lapis_block",
  53.         "minecraft:iron_block",
  54.         "minecraft:gold_block",
  55.         "minecraft:command_block",
  56.         "computronics:oc_special_parts",
  57.         "opencomputers:casecreative",
  58.         {"opencomputers:material", 25},
  59.         {"opencomputers:material", 22},
  60.         {"opencomputers:material", 19},
  61.         {"opencomputers:component", 19},
  62.         {"opencomputers:component", 18},
  63.         {"opencomputers:component", 12},
  64.         {"opencomputers:component", 32},
  65.         {"opencomputers:card", 0},
  66.         {"plethora:module", 7},
  67.         {"plethora:module", 1},
  68.         "bibliocraft:bookcasecreative",
  69.         "minecraft:nether_star",
  70.         "quark:pirate_hat"
  71.     }
  72.  
  73.     local baseblocks = {
  74.         "minecraft:wool",
  75.         "minecraft:concrete",
  76.         "minecraft:concrete_powder",
  77.         "chisel:antiblock",
  78.         "chisel:energizedvoidstone",
  79.         "chisel:voidstonerunic",
  80.         "chisel:voidstone",
  81.         "minecraft:end_portal",
  82.         "quark:stained_clay_tiles",
  83.         "quark:stained_planks",
  84.         "quark:quilted_wool",
  85.         "quark:cavecrystal",
  86.         "minecraft:stained_hardened_clay",
  87.         "minecraft:stained_glass",
  88.         "minecraft:stained_glass_pane",
  89.         {"minecraft:white_glazed_terracotta", 0},
  90.         {"minecraft:orange_glazed_terracotta", 0},
  91.         {"minecraft:magneta_glazed_terracotta", 0},
  92.         {"minecraft:light_blue_glazed_terracotta", 0},
  93.         {"minecraft:yellow_glazed_terracotta", 0},
  94.         {"minecraft:lime_glazed_terracotta", 0},   
  95.         {"minecraft:pink_glazed_terracotta", 0},
  96.         {"minecraft:gray_glazed_terracotta", 0},
  97.         {"minecraft:silver_glazed_terracotta", 0},
  98.         {"minecraft:cyan_glazed_terracotta", 0},
  99.         {"minecraft:purple_glazed_terracotta", 0},
  100.         {"minecraft:blue_glazed_terracotta", 0},
  101.         {"minecraft:brown_glazed_terracotta", 0},
  102.         {"minecraft:green_glazed_terracotta", 0},
  103.         {"minecraft:red_glazed_terracotta", 0},
  104.         {"minecraft:black_glazed_terracotta", 0},
  105.         {"minecraft:bedrock", 0},
  106.         {"minecraft:diamond_block", 0},
  107.         {"minecraft:emerald_block", 0},
  108.         {"minecraft:redstone_block", 0},
  109.         {"minecraft:lapis_block", 0},
  110.         {"minecraft:iron_block", 0},
  111.         {"minecraft:gold_block", 0}
  112.     }
  113.  
  114.     local blocks = {}
  115.     for _, b in pairs(baseblocks) do
  116.         if type(b) == "table" then table.insert(blocks, b)
  117.         else
  118.             for i = 0, 15 do
  119.                 table.insert(blocks, {b, i})
  120.             end
  121.         end
  122.     end
  123.  
  124.     local x, y, z = commands.getBlockPosition()
  125.     local cx, cz = math.floor(x / 16) * 16, math.floor(z / 16) * 16
  126.    
  127.     local give_items = not targs:match "scrooge"
  128.  
  129.     while true do
  130.         for i = 1, 8 do
  131.             local rx, ry, rz = math.random(cx, cx + 15), math.random(0, 255), math.random(cz, cz + 15)
  132.             local pick = randpick(blocks)
  133.             local meta, block = pick[2], pick[1]
  134.             if rx ~= x and ry ~= y and rz ~= z then
  135.                 commands.execAsync(("setblock %d %d %d %s %d replace"):format(rx, ry, rz, block, meta))
  136.             end
  137.         end
  138.         if give_items and math.random(0, 1000) == 42 then
  139.             print "POTATO FESTIVAL!"
  140.             for i = 1, 36 do
  141.                 local pick = randpick(items)
  142.                 local meta = 0
  143.                 local item = pick
  144.                 if type(pick) == "table" then meta = pick[2] item = pick[1] end
  145.                 commands.execAsync(("give @a %s 64 %d"):format(item, meta))
  146.             end
  147.         end
  148.         sleep()
  149.     end
  150. end
  151.  
  152. local monitors = {peripheral.find "monitor"}
  153. local signs = {peripheral.find "minecraft:sign"}
  154. table.insert(monitors, term.current())
  155.  
  156. local duochrome_mode = targs:find "duochrome" ~= nil
  157. local function random_color()
  158.     if duochrome_mode then
  159.         if math.random(0, 1) == 0 then return colors.black
  160.         else return colors.white end
  161.     end
  162.     return math.pow(2, math.random(0, 15))
  163. end
  164.  
  165. local function random_segment(text)
  166.     local start = math.random(1, #text)
  167.     return text:sub(start, math.random(start, #text))
  168. end
  169.  
  170. local sixel_mode = targs:find "sixel" ~= nil
  171. local min, max = 0, 255
  172. if sixel_mode then
  173.     min, max = 128, 159
  174. end
  175.  
  176. local function random_char()
  177.     return string.char(math.random(min, max))
  178. end
  179.  
  180. local colors = {}
  181. for i = 0, 15 do table.insert(colors, ("%x"):format(i)) end
  182.  
  183. local function random_pick(list)
  184.     return list[math.random(1, #list)]
  185. end
  186.  
  187. local function one_pixel(m, x, y)
  188.     m.setCursorPos(x, y)
  189.     if text then
  190.         m.setBackgroundColor(random_color())
  191.         m.setTextColor(random_color())
  192.         m.write(random_segment(text))
  193.     else   
  194.         m.blit(random_char(), random_pick(colors), random_pick(colors))
  195.     end
  196. end
  197.  
  198. local chat_colors = {
  199.     "k",
  200.     "l",
  201.     "m",
  202.     "n",
  203.     "o"
  204. }
  205. for i = 0, 16 do table.insert(chat_colors, string.format("%x", i)) end
  206.  
  207. local hook = _G.potatoplex_hook
  208.  
  209. local slowpalette_mode = targs:find "slowpalette" ~= nil
  210. local function run(m)
  211.     local w, h = m.getSize()
  212.  
  213.     for i = 1, 16 do
  214.         local x, y = math.random(1, w), math.random(1, h)
  215.         one_pixel(m, x, y)
  216.     end
  217.     if not slowpalette_mode or math.random(0, 20) == 13 then
  218.         m.setPaletteColor(random_color(), math.random(), math.random(), math.random())
  219.     end
  220.     if hook then hook(m) end
  221. end
  222.  
  223. for k, v in pairs(monitors) do if v.setTextScale then v.setTextScale(1) end end
  224.  
  225. local function line()
  226.     local out = "\167" .. random_pick(chat_colors)
  227.     for i = 1, 32 do
  228.         out = out .. random_char()
  229.     end
  230.     return out
  231. end
  232.  
  233. while true do
  234.     for k, v in pairs(monitors) do
  235.         pcall(run, v)
  236.         sleep(0)
  237.     end
  238.     for k, v in pairs(signs) do
  239.         pcall(v.setSignText, line(), line(), line(), line())
  240.         sleep()
  241.     end
  242. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement