Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local blueprint = {}
- blueprint.x = tonumber(args[1])
- blueprint.y = tonumber(args[2])
- blueprint.h = tonumber(args[3])
- blueprint.slots = {}
- blueprint.tcode = {}
- local userFile = shell.resolve(args[4])
- if fs.exists(userFile) then
- print("Error: A file by that name already exists")
- return
- end
- local bpFile = fs.open(userFile,"w")
- --returns whatever slot the block was put into
- function scan(up)
- local slotCounts = {}
- for i=1,16 do
- slotCounts[i] = turtle.getItemCount(i)
- end
- if up then
- turtle.digUp()
- else
- turtle.dig()
- end
- local slot = 0
- for i=1,16 do
- if turtle.getItemCount(i) > slotCounts[i] then
- slot = i
- end
- end
- if slot > 0 then
- --if slot hasn't been used yet
- if not blueprint.slots[slot] then
- --get item name for slot
- local item = turtle.getItemDetail(slot).name
- blueprint.slots[slot] = {name = item, count = 0}
- end
- --add 1 to the slot count
- blueprint.slots[slot].count = turtle.getItemCount(slot)
- end
- --add the slot number to the tcode
- return slot
- end
- local i = 1
- local right = true
- blueprint.tcode[i] = scan()
- i = i + 1
- turtle.forward()
- for h=1,blueprint.h do
- for y=1,blueprint.y do
- for x=1,blueprint.x - 1 do
- blueprint.tcode[i] = scan()
- turtle.forward()
- i = i + 1
- end
- if y < blueprint.y then
- if right then
- turtle.turnRight()
- blueprint.tcode[i] = scan()
- i = i + 1
- turtle.forward()
- turtle.turnRight()
- right = false
- else
- turtle.turnLeft()
- blueprint.tcode[i] = scan()
- i = i + 1
- turtle.forward()
- turtle.turnLeft()
- right = true
- end
- end
- end
- if h < blueprint.h then
- blueprint.tcode[i] = scan(true)
- i = i + 1
- turtle.turnRight()
- turtle.turnRight()
- turtle.up()
- end
- end
- local output = textutils.serialize(blueprint)
- bpFile.write(output)
- bpFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement