2022-12-01 18:33:19 +01:00
|
|
|
local S = minetest.get_translator(minetest.get_current_modname())
|
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
local pp_box_off = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
|
|
|
}
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
local pp_box_on = {
|
|
|
|
type = "fixed",
|
2013-04-21 08:16:43 +02:00
|
|
|
fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
|
2012-12-27 22:28:39 +01:00
|
|
|
}
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2023-06-18 20:05:35 +02:00
|
|
|
local function obj_touching_plate_pos(obj_ref, plate_pos)
|
|
|
|
local obj_pos = obj_ref:get_pos()
|
|
|
|
local props = obj_ref:get_properties()
|
|
|
|
if not (props and obj_pos and not obj_ref:get_attach()) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
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 not (collisionbox and physical or is_player or is_item) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
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_min = plate_pos.y - 8 / 16
|
|
|
|
local plate_y_max = plate_pos.y - 6.5 / 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]
|
|
|
|
local obj_y_max = obj_pos.y + collisionbox[5]
|
|
|
|
|
|
|
|
if
|
|
|
|
obj_y_min < plate_y_max and
|
|
|
|
obj_y_max > plate_y_min and
|
|
|
|
obj_x_min < plate_x_max and
|
|
|
|
obj_x_max > plate_x_min and
|
|
|
|
obj_z_min < plate_z_max and
|
|
|
|
obj_z_max > plate_z_min
|
|
|
|
then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
local function pp_on_timer(pos)
|
2014-11-22 12:28:45 +01:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local basename = minetest.registered_nodes[node.name].pressureplate_basename
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
-- This is a workaround for a strange bug that occurs when the server is started
|
|
|
|
-- For some reason the first time on_timer is called, the pos is wrong
|
2014-11-22 12:28:45 +01:00
|
|
|
if not basename then return end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2023-06-18 20:05:35 +02:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, 1)
|
|
|
|
local obj_touching = false
|
|
|
|
for k, obj in pairs(objs) do
|
|
|
|
if obj_touching_plate_pos(obj, pos) then
|
|
|
|
obj_touching = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2023-06-18 20:05:35 +02:00
|
|
|
if not obj_touching and node.name == basename .. "_on" then
|
2016-02-14 21:00:37 +01:00
|
|
|
minetest.set_node(pos, {name = basename .. "_off"})
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.receptor_off(pos, mesecon.rules.pplate)
|
2023-06-18 20:05:35 +02:00
|
|
|
elseif obj_touching and node.name == basename .. "_off" then
|
|
|
|
minetest.set_node(pos, {name = basename .. "_on"})
|
|
|
|
mesecon.receptor_on(pos, mesecon.rules.pplate )
|
2012-12-27 22:28:39 +01:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
-- Register a Pressure Plate
|
|
|
|
-- offstate: name of the pressure plate when inactive
|
2013-02-24 19:02:38 +01:00
|
|
|
-- onstate: name of the pressure plate when active
|
2012-12-27 22:28:39 +01:00
|
|
|
-- description: description displayed in the player's inventory
|
|
|
|
-- tiles_off: textures of the pressure plate when inactive
|
|
|
|
-- tiles_on: textures of the pressure plate when active
|
2013-02-24 19:02:38 +01:00
|
|
|
-- image: inventory and wield image of the pressure plate
|
|
|
|
-- recipe: crafting recipe of the pressure plate
|
2018-01-28 21:14:54 +01:00
|
|
|
-- groups: groups
|
|
|
|
-- sounds: sound table
|
|
|
|
|
|
|
|
function mesecon.register_pressure_plate(basename, description, textures_off, textures_on, image_w, image_i, recipe, groups, sounds)
|
|
|
|
if not groups then
|
|
|
|
groups = {}
|
|
|
|
end
|
|
|
|
local groups_off = table.copy(groups)
|
|
|
|
local groups_on = table.copy(groups)
|
|
|
|
groups_on.not_in_creative_inventory = 1
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2014-11-22 12:28:45 +01:00
|
|
|
mesecon.register_node(basename, {
|
2012-12-27 22:28:39 +01:00
|
|
|
drawtype = "nodebox",
|
2013-04-21 07:00:31 +02:00
|
|
|
inventory_image = image_i,
|
|
|
|
wield_image = image_w,
|
2012-12-27 22:28:39 +01:00
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
|
|
|
description = description,
|
2014-11-22 12:28:45 +01:00
|
|
|
pressureplate_basename = basename,
|
2012-12-27 22:28:39 +01:00
|
|
|
on_timer = pp_on_timer,
|
|
|
|
on_construct = function(pos)
|
2014-11-22 22:09:26 +01:00
|
|
|
minetest.get_node_timer(pos):start(mesecon.setting("pplate_interval", 0.1))
|
2012-12-27 22:28:39 +01:00
|
|
|
end,
|
2018-01-28 21:14:54 +01:00
|
|
|
sounds = sounds,
|
2014-11-22 12:28:45 +01:00
|
|
|
},{
|
|
|
|
mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }},
|
|
|
|
node_box = pp_box_off,
|
|
|
|
selection_box = pp_box_off,
|
2018-01-28 21:14:54 +01:00
|
|
|
groups = groups_off,
|
2014-11-22 12:28:45 +01:00
|
|
|
tiles = textures_off
|
|
|
|
},{
|
|
|
|
mesecons = {receptor = { state = mesecon.state.on, rules = mesecon.rules.pplate }},
|
2012-12-27 22:28:39 +01:00
|
|
|
node_box = pp_box_on,
|
2014-11-22 12:28:45 +01:00
|
|
|
selection_box = pp_box_on,
|
2018-01-28 21:14:54 +01:00
|
|
|
groups = groups_on,
|
2014-11-22 12:28:45 +01:00
|
|
|
tiles = textures_on
|
2012-12-27 22:28:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2014-11-22 12:28:45 +01:00
|
|
|
output = basename .. "_off",
|
2012-12-27 22:28:39 +01:00
|
|
|
recipe = recipe,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.register_pressure_plate(
|
2014-11-22 12:28:45 +01:00
|
|
|
"mesecons_pressureplates:pressure_plate_wood",
|
2022-12-01 18:33:19 +01:00
|
|
|
S("Wooden Pressure Plate"),
|
2013-04-21 07:00:31 +02:00
|
|
|
{"jeija_pressure_plate_wood_off.png","jeija_pressure_plate_wood_off.png","jeija_pressure_plate_wood_off_edges.png"},
|
|
|
|
{"jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on_edges.png"},
|
|
|
|
"jeija_pressure_plate_wood_wield.png",
|
|
|
|
"jeija_pressure_plate_wood_inv.png",
|
2018-01-28 21:14:54 +01:00
|
|
|
{{"group:wood", "group:wood"}},
|
|
|
|
{ choppy = 3, oddly_breakable_by_hand = 3 },
|
2022-05-05 16:57:53 +02:00
|
|
|
mesecon.node_sound.wood)
|
2012-12-27 22:28:39 +01:00
|
|
|
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.register_pressure_plate(
|
2014-11-22 12:28:45 +01:00
|
|
|
"mesecons_pressureplates:pressure_plate_stone",
|
2022-12-01 18:33:19 +01:00
|
|
|
S("Stone Pressure Plate"),
|
2013-04-21 07:00:31 +02:00
|
|
|
{"jeija_pressure_plate_stone_off.png","jeija_pressure_plate_stone_off.png","jeija_pressure_plate_stone_off_edges.png"},
|
|
|
|
{"jeija_pressure_plate_stone_on.png","jeija_pressure_plate_stone_on.png","jeija_pressure_plate_stone_on_edges.png"},
|
|
|
|
"jeija_pressure_plate_stone_wield.png",
|
|
|
|
"jeija_pressure_plate_stone_inv.png",
|
2022-05-05 16:57:53 +02:00
|
|
|
{{"mesecons_gamecompat:cobble", "mesecons_gamecompat:cobble"}},
|
2018-01-28 21:14:54 +01:00
|
|
|
{ cracky = 3, oddly_breakable_by_hand = 3 },
|
2022-05-05 16:57:53 +02:00
|
|
|
mesecon.node_sound.stone)
|