From ba292aeb5d4085ab3d1dffd4e1b608e81e27556d Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Thu, 1 Dec 2022 13:02:30 -0600 Subject: [PATCH 1/3] Pressure plates check for entity contact --- .../REDSTONE/mesecons_pressureplates/init.lua | 71 ++++++++++++++----- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua index a453d1981..41698a661 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua @@ -37,19 +37,54 @@ local function pp_on_timer(pos, elapsed) end end - local objs = minetest.get_objects_inside_radius(pos, .99) + local function obj_touching_plate_pos(obj_ref, plate_pos) + local obj_pos = obj_ref:get_pos() + local props = obj_ref:get_properties() + local parent = obj_ref:get_attach() + if props and obj_pos and not parent then + local collisionbox = props.collisionbox + local physical = props.physical + local is_player = obj_ref:is_player() + local luaentity = obj_ref:get_luaentity() + local is_item = luaentity and luaentity.name == "__builtin:item" + if collisionbox and physical or is_player or is_item then + local plate_x_min = plate_pos.x - 7 / 16 + local plate_x_max = plate_pos.x + 7 / 16 + local plate_z_min = plate_pos.z - 7 / 16 + local plate_z_max = plate_pos.z + 7 / 16 + local plate_y_max = plate_pos.y - 7 / 16 + + local obj_x_min = obj_pos.x + collisionbox[1] + local obj_x_max = obj_pos.x + collisionbox[4] + local obj_z_min = obj_pos.z + collisionbox[3] + local obj_z_max = obj_pos.z + collisionbox[6] + local obj_y_min = obj_pos.y + collisionbox[2] + + if + obj_y_min <= plate_y_max and + not (obj_x_min >= plate_x_max) and + not (obj_x_max <= plate_x_min) and + not (obj_z_min >= plate_z_max) and + not (obj_z_max <= plate_z_min) + then + return true + end + end + end + return false + end + + local objs = minetest.get_objects_inside_radius(pos, 1) if node.name == basename .. "_on" then - local disable - if #objs == 0 then - disable = true - elseif not activated_by.any then - disable = true - for k, obj in pairs(objs) do - if obj_does_activate(obj, activated_by) then - disable = false - break - end + local disable = true + for k, obj in pairs(objs) do + if + obj_does_activate(obj, activated_by) and + obj_touching_plate_pos(obj, pos) + then + disable = false + break end end if disable then @@ -58,13 +93,13 @@ local function pp_on_timer(pos, elapsed) end elseif node.name == basename .. "_off" then for k, obj in pairs(objs) do - local objpos = obj:get_pos() - if obj_does_activate(obj, activated_by) then - if objpos.y > pos.y-1 and objpos.y < pos.y then - minetest.set_node(pos, {name = basename .. "_on"}) - mesecon.receptor_on(pos, mesecon.rules.pplate) - break - end + if + obj_does_activate(obj, activated_by) and + obj_touching_plate_pos(obj, pos) + then + minetest.set_node(pos, {name = basename .. "_on"}) + mesecon.receptor_on(pos, mesecon.rules.pplate) + break end end end From d8c16b1f318048ee69b06b78f2e8cb64ba032d25 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Sun, 4 Dec 2022 10:53:07 -0600 Subject: [PATCH 2/3] Add 1 sec deactivation delay to pplates --- .../REDSTONE/mesecons_pressureplates/init.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua index 41698a661..0d81e6dfe 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua @@ -84,12 +84,23 @@ local function pp_on_timer(pos, elapsed) obj_touching_plate_pos(obj, pos) then disable = false + minetest.get_meta(pos):set_string("deact_time", "") break end end if disable then - minetest.set_node(pos, {name = basename .. "_off"}) - mesecon.receptor_off(pos, mesecon.rules.pplate) + local meta = minetest.get_meta(pos) + local deact_time = meta:get_float("deact_time") + local current_time = minetest.get_us_time() + if deact_time == 0 then + deact_time = current_time + 1 * 1000 * 1000 + meta:set_float("deact_time", deact_time) + end + if deact_time <= current_time then + minetest.set_node(pos, { name = basename .. "_off" }) + mesecon.receptor_off(pos, mesecon.rules.pplate) + meta:set_string("deact_time", "") + end end elseif node.name == basename .. "_off" then for k, obj in pairs(objs) do @@ -97,7 +108,7 @@ local function pp_on_timer(pos, elapsed) obj_does_activate(obj, activated_by) and obj_touching_plate_pos(obj, pos) then - minetest.set_node(pos, {name = basename .. "_on"}) + minetest.set_node(pos, { name = basename .. "_on" }) mesecon.receptor_on(pos, mesecon.rules.pplate) break end From 7c87ed2d6c46b2b9b5e84cce3ce4330bff3e3f7d Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Mon, 5 Dec 2022 14:24:34 -0600 Subject: [PATCH 3/3] Add rightclick support to pplates --- mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua index 0d81e6dfe..9248e693e 100644 --- a/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_pressureplates/init.lua @@ -12,6 +12,16 @@ local pp_box_on = { fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 }, } +local function pp_on_rightclick(pos, node) + local basename = minetest.registered_nodes[node.name].pressureplate_basename + if node.name == basename .. "_off" then + minetest.set_node(pos, { name = basename .. "_on" }) + mesecon.receptor_on(pos, mesecon.rules.pplate) + else + minetest.get_meta(pos):set_string("deact_time", "") + end +end + local function pp_on_timer(pos, elapsed) local node = minetest.get_node(pos) local basename = minetest.registered_nodes[node.name].pressureplate_basename @@ -164,6 +174,7 @@ function mesecon.register_pressure_plate(basename, description, textures_off, te walkable = false, description = description, on_timer = pp_on_timer, + on_rightclick = pp_on_rightclick, on_construct = function(pos) minetest.get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) end,