-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarmutils.lua
More file actions
88 lines (79 loc) · 2.33 KB
/
farmutils.lua
File metadata and controls
88 lines (79 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
local function CalculateDelta(scan)
delta = math.abs(scan["crop:growth"] - sampleStats[1]) +
math.abs(scan["crop:gain"] - sampleStats[2]) +
math.abs(scan["crop:resistance"] - sampleStats[3])
return delta
end
local function IsDelta(i, j)
if tonumber(field[i][j]) ~= nil then return true else return false end
end
local function Panic()
print("Removing empty crop sticks")
for j = 1, fieldLength do
for i = 1, fieldLength do
if field[i][j] == "sticks" then
nav.MoveTo(i, j)
r.swing(0)
end
end
end
os.exit()
end
local function IsValidPlaceSticks(i, j)
if field[i][j] ~= "empty" then return false end
count = 0
if i > 1 and IsDelta(i - 1 , j) then count = count + 1 end
if i < fieldLength and IsDelta(i + 1, j) then count = count + 1 end
if j > 1 and IsDelta(i , j - 1) then count = count + 1 end
if j < fieldLength and IsDelta(i, j + 1) then count = count + 1 end
if count >= 2 then return true else return false end
end
local function CalculateAvgDelta()
sum = 0
for j = 1, fieldLength do
for i = 1, fieldLength do
if IsDelta(i, j) then sum = sum + field[i][j] end
end
end
avgDelta = sum / plantCount
print("New average delta: " .. avgDelta)
end
local function AnotherSeedbag()
inv.Equip("spade")
r.use(0)
inv.Equip("sticks")
r.use(0)
inv.DropToChest()
end
local function PlaceSticks()
inv.Equip("sticks")
r.use(0)
sticksCount = sticksCount - 1
end
local function RemoveWeed()
inv.Equip("spade")
r.use(0)
PlaceSticks()
end
local function AnalyzeScan(scan)
if scan == nil then return "sticks"
elseif scan.name == "minecraft:air" then return "empty"
elseif scan.name == "IC2:blockCrop" then
if scan["crop:name"] == "weed" then return "weed" end
if plantName == "?" then plantName = scan["crop:name"] end
if scan["crop:name"] == plantName then return CalculateDelta(scan)
else return "seedbag" end
else return "unknown" end
end
farmutils = {
AnalyzeScan = AnalyzeScan,
IsDelta = IsDelta,
CalculateDelta = CalculateDelta,
CalculateAvgDelta = CalculateAvgDelta,
IsValidPlaceSticks = IsValidPlaceSticks,
RemoveWeed = RemoveWeed,
PlaceSticks = PlaceSticks,
AnotherSeedbag = AnotherSeedbag,
Panic = Panic
}
return farmutils