comparator read inventory through opaque blocks
This commit is contained in:
parent
d01a821325
commit
f6e94f7d4f
|
@ -107,25 +107,31 @@ end
|
|||
|
||||
|
||||
-- weather pos has an inventory that contains at least one item
|
||||
local function container_inventory_nonempty(pos)
|
||||
local function container_inventory_nonempty(pos, rule)
|
||||
-- https://minecraft.fandom.com/wiki/Redstone_Comparator#Measure_block_state
|
||||
-- signal strength = floor(1 + ((sum of all slots' fullnesses) / (number of slots in container)) × 14)
|
||||
-- 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 end
|
||||
if not invnodedef then return 0, false end
|
||||
|
||||
if minetest.get_item_group(invnode.name, "opaque") == 1 and rule then
|
||||
--found opaque block -> check next block
|
||||
local backback_pos = vector.add(pos, rule)
|
||||
local bb_voltage, _ = container_inventory_nonempty(backback_pos, nil)
|
||||
return bb_voltage, true
|
||||
end
|
||||
|
||||
-- Only accept containers. When a container is dug, it's inventory
|
||||
-- seems to stay. and we don't want to accept the inventory of an air
|
||||
-- block
|
||||
if not invnodedef.groups.container then return 0 end
|
||||
if not invnodedef.groups.container then return 0, false end
|
||||
|
||||
local inv = minetest.get_inventory({type="node", pos=pos})
|
||||
if not inv then return 0 end
|
||||
if not inv then return 0, false end
|
||||
|
||||
|
||||
--minetest.log("action", mesecon.postostring(pos) .. "-->" .. "container_inventory_nonempty.inv= " .. mesecon.tabletostring(inv:get_lists()))
|
||||
|
@ -159,10 +165,10 @@ local function container_inventory_nonempty(pos)
|
|||
if item_count>0 then
|
||||
local voltage = math.floor(1 + (item_count/inv_space*14))
|
||||
--minetest.log("action", mesecon.postostring(pos) .. "-->" .. "container_inventory_nonempty.voltage= " .. voltage)
|
||||
return voltage
|
||||
return voltage, false
|
||||
end
|
||||
|
||||
return 0
|
||||
return 0, false
|
||||
end
|
||||
|
||||
-- weather pos has an constant signal output for the comparator
|
||||
|
@ -179,15 +185,17 @@ local function comparator_desired_on(pos, node)
|
|||
local voltage = 0
|
||||
if back_rule then
|
||||
local back_pos = vector.add(pos, back_rule)
|
||||
--local _, vo_back = mesecon.is_power_on(back_pos)
|
||||
--local _, _, vo_back = mesecon.is_powered(back_pos)
|
||||
local _, _, vo_back = mesecon.is_powered(pos, back_rule)
|
||||
|
||||
|
||||
local vo_coin = container_inventory_nonempty(back_pos)
|
||||
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
|
||||
|
||||
|
@ -476,7 +484,7 @@ minetest.register_abm({
|
|||
"mcl_comparators:comparator_off_comp",
|
||||
"mcl_comparators:comparator_off_sub",
|
||||
},
|
||||
neighbors = {"group:container", "group:comparator_signal"},
|
||||
neighbors = {"group:container", "group:comparator_signal", "group:opaque"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = update_self,
|
||||
|
|
Loading…
Reference in New Issue