ComputerCraft Archive

Replicator

computer operating-system unknown forum

Description

Self-replicating ComputerCraft Turtle

Installation

Copy one of these commands into your ComputerCraft terminal:

Pastebin:pastebin get 3fnFhwvd replicator
wget:wget https://pastebin.com/raw/3fnFhwvd replicator
Archive:wget https://cc.shobie.xyz/cc/get/pb-3fnFhwvd replicator
Quick Install: wget https://cc.shobie.xyz/cc/get/pb-3fnFhwvd Replicator

Usage

Run the program after downloading

Tags

forumturtle-programs

Source

View Original Source

Code Preview

-- Self-replicating ComputerCraft Turtle
-- https://github.com/jnordberg/minecraft-replicator

local function fetchUrl(url)
  local valid, err = http.checkURL(url)
  if not valid then
    error('Invalid URL: ' .. err)
  end
  local h = http.get(url)
  if h == nil then
    error('Unknown error when fetching: ' .. url)
  end
  if h.getResponseCode() ~= 200 then
    error('Unexpected response from server')
  end
  local rv = h.readAll()
  h.close()
  return rv
end

local function wget(url, filename)
  local data = fetchUrl(url)
  if fs.exists(filename) then
    fs.delete(filename)
  end
  local h = fs.open(filename, 'w')
  h.write(data)
  h.close()
end

local sourceUrl = 'https://raw.githubusercontent.com/jnordberg/minecraft-replicator/master/'

local sourceFiles = {
  'bootstrap',
  'lib/class.lua',
  'lib/items.lua',
  'lib/serpent.lua',
  'lib/utils.lua',
  'replicator',
}

term.clear()
term.setCursorPos(3, 2)
term.write('Installing')

fs.makeDir('lib')
fs.makeDir('state')

for i,file in ipairs(sourceFiles) do
  term.write('.')
  wget(sourceUrl .. file, file)
end

shell.run('replicator')