comparator read from item_frame

This commit is contained in:
Henry Behrendt 2021-10-09 22:09:34 +02:00
parent 1227b6e1f1
commit 91cfb10097
1 changed files with 33 additions and 48 deletions

View File

@ -70,7 +70,6 @@ local function container_inventory_nonempty(pos, rule)
-- fullness of a slot = number of items in slot / max stack size for this type of item
local invnode = minetest.get_node(pos)
local invnodedef = minetest.registered_nodes[invnode.name]
-- Ignore stale nodes
if not invnodedef then return 0, false end
@ -90,52 +89,46 @@ local function container_inventory_nonempty(pos, rule)
end
local inv = minetest.get_inventory({type="node", pos=pos})
if not inv then return 0, false end
if (not inv) or inv:is_empty("main") then return 0, false end
if invnode.name=="mcl_jukebox:jukebox" then
if not inv:is_empty("main") then
-- Jukebox contains a disc: Stop music and remove disc
local record = inv:get_stack("main", 1)
if mcl_jukebox.registered_records[record:get_name()] then
local ident = mcl_jukebox.registered_records[record:get_name()][3]
local t = {
id_13 = 1,
id_cat = 2,
id_blocks = 3,
id_chirp = 4,
id_far = 5,
id_mall = 6,
id_mellohi = 7,
id_stal = 8,
id_strad = 9,
id_ward = 10,
id_11 = 11,
id_wait = 12,
id_Pigstep = 13,
}
local vol = t["id_"..ident]
if vol then return vol, false end
end
local record = inv:get_stack("main", 1)
if mcl_jukebox.registered_records[record:get_name()] then
local ident = mcl_jukebox.registered_records[record:get_name()][3]
local t = {
id_13 = 1,
id_cat = 2,
id_blocks = 3,
id_chirp = 4,
id_far = 5,
id_mall = 6,
id_mellohi = 7,
id_stal = 8,
id_strad = 9,
id_ward = 10,
id_11 = 11,
id_wait = 12,
id_Pigstep = 13,
}
local vol = t["id_"..ident]
if vol then return vol, false end
end
elseif invnode.name=="mcl_itemframes:item_frame" then
local meta = minetest.get_meta(pos)
local rotation = meta:get_int("rotation") or 0
return rotation+1, false
else
local item_count = 0
local inv_space = 0
for listname, _ in pairs(inv:get_lists()) do
local stack = inv:get_stack(listname, 1)
local st_size = inv:get_size(listname)
inv_space = inv_space + (64 * st_size)
for i = 1,st_size do
local stack = inv:get_stack(listname, i)
item_count = item_count + (stack:get_count() * 64 / stack:get_stack_max())
end
--if not inv:is_empty(listname) then return true, 15 end
end
if item_count>0 then
local voltage = math.floor(1 + (item_count/inv_space*14))
return voltage, false
@ -159,25 +152,18 @@ local function comparator_desired_on(pos, node)
if back_rule then
local back_pos = vector.add(pos, back_rule)
local _, _, vo_back = mesecon.is_powered(pos, back_rule)
local vo_coin, spread = container_inventory_nonempty(back_pos, back_rule)
local vo_sso = static_signal_output(back_pos)
if vo_coin>=1 and spread and vo_back<15 then
--container through opaque block and block is powerd less than 15 -> ignore powered block
vo_back=0
end
voltage = math.max(vo_back, vo_coin, vo_sso)
end
-- if back input is off, we don't need to check side inputs
if voltage<1 then return false, 0 end
local mode = minetest.registered_nodes[node.name].comparator_mode
local side_voltage = 0
for ri = 2,3 do
if my_input_rules[ri] then
@ -188,6 +174,7 @@ local function comparator_desired_on(pos, node)
end
end
local mode = minetest.registered_nodes[node.name].comparator_mode
if mode == "comp" then
-- Comparators in comparison mode
if side_voltage > voltage then
@ -240,9 +227,7 @@ local function update_self(pos, node)
local old_state = mesecon.is_receptor_on(node.name)
local meta = minetest.get_meta(pos)
local old_voltage = old_state and (meta:get_string("mesecon_voltage")~="" and meta:get_int("mesecon_voltage") or 15) or 0
local new_state, new_voltage = comparator_desired_on(pos, node)
if (new_state ~= old_state) or (old_voltage~=new_voltage) then
if old_voltage~=new_voltage then meta:set_int("mesecon_voltage", new_voltage) end
if new_state then