Change over redstone torcher (don't work), change hopper-comparator interaction again, start working on dig/place node handlers (doesn't work yet)

This commit is contained in:
teknomunk 2024-04-15 11:44:36 +00:00
parent 934f94043a
commit 8c918c703b
5 changed files with 50 additions and 15 deletions

View File

@ -33,6 +33,7 @@ local POSSIBLE_COMPARATOR_POSITIONS = {
}
-- update comparator state, if needed
local function update_self(pos, node)
print("Updating comparator at "..vector.to_string(pos))
node = node or minetest.get_node(pos)
local nodedef = minetest.registered_nodes[node.name]
@ -50,12 +51,14 @@ local function update_self(pos, node)
local power_level = 0
if back_nodedef and back_nodedef._mcl_comparators_get_reading then
power_level = back_nodedef._mcl_comparators_get_reading(back_pos)
else
power_level = vl_redstone.get_power(back_pos)
end
-- Get the maximum side power level
local side_power_level = 0
for i=2,3 do
local pl = vl_redstone.get_power_level(vector.add(pos,input_rules[i]))
local pl = vl_redstone.get_power(vector.add(pos,input_rules[i]))
if pl > side_power_level then
side_power_level = pl
end

View File

@ -71,7 +71,7 @@ local function torch_action_on(pos, node)
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off", param2=node.param2})
end
mesecon.receptor_off(pos, torch_get_output_rules(node))
vl_redstone.set_power(pos, 0, 2)
elseif node.name == "mesecons_torch:mesecon_torch_on_wall" then
overheat = mesecon.do_overheat(pos)
if overheat then
@ -79,7 +79,7 @@ local function torch_action_on(pos, node)
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_off_wall", param2=node.param2})
end
mesecon.receptor_off(pos, torch_get_output_rules(node))
vl_redstone.set_power(pos, 0, 2)
end
if overheat then
torch_overheated(pos)
@ -94,7 +94,7 @@ local function torch_action_off(pos, node)
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated", param2=node.param2})
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on", param2=node.param2})
mesecon.receptor_on(pos, torch_get_output_rules(node))
vl_redstone.set_power(pos, 15, 2)
end
elseif node.name == "mesecons_torch:mesecon_torch_off_wall" or node.name == "mesecons_torch:mesecon_torch_overheated_wall" then
overheat = mesecon.do_overheat(pos)
@ -102,7 +102,7 @@ local function torch_action_off(pos, node)
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_overheated_wall", param2=node.param2})
else
minetest.swap_node(pos, {name="mesecons_torch:mesecon_torch_on_wall", param2=node.param2})
mesecon.receptor_on(pos, torch_get_output_rules(node))
vl_redstone.set_power(pos, 15, 2)
end
end
if overheat then

View File

@ -1,3 +1,3 @@
name = mesecons_torch
depends = mesecons, mcl_torches
depends = mesecons, mcl_torches, vl_redstone
optional_depends = doc

View File

@ -23,10 +23,10 @@ local REDSTONE_POWER_META_SOURCE = REDSTONE_POWER_META.."."
local multipower_cache = {}
local function get_node_multipower_data(pos)
local function get_node_multipower_data(pos, no_create)
local hash = minetest_hash_node_pos(pos)
local node_multipower = multipower_cache[hash]
if not node_multipower then
if not node_multipower and not no_create then
local meta = minetest_get_meta(pos)
node_multipower = minetest_deserialize(meta:get_string("vl_redstone.multipower")) or {sources={}}
multipower_cache[hash] = node_multipower
@ -236,7 +236,13 @@ vl_scheduler.register_function("vl_redstone:flow_power",function(task, source_po
end)
function vl_redstone.set_power(pos, strength, delay)
local node_multipower = get_node_multipower_data(pos)
-- Get existing multipower data, but don't create the data if the strength is zero
local no_create
if strength == 0 then no_create = true end
local node_multipower = get_node_multipower_data(pos, no_create)
if not node_multipower then return end
-- Determine how far we need to trace conductors
local distance = node_multipower.drive_strength or 0
-- Don't perform an update if the power level is the same as before
@ -253,11 +259,33 @@ function vl_redstone.set_power(pos, strength, delay)
vl_scheduler.add_task(delay or 0, "vl_redstone:flow_power", 2, {pos, strength, distance + 1})
end
function vl_redstone.get_power_level(pos)
function vl_redstone.get_power(pos)
local node_multipower = get_node_multipower_data(pos)
return node_multipower.strength or 0
end
function vl_redstone.on_placenode(pos, node)
local nodedef = minetest.registered_nodes[node.name]
if not nodedef then return end
if not nodedef.mesecons then return end
local receptor = nodedef.mesecons.receptor
if not receptor then return end
if receptor.state == mesecon.state.on then
vl_redstone.set_power(pos, 15)
else
vl_redstone.set_power(pos, 0)
end
end
function vl_redstone.on_dignode(pos, node)
print("Dug node at "..vector.to_string(pos))
-- Node was dug, can't power anything
-- This doesn't work because the node is gone and we don't know what we were powering
-- TODO: get the rules here and use that for the first step
vl_redstone.set_power(pos, 0)
end
-- Persist multipower data
minetest.register_on_shutdown(function()
for pos_hash,node_multipower in pairs(multipower_cache) do
@ -266,3 +294,6 @@ minetest.register_on_shutdown(function()
meta:set_string("vl_redstone.multipower", minetest_serialize(node_multipower))
end
end)
minetest.register_on_placenode(vl_redstone.on_placenode)
minetest.register_on_dignode(vl_redstone.on_dignode)

View File

@ -188,6 +188,11 @@ local function hopper_pull_from_mc(mc_ent, dest_pos, inv_size)
end
mcl_hoppers.pull_from_minecart = hopper_pull_from_mc
local function get_reading(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return mcl_comparators.read_inventory(inv, "main")
end
-- Downwards hopper (base definition)
@ -337,11 +342,7 @@ local def_hopper = {
return true
end,
_mcl_comparators_get_reading = function (pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return mcl_comparators.read_inventory(inv, "main")
end,
_mcl_comparators_get_reading = get_reading,
sounds = mcl_sounds.node_sound_metal_defaults(),
_mcl_blast_resistance = 4.8,