]> git.lizzy.rs Git - Crafter.git/commitdiff
Only index node once in redstone update
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 27 Jun 2020 04:53:59 +0000 (00:53 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 27 Jun 2020 04:53:59 +0000 (00:53 -0400)
mods/redstone/init.lua

index cb0345a54a2c3770a43456167048d16714fa65c5..791ed19c58a64255f31f6f698d57ef13adddb92c 100644 (file)
@@ -120,22 +120,16 @@ end
 
 --collect all nodes that are local to the modified
 --node of redstone dust and store in memory
-local function get_group(i,gotten_group)
-       return(get_item_group(get_node(i).name, gotten_group))
-end
-
-
 local localredstone = {}
-
+local node
 localredstone.injector = function(i,origin)
-       if get_node(i).name == "air" then
+       node = get_node(i).name
+       if node == "air" then
                return
        end
 
-       if r_index[i.x] and r_index[i.x][i.y] then
-               if r_index[i.x][i.y][i.z] then
-                       return
-               end
+       if r_index[i.x] and r_index[i.x][i.y] and r_index[i.x][i.y][i.z] then
+               return
        end
 
        if vector_distance(i,origin) > 9 then
@@ -143,7 +137,7 @@ localredstone.injector = function(i,origin)
        end
 
        --index dust
-       if get_group(i,"redstone_dust") > 0 then
+       if get_item_group(node,"redstone_dust") > 0 then
                if vector_distance(i,origin) <= 8 then
                        --add data to both maps
                        if not r_index[i.x] then r_index[i.x] = {} end
@@ -152,7 +146,7 @@ localredstone.injector = function(i,origin)
 
                        if not check_table[i.x] then check_table[i.x] = {} end
                        if not check_table[i.x][i.y] then check_table[i.x][i.y] = {} end
-                       check_table[i.x][i.y][i.z] = get_group(i,"redstone_power")
+                       check_table[i.x][i.y][i.z] = get_item_group(node,"redstone_power")
                        
                        --the data to the 3d array must be written to memory before this is executed
                        --or a stack overflow occurs!!!
@@ -161,26 +155,26 @@ localredstone.injector = function(i,origin)
                else
                        if not r_index[i.x] then r_index[i.x] = {} end
                        if not r_index[i.x][i.y] then r_index[i.x][i.y] = {} end
-                       r_index[i.x][i.y][i.z] = {torch = true,power=get_group(i,"redstone_power")}
+                       r_index[i.x][i.y][i.z] = {torch = true,power=get_item_group(node,"redstone_power")}
                end
        end
        --index power sources
-       if get_group(i,"redstone_torch") > 0 then
+       if get_item_group(node,"redstone_torch") > 0 then
                if not r_index[i.x] then r_index[i.x] = {} end
                if not r_index[i.x][i.y] then r_index[i.x][i.y] = {} end
-               r_index[i.x][i.y][i.z] = {torch = true,power=get_group(i,"redstone_power")}
+               r_index[i.x][i.y][i.z] = {torch = true,power=get_item_group(node,"redstone_power")}
        end     
        --index directional power sources (Like repeaters/comparators)
        --only outputs forwards
-       if get_group(i,"torch_directional") > 0 then
+       if get_item_group(node,"torch_directional") > 0 then
                if not r_index[i.x] then r_index[i.x] = {} end
                if not r_index[i.x][i.y] then r_index[i.x][i.y] = {} end
-               r_index[i.x][i.y][i.z] = {torch_directional = true, dir = get_node(i).param2 , power = get_group(i,"redstone_power")}
+               r_index[i.x][i.y][i.z] = {torch_directional = true, dir = get_node(i).param2 , power = get_item_group(node,"redstone_power")}
        end
        
        --index directional activators (Like repeaters/comparators)
        --only accepts input from the back
-       if get_group(i,"redstone_activation_directional") > 0 then
+       if get_item_group(node,"redstone_activation_directional") > 0 then
                --print("indexing directional")
                if not a_index[i.x] then a_index[i.x] = {} end
                if not a_index[i.x][i.y] then a_index[i.x][i.y] = {} end
@@ -191,7 +185,7 @@ localredstone.injector = function(i,origin)
        end
        
        --index objects that activate
-       if get_group(i,"redstone_activation") > 0 then
+       if get_item_group(node,"redstone_activation") > 0 then
                if not a_index[i.x] then a_index[i.x] = {} end
                if not a_index[i.x][i.y] then a_index[i.x][i.y] = {} end
                if not a_index[i.x][i.y][i.z] then a_index[i.x][i.y][i.z] = {} end