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"},
{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
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
--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
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
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
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
else
--redstone and torch
for _,order in pairs(order) do
+ instructions = instructions + 1
i = add_vec(pos,order)
x=i.x
y=i.y
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
end
end
]]--
+ if instructions and instructions > 0 then
+ print(instructions)
+ end
+ instructions = 0
end)
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,