- end
- end
- for x = -1,1 do
- for y = -1,1 do
- for z = -1,1 do
- if not vector.equals(vector.new(0,0,0),vector.new(x,y,z)) then
- local pos2 = vector.add(pos,vector.new(x,y,z))
- local power = minetest.registered_nodes[minetest.get_node(pos2).name].power
- if power then
- if power < oldpower then
- if not torch == true then
- if minetest.get_node_group(minetest.get_node(pos).name, "redstone_dust") > 0 then
- minetest.set_node(pos,{name="redstone:dust_0"})
- end
+ return(boundary)
+end
+
+
+
+
+--make all power sources push power out
+local pos
+local node
+local power
+local boundary
+local function calculate(pos,is_capacitor)
+ if not is_capacitor then
+ boundary = create_boundary_box(pos)
+ --pathfind through memory map
+ for x,index_x in pairs(boundary) do
+ for y,index_y in pairs(index_x) do
+ for z,data in pairs(index_y) do
+ --allow data values for torches
+ if data.torch and not data.torch_directional then
+ redstone_pathfinder(new_vec(x,y,z),data.torch,boundary)
+ boundary[x][y][z] = nil
+ elseif data.torch_directional then
+ redstone_pathfinder(new_vec(x,y,z),data.torch,boundary,data.output)
+ end
+ end
+ end
+ end
+ --reassemble the table into a position list minetest can understand
+ --run through and set dust
+ for x,datax in pairs(boundary) do
+ for y,datay in pairs(datax) do
+ for z,data in pairs(datay) do
+ if data.dust and data.dust ~= data.origin then
+ swap_node(new_vec(x,y,z),{name="redstone:dust_"..data.dust})
+ end
+ --write data back to memory pool
+ pool[x][y][z] = data
+
+ if data.dust then
+ --delete the data to speed up next loop
+ boundary[x][y][z] = nil
+ end
+ end
+ end
+ end
+
+
+ --this must be done after the memory is written
+ for x,datax in pairs(boundary) do
+ for y,datay in pairs(datax) do
+ for z,data in pairs(datay) do
+ if data.directional_activator then
+ directional_activator(new_vec(x,y,z))
+ elseif data.activator then
+ non_directional_activator(new_vec(x,y,z))