View difference between Paste ID: csv5n2Un and eF0D625V
SHOW: | | - or go back to the newest paste.
1
local component = require("component");
2
local robot_api = require("robot");
3
local computer = require("computer");
4
local sides = require("sides");
5
6
local inventory = component.inventory_controller;
7
--local robot = component.robot;
8
local geolyzer = component.geolyzer;
9
local redstone = component.redstone;
10
11
local iron_scaffold = "ic2:scaffold";
12
local foam = "ic2:foam";
13
local reinforced_stone = "ic2:resource";
14
local air = "minecraft:air";
15
local sand = "minecraft:sand";
16
17-
local iron_scaffol_inventory_number = 3 +5;
17+
local iron_scaffol_inventory_number = 3;
18-
local reinforced_stone_inventory_number = 1;
18+
local reinforced_stone_inventory_number = 5;
19-
local sand_inventory_number = 4 +5;
19+
local sand_inventory_number = 4;
20-
local bore_inventory_number = 2 +5;
20+
local bore_inventory_number = 2;
21-
local spray_inventory_number = 1 +5;
21+
local spray_inventory_number = 1;
22
23
local sand_slot = 4;
24
local scaffold_slot = 7;
25
local stone_slot = 1;
26
27
local function isBlock(name)
28
	local info_from_geolyzer = geolyzer.analyze(sides.forward);
29
    if (info_from_geolyzer.name == name) 
30
        then return true 
31
    else return false
32
	end
33
end
34
35
local function placeIronScaffold()
36
    robot_api.select(iron_scaffol_inventory_number);
37
    result_of_placing = robot_api.place();
38
	return result_of_placing;
39
end
40
    
41
local function foamTheScaffold()
42
    robot_api.select(spray_inventory_number);
43
	inventory.equip();
44
    result_of_foaming = robot_api.use();
45
    inventory.equip();
46
    return result_of_foaming;
47
end
48
49
local function useSandOnFoam()
50
    robot_api.select(sand_inventory_number);
51
    inventory.equip();
52
    result_of_sanding = robot_api.use();
53
    inventory.equip();
54
    return result_of_sanding;
55
end
56
57
local function boreTheStone()
58
    robot_api.select(bore_inventory_number);
59
	inventory.equip();
60
    result = robot_api.swing();
61
    inventory.equip();
62
    return result;
63
end
64
65
local function refuelSprayer()
66-
    print("spray_refuel");
66+
	print("refuel sprayer");
67
    robot_api.select(spray_inventory_number);
68
    inventory.dropIntoSlot(sides.up, 1);
69-
    robot_api.turnAround();
69+
	os.sleep(4);
70-
    robot_api.use();
70+
    robot_api.suckUp();
71-
    robot_api.turnAround();
71+
72
73
local function isEnergyBelow30Procent()
74
    local max_energy = computer.maxEnergy();
75
    local current_energy = computer.energy();
76
    local current_energy_in_procents = (current_energy * 100) / max_energy;
77
    return current_energy_in_procents;
78
end
79
    
80
local function chargeUp()
81
    redstone.setOutput(sides.right, 15);
82
    while (true) do
83
            os.sleep(2);
84
            if (computer.energy() >= (computer.maxEnergy()*0.9)) then break; end;
85
    end
86
    redstone.setOutput(sides.right, 0);
87
end
88
    
89
local function takeSandAndScaffoldFromExternalInventory()
90
    robot_api.select(sand_inventory_number);
91
    if (inventory.suckFromSlot(sides.down, sand_slot) == false) then print("There is no sand in external inventory!"); end;
92
    robot_api.select(iron_scaffol_inventory_number);
93-
    inventory.suckFromSlot(sides.down, sand_slot);
93+
    if (inventory.suckFromSlot(sides.down, scaffold_slot) == false) then print("There is no iron scaffold in external inventory!"); end;
94
end
95-
    inventory.suckFromSlot(sides.down, scaffold_slot); 
95+
96
local function isOutOfMaterials()
97
        robot_api.select(sand_inventory_number);
98
        local stack = inventory.getStackInInternalSlot();
99
		if (stack == nil) 
100
			then return true; 
101
			end;
102
        local size = stack.size;
103
        if (size <= 0) then return true; end;
104
        return false;
105
end
106
    
107
local function isStoneFull()
108
        robot_api.select(reinforced_stone_inventory_number);
109
		local stack = inventory.getStackInInternalSlot();
110
		if (stack == nil) 
111
			then return false; 
112
			end;
113
        local size = stack.size;
114
		print("I have ", size, " stone");
115
        if (size >= 5) then return true; end;
116-
        if (size >= 1) then return true; end;
116+
117
end
118
119
local function getRidOfStone()
120
        robot_api.select(reinforced_stone_inventory_number);
121-
  		for i=1, 8, 1
121+
        inventory.dropIntoSlot(sides.down, stone_slot, 5);
122-
    	do
122+
    	print("Get rid of stone.");
123-
        	local item = inventory.getStackInInternalSlot(i);
123+
124-
        	if (item) 
124+
125-
            then
125+
126-
            	if (item.name == reinforced_stone) 
126+
127-
                then
127+
128-
                	inventory.dropIntoSlot(sides.down, stone_slot);
128+
129-
            	end;
129+
130-
        	end;       	
130+
131-
        end;
131+
132
        if (isOutOfMaterials() == true)
133
             then takeSandAndScaffoldFromExternalInventory();
134
             end;
135
        if (isStoneFull() == true)
136
             then getRidOfStone();
137
             end;
138
        if (remaining_foam <= 40)
139
            then 
140
			   print(remaining_foam);
141
               refuelSprayer();
142
			   remaining_foam = 80;
143
            end;
144-
        
144+
145-
        if (remaining_foam <= 0)
145+
146
             end;
147-
               print(remaining_foam);
147+
148
             then 
149
                if (foamTheScaffold() == true) 
150-
               getRidOfStone();
150+
151-
               inventory.equip();
151+
152-
               getRidOfStone();
152+
153-
               inventory.equip();
153+
154
             end;
155-
        
155+
156-
        robot_api.select(iron_scaffol_inventory_number);
156+
157-
        
157+
158
        if (isBlock(reinforced_stone) == true) 
159
             then boreTheStone();
160
             end;
161
    end;
162
end;
163
164
main();
165
--refuelSprayer();
166