Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- arguments: length width
- -- length and width of bounding fence rectangle: length width-2 length width-2
- -- starts along length with block in front of turtle and turns left after length fence blocks
- local args = {...}
- local t = turtle
- local ts = t.select
- local ic = t.getItemCount
- print("Fuel: ",t.getFuelLevel()," / ",t.getFuelLimit())
- local slotList = {}
- local function prepareRandomSlot()
- slotList = {}
- for i=1,16 do
- if ic(i) > 0 then slotList[#slotList+1] = {["slot"]=i,["qty"]=ic(i)} end
- end
- end
- prepareRandomSlot()
- local function updateRandomSlot(slot)
- local index = nil
- for i=1,#slotList do
- if slotList[i].slot == slot then
- slotList[i].qty = slotList[i].qty - 1
- index = i
- break
- end
- if index and slotList[index].qty <= 0 then table.remove(slotList,index) end
- end
- end
- local function randomSlot()
- if #slotList == 0 then return 1
- else
- return slotList[math.random(#slotList)].slot
- end
- end
- local function placeFence(slot)
- ts(slot)
- t.digDown()
- t.placeDown()
- updateRandomSlot(slot)
- end
- local length = args[1] and args[1] or 0
- local width = args[2] and args[2] or 0
- local function move()
- while t.detect() do
- t.dig()
- sleep(0.5)
- end
- t.forward()
- end
- local function go()
- local rect = {length,width-1,length-1,width-2}
- for k=1,4 do
- for i=1,rect[k] do
- move()
- placeFence(randomSlot())
- end
- t.turnLeft()
- end
- end
- go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement