View difference between Paste ID: YVmeAnju and HK4R0bF4
SHOW: | | - or go back to the newest paste.
1-
local chest = peripheral.wrap("right")
1+
local chest = peripheral.wrap("back")
2
local oreExt = peripheral.wrap("extractor_6") 	-- ore extractor
3
local dustExt = peripheral.wrap("extractor_7") -- dust extractor
4
5-
chest.condenseItems()
5+
6
local oresDir = "south"
7
local dustsDir = "north"
8
local redOre = "left"
9
local redDust = "right"
10
local sentOres = 0
11
local sentDusts = 0
12
13
14
15
local oArray = {"15:0", --iron ore
16-
--pulled = chest.pullItemIntoSlot("west", 1, 64, 1)
16+
17-
--pushed = chest.pushItemIntoSlot("west", 1, 64, 1)
17+
18-
--print(pushed)
18+
19
local dArray = 	{"30888:1", --iron dust
20
                     "30888:9", --iron slurry
21
                     "30888:2", --gold dust
22
                     "30888:10"}
23
print("size is: " .. size)
24
25
--see if item is extractable
26
function isOre(ore)                                          
27
    for k,v in pairs(oArray) do
28
      if (ore == v) then
29
        return true
30
      end
31
    end
32
    return false
33
end
34
35
function isDust(dust)                                    
36
    for x,y in pairs(dArray) do
37
      if (dust == y) then
38
        return true
39
      end
40
    end
41-
for i=1,size do
41+
42-
  print (i)
42+
43-
  local id = chest.getStackInSlot(i)
43+
44-
  if (id ~= nil) then
44+
45-
    local combID = tostring(id["id"])..":"..tostring(id["dmg"])
45+
46-
    --print (combID)
46+
47-
    --print (type(combID))
47+
function sendStuff()
48-
 	  if (isOre(combID)) then
48+
	sentOres = 0
49-
	     --print(id["name"])
49+
	sentDusts = 0
50-
	     chest.pushItem(oresDir,i,64)
50+
    chest.condenseItems()
51-
    elseif (isDust(combID)) then
51+
  for i=1,size do
52-
  	   --print(id["name"])
52+
  		  --print (i)
53-
  	   chest.pushItem(dustsDir,i,64)
53+
  		  local id = chest.getStackInSlot(i)
54-
  	 end
54+
      if (id ~= nil) then
55-
  
55+
    			 local combID = tostring(id["id"])..":"..tostring(id["dmg"])
56
    			 --print (combID)
57
			     --print (type(combID))
58
  			     if (isOre(combID)) then
59
			    	  --print(id["name"])
60
				      sentOres = sentOres + chest.pushItem(oresDir,i,64)
61
					  if (sentOres > 0) then
62
						rs.setOutput(redOre, true)
63
					  end	
64
      		     elseif (isDust(combID)) then
65
      				--print(id["name"])
66
      				sentDusts = sentOres + chest.pushItem(dustsDir,i,64)
67
					if (sentDusts > 0) then
68
						rs.setOutput(redDust, true)
69
					end	
70
    			 end
71
		
72
73
       end
74
    end
75
	print (tostring(sentOres) .. "and" .. tostring(sentDusts))
76
		
77
  end
78
79
function pullOres(slot)
80
	oreExt.pushItem(dustsDir, slot, 64)
81
end
82
function pullDusts(slot)
83
	dustExt.pushItem(oresDir, slot, 64)
84
end
85
86
function oreSlot(nr)
87
	if (oreExt.getStackInSlot(nr) ~= nil) then
88
		return false
89
	else
90
		return true
91
	end
92
end
93
94
function dustSlot(nr)
95
	if (dustExt.getStackInSlot(nr) ~= nil) then
96
		return false
97
	else 
98
		return true
99
	end
100
end
101
102
function dustQ(nr)
103
	local var = dustExt.getStackInSlot(nr)
104
	if (var ~= nil) then
105
		if (var["qty"] > 62) then
106
			return true
107
		end
108
	else
109
		return false
110
	end
111
	return false
112
end
113
114
function oreQ(nr)
115
	local var = oreExt.getStackInSlot(nr)
116
	if (var ~= nil) then
117
		if (var["qty"] > 62) then
118
			return true
119
		
120
		else
121
			return false
122
		end
123
	end
124
	return false
125
end
126
127
128
while true do
129
	if (oreSlot(1) and oreSlot(7)) then
130
		rs.setOutput(redOre, false)
131
		sendStuff()
132
		print("1")
133
		--pullOres(2)
134
		--pullOres(8)
135
	--elseif (oreSlot(1) or oreSlot(7)) then
136
		--sendStuff()
137
		--pullOres(2)
138
		--print("2")
139
		--pullOres(8)
140
	end
141
	if (oreQ(2)) then
142
		--rs.setOutput("back", false)
143
		pullOres(2)
144
		print("3")
145
		--rs.setOutput("back", true)
146
	elseif  (oreQ(8)) then
147
		pullOres(8)
148
		print("4")
149
	end
150
151
	if (dustSlot(3) and dustSlot(5)) then
152
		rs.setOutput(redDust, false)
153
		sendStuff()
154
		print("5")
155
	--elseif (dustSlot(3) or dustSlot(5)) then
156
		--sendStuff()
157
		--pullDusts(4)
158
		--pulldusts(6)
159
		--print("6")
160
	end
161
	if (dustQ(4)) then
162
		pullDusts(4)
163
		print("7")
164
	elseif (dustQ(6)) then
165
		pulldusts(6)
166
		print("8")
167
	end
168
end