]> git.lizzy.rs Git - Crafter.git/commitdiff
Push all debug info
authoroilboi <47129783+oilboi@users.noreply.github.com>
Fri, 3 Jul 2020 20:15:14 +0000 (16:15 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Fri, 3 Jul 2020 20:15:14 +0000 (16:15 -0400)
mods/redstone/comparator.lua
mods/redstone/dispenser.lua [new file with mode: 0644]
mods/redstone/init.lua
mods/redstone/pressure_plate.lua

index 9d81556be90986841b22985869e30647c6b3d890..77f4403de4d227a52c79ed970cb8697f0eb149bb 100644 (file)
@@ -1,71 +1,7 @@
 local minetest,vector,math = minetest,vector,math
 
-local function comparator_logic(pos)
-       
-       local old_power = get_powered_state_directional(pos)
-       
-       local param2 = minetest.get_node(pos).param2
-       local dir = minetest.facedir_to_dir(param2)
-       local get_group = minetest.get_item_group
-       
-       --get inputs and outputs
-       local input_pos_straight = vector.subtract(pos,dir)
-       
-       --if you're reading this, this is an easy way to get 90 degrees from a direction (math.pi would be 180 degrees which you can simply -1 multiply the direction instead)
-       local input_pos_right = vector.add(minetest.yaw_to_dir(minetest.dir_to_yaw(dir)-(math.pi/2)),pos)
-       local input_pos_left = vector.add(minetest.yaw_to_dir(minetest.dir_to_yaw(dir)+(math.pi/2)),pos)
-       
-       local output_pos = vector.add(pos,dir)
-       local output = false
-       
-       local comparator_level = get_group(minetest.get_node(pos).name, "comparator")
-       
-       local input_level = get_group(minetest.get_node(input_pos_straight).name, "redstone_power")
-       local output_level = get_group(minetest.get_node(output_pos).name, "redstone_power")
-       
-       --this prefers right to left--
-       
-       local output_node = minetest.get_node(output_pos).name
-       local input_node_straight = minetest.get_node(input_pos_straight).name
-       
-       local left_level = get_group(minetest.get_node(input_pos_left).name, "redstone_power")
-       local right_level = get_group(minetest.get_node(input_pos_right).name, "redstone_power")
-       
-       local compare_level = 0
-       if right_level > compare_level then
-               compare_level = right_level
-       end
-       if left_level > compare_level then
-               compare_level = left_level
-       end     
-       local new_output_level = 0
-       
-       if input_level > compare_level then
-               new_output_level = 9
-       elseif input_level <= compare_level then
-               new_output_level = 0
-       end
-       
-       --charge
-       if input_level > 0 then--and output_level ~= new_output_level-1 then
-               if comparator_level ~= new_output_level then
-                       --print("comparator on")
-                       minetest.swap_node(pos, {name="redstone:comparator_"..new_output_level,param2=param2})
-                       redstone.collect_info(output_pos)
-               end
-       elseif output_level ~= new_output_level-1 then
-               if comparator_level ~= new_output_level then
-                       --print("comparator off")
-                       minetest.swap_node(pos, {name="redstone:comparator_"..new_output_level,param2=param2})
-                       redstone.collect_info(output_pos)
-               end
-       end
-       
-       set_old_power(pos,old_power)
-end
-
 
-for i = 0,9 do
+for i = 0,16 do
        minetest.register_node("redstone:comparator_"..i, {
                description = "Redstone Comparator",
                tiles = {"repeater_on.png"},
@@ -87,29 +23,14 @@ for i = 0,9 do
                                        {0.4, -0.5,  -0.35, 0.2,  0.1, -0.15}, --input post
                                },
                        },
-               redstone_activation = function(pos)
-                       comparator_logic(pos)
-               end,
-               redstone_deactivation = function(pos)
-                       comparator_logic(pos)
-               end,
-               redstone_update = function(pos)
-                       comparator_logic(pos)
-               end,
-               on_construct = function(pos)
-               end,
+
                after_place_node = function(pos, placer, itemstack, pointed_thing)
                        redstone.collect_info(pos)
                end,
-               on_dig = function(pos, node, digger)
-                       local param2 = minetest.get_node(pos).param2
-                       minetest.node_dig(pos, node, digger)
-                       local dir = minetest.facedir_to_dir(param2)
-                       redstone.collect_info(vector.add(pos,dir))
-               end,
-               after_destruct = function(pos)
+               on_destruct = function(pos)
                end,
        })
+
 end
 
 
diff --git a/mods/redstone/dispenser.lua b/mods/redstone/dispenser.lua
new file mode 100644 (file)
index 0000000..e69de29
index 79ffbe2fd7d2554e9cbde8a57a1ea81ab795775b..9fe5d08c8e99f8b9140cdd87771d3d3bca31e089 100644 (file)
@@ -36,11 +36,12 @@ local vec_equals      = vector.equals
 local activator_table = {} -- this holds the translation data of activator tables (activator functions)
 local capacitor_table = {}
 local player_detection_table = {}
+local instructions = 0
 
 -- redstone class
 redstone = {}
 
-redstone.max_state = 9 -- the limit to power transmission
+redstone.max_state = 64 -- the limit to power transmission
 
 redstone.player_detector_add = function(pos)
        player_detection_table[minetest.serialize(pos)] = pos
@@ -90,19 +91,22 @@ dofile(path.."/detector.lua")
 --this is written out manually so that
 --math.abs is not needed
 local order = {
-       {x=0,y=0,z=0},
-
-       {x=1, y=0, z=0}, {x=-1, y=0, z= 0},
-       {x=0, y=0, z=1}, {x= 0, y=0, z=-1},
-
-       {x=0, y=1, z=0}, {x= 0, y=-1, z=0},
-
-       {x=1, y=1, z=0}, {x=-1, y=1, z= 0},
-       {x=0, y=1, z=1}, {x= 0, y=1, z=-1},
-
-       {x=1, y=-1, z=0}, {x=-1, y=-1, z= 0},
-       {x=0, y=-1, z=1}, {x= 0, y=-1, z=-1},
-}
+       {x= 0,y= 0,z= 0},
+       {x= 1,y= 0,z= 0},
+       {x=-1,y= 0,z= 0},
+       {x= 0,y= 0,z= 1},
+       {x= 0,y= 0,z=-1},
+       {x= 0,y= 1,z= 0},
+       {x= 0,y=-1,z= 0},
+       {x= 1,y= 1,z= 0}, 
+       {x=-1,y= 1,z= 0},
+       {x= 0,y= 1,z= 1},
+       {x= 0,y= 1,z=-1},
+       {x= 1,y=-1,z= 0},
+       {x=-1,y=-1,z= 0},
+       {x= 0,y=-1,z= 1},
+       {x= 0,y=-1,z=-1},
+       }
 
 --thanks to RhodiumToad for helping me figure out a good method to do this
 
@@ -110,20 +114,27 @@ local pool = {} -- this holds all redstone data (literal 3d virtual memory map)
 
 
 local function data_injection(pos,data)
+       instructions = instructions + 1
        -- add data into 3d memory
        if data then
                if not pool[pos.x] then pool[pos.x] = {} end
                if not pool[pos.x][pos.y] then pool[pos.x][pos.y] = {} end
                pool[pos.x][pos.y][pos.z] = data
+               instructions = instructions + 1
+               --print("building 3d memory")
        --delete data from 3d memory
        else
                if pool and pool[pos.x] and pool[pos.x][pos.y] then
                        pool[pos.x][pos.y][pos.z] = data
+                       instructions = instructions + 1
+                       --print("deleting 3d memory")
                        if pool[pos.x][pos.y] and not next(pool[pos.x][pos.y]) then
                                pool[pos.x][pos.y] = nil
+                               instructions = instructions + 1
                                -- only run this if y axis is empty
                                if pool[pos.x] and not next(pool[pos.x]) then
                                        pool[pos.x] = nil
+                                       instructions = instructions + 1
                                end
                        end
                end
@@ -158,13 +169,18 @@ local table_3d
 local temp_pool
 local r_max = redstone.max_state
 local function create_boundary_box(pos)
+       instructions = instructions + 1
        table_3d = {}
        for x = pos.x-r_max,pos.x+r_max do
+               instructions = instructions + 1
                if pool[x] then
                        for y = pos.y-r_max,pos.y+r_max do
+                               instructions = instructions + 1
                                if pool[x][y] then
                                        for z = pos.z-r_max,pos.z+r_max do
+                                               instructions = instructions + 1
                                                temp_pool = pool[x][y][z]
+                                               instructions = instructions + 1
                                                if temp_pool then
                                                        if not table_3d[x] then table_3d[x] = {} end
                                                        if not table_3d[x][y] then table_3d[x][y] = {} end
@@ -194,7 +210,7 @@ local i
 local index
 local function capacitor_pathfind(source,mem_map)
        for _,order in pairs(order) do
-
+               
                i = add_vec(source,order)
                if not mem_map[i.x] then mem_map[i.x] = {} end
                if not mem_map[i.x][i.y] then mem_map[i.x][i.y] = {} end
@@ -364,6 +380,7 @@ local function redstone_distribute(pos,power,mem_map,output)
        else
                --redstone and torch
                for _,order in pairs(order) do
+                       instructions = instructions + 1
                        i = add_vec(pos,order)
                        x=i.x
                        y=i.y
@@ -410,6 +427,7 @@ local function dust_sniff(pos,mem_map,boundary,single,origin,ignore)
        if not single then
                --print("all position index--")
                for _,order in pairs(order) do
+                       instructions = instructions + 1
                        i = add_vec(pos,order)
 
                        if not mem_map[i.x] then mem_map[i.x] = {} end
@@ -730,6 +748,10 @@ minetest.register_globalstep(function(dtime)
                end
        end
        ]]--
+       if instructions and instructions > 0 then
+               print(instructions)
+       end
+       instructions = 0
 end)
 
 
@@ -823,8 +845,7 @@ for i = 0,d_max do
                        data_injection(pos,{dust=i})
                        calculate(pos)
                end,
-               after_destruct = function(pos)
-                       print("test")
+               after_destruct = function(pos)                  
                        data_injection(pos,nil)
                        calculate(pos)
                end,
index 5def16f1b05a215a13908fad2d8dc812fde11e0f..078fa0ef59006b0d085d32177ad92530d2ce04c4 100644 (file)
@@ -1,6 +1,6 @@
 local minetest,ipairs,vector = minetest,ipairs,vector
 
-r_max
+
 
 for level = 0,9 do
 local subtracter = 0