View difference between Paste ID: GYQdgqP9 and xkPnRQZW
SHOW: | | - or go back to the newest paste.
1
--[[
2
Source: http://adf.ly/mQGKM
3
Authors: Lyqyd, Zaflis, Kreezxil
4
Ripped by: Kreezxil
5
Notes: Until now this code sat freely in forum, its still free, but now its encapsulated in a program that can be run and given arguments as well as loaded with 'pastebin get'
6
Changelog:
7
2/22/14 - Requested Concept by Narny123 - http://adf.ly/mQFxT
8
2/22/14 - Original Code by Lyqyd - http://adf.ly/mQG5h
9
2/28/14 - Modified Code by Zaflis - http://adf.ly/mQGD2
10
- now supports digging through gravel, and digs high enough tunnel for player to follow through
11
- added code to allow fence removal
12
5/10/14 - Modified Code by Kreezxil
13
- rearranged and encapsulated with function declarations parts of code to allow it to be in a program much easier
14
- added arguments for variable sized fence building and removing
15
- added help when arguments fail to match or nothing slot 1
16
--]]
17
18
local index = 1
19
turtle.select(1)
20
21
function place()
22
  while turtle.detectUp() do
23
    turtle.digUp()
24
  end
25
  turtle.digDown()
26
  turtle.placeDown()
27
  if turtle.getItemCount(index) == 0 then
28
    index = index + 1
29
  end
30
  if index > 16 then 
31
      index = 1 
32
  end
33
  turtle.select(index)
34
end
35
36
function removeFence(length,width)
37
    turtle.digDown()
38
	for i = 1, 4 do
39
      if i==1 or i==3 then
40
          side=length
41
      else
42
          side=width
43
      end
44
	  for j = 1, side-1 do
45
		turtle.dig()
46
		turtle.forward()
47
		turtle.digDown()
48
	  end
49
	  turtle.turnRight()
50
	end
51
end
52
53
function buildFence(length,width)
54
	place()
55
	for i = 1, 4 do
56
      if i==1 or i==3 then
57
          side=length
58
      else
59
          side=width
60
      end
61
	  for j = 1, side-1 do
62
		while turtle.detect() do
63
		  turtle.dig()
64
		end 
65
		turtle.forward()
66
		place()
67
	  end
68
	  turtle.turnRight() -- Goes clockwise
69
	end
70
end
71
72
function myName()
73
	fullName = shell.getRunningProgram()
74
	return fs.getName(fullName)
75
end
76
77
function mats()
78
  count=0
79
  for i=1,16 do
80
	count = count + turtle.getItemCount(i)
81
  end
82
  return count
83
end
84
85
function needed(length,width)
86
   return (length*2)+(width*2)
87
end
88
89
args = {...}
90
91
if #args < 3 then
92
  print("Usage:")
93
  print(" "..myName().." <length> <width> <remove|build>")
94
  print(" Turtle should also contain materials to be used as fences, preferably fences.")
95
  return
96
end
97
98
if tonumber(args[1])==nil or tonumber(args[2])==nil then
99
    print("Dimensions must be numerical.")
100
    return
101
end
102
103
if tonumber(args[1]) < 1 or tonumber(args[2]) < 1 then
104
  print("A dimension may not be less than 1")
105
  return
106
end
107
108
if mats() < needed(tonumber(args[1]),tonumber(args[2])) then
109
  print("Not enough materials in turtle to build fence, please add more materials.")
110
  return
111
end
112
113
if args[3]== "remove" then
114
  removeFence(tonumber(args[1]),tonumber(args[2]))
115
elseif args[3]=="build" then
116
  buildFence(tonumber(args[1]),tonumber(args[2]))
117
else
118
  print("The third option must be either 'remove' or 'build'")
119
end