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
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
pp_on_timer = function (pos, elapsed)
|
|
|
|
local node = minetest.env:get_node(pos)
|
|
|
|
local ppspec = minetest.registered_nodes[node.name].pressureplate
|
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
|
|
|
|
if not ppspec then return end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
2013-02-24 19:09:07 +01:00
|
|
|
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-27 22:28:39 +01:00
|
|
|
if objs[1] == nil and node.name == ppspec.onstate then
|
|
|
|
minetest.env:add_node(pos, {name = ppspec.offstate})
|
|
|
|
mesecon:receptor_off(pos)
|
|
|
|
-- force deactivation of mesecon two blocks below (hacky)
|
2013-02-24 19:09:07 +01:00
|
|
|
if not mesecon:connected_to_receptor(two_below) then
|
|
|
|
mesecon:turnoff(two_below)
|
|
|
|
end
|
2012-12-27 22:28:39 +01:00
|
|
|
else
|
2012-12-07 15:52:52 +01:00
|
|
|
for k, obj in pairs(objs) do
|
2012-12-27 22:28:39 +01:00
|
|
|
local objpos = obj:getpos()
|
|
|
|
if objpos.y > pos.y-1 and objpos.y < pos.y then
|
|
|
|
minetest.env:add_node(pos, {name=ppspec.onstate})
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecon:receptor_on(pos)
|
2012-12-27 22:28:39 +01:00
|
|
|
-- force activation of mesecon two blocks below (hacky)
|
2013-02-24 19:09:07 +01:00
|
|
|
mesecon:turnon(two_below)
|
2012-12-07 15:52:52 +01:00
|
|
|
end
|
|
|
|
end
|
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
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2013-04-21 07:00:31 +02:00
|
|
|
function mesecon:register_pressure_plate(offstate, onstate, description, textures_off, textures_on, image_w, image_i, recipe)
|
2012-12-27 22:28:39 +01:00
|
|
|
local ppspec = {
|
|
|
|
offstate = offstate,
|
|
|
|
onstate = onstate
|
2012-03-05 19:21:26 +01:00
|
|
|
}
|
2012-12-27 22:28:39 +01:00
|
|
|
|
|
|
|
minetest.register_node(offstate, {
|
|
|
|
drawtype = "nodebox",
|
2013-04-21 07:00:31 +02:00
|
|
|
tiles = textures_off,
|
|
|
|
inventory_image = image_i,
|
|
|
|
wield_image = image_w,
|
2012-12-27 22:28:39 +01:00
|
|
|
paramtype = "light",
|
|
|
|
selection_box = pp_box_off,
|
|
|
|
node_box = pp_box_off,
|
|
|
|
groups = {snappy = 2, oddly_breakable_by_hand = 3},
|
|
|
|
description = description,
|
|
|
|
pressureplate = ppspec,
|
|
|
|
on_timer = pp_on_timer,
|
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.off
|
|
|
|
}},
|
|
|
|
on_construct = function(pos)
|
|
|
|
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node(onstate, {
|
|
|
|
drawtype = "nodebox",
|
2013-04-21 07:00:31 +02:00
|
|
|
tiles = textures_on,
|
2012-12-27 22:28:39 +01:00
|
|
|
paramtype = "light",
|
|
|
|
selection_box = pp_box_on,
|
|
|
|
node_box = pp_box_on,
|
|
|
|
groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
|
|
|
|
drop = offstate,
|
|
|
|
pressureplate = ppspec,
|
|
|
|
on_timer = pp_on_timer,
|
2013-03-07 02:51:57 +01:00
|
|
|
sounds = default.node_sound_wood_defaults(),
|
2012-12-27 22:28:39 +01:00
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.on
|
|
|
|
}},
|
|
|
|
on_construct = function(pos)
|
|
|
|
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
|
|
end,
|
2013-02-24 19:02:38 +01:00
|
|
|
after_dig_node = function(pos)
|
|
|
|
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
|
|
|
|
if not mesecon:connected_to_receptor(two_below) then
|
|
|
|
mesecon:turnoff(two_below)
|
|
|
|
end
|
|
|
|
end
|
2012-12-27 22:28:39 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = offstate,
|
|
|
|
recipe = recipe,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
mesecon:register_pressure_plate(
|
|
|
|
"mesecons_pressureplates:pressure_plate_wood_off",
|
|
|
|
"mesecons_pressureplates:pressure_plate_wood_on",
|
|
|
|
"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",
|
2013-12-01 01:07:12 +01:00
|
|
|
{{"group:wood", "group:wood"}})
|
2012-12-27 22:28:39 +01:00
|
|
|
|
|
|
|
mesecon:register_pressure_plate(
|
|
|
|
"mesecons_pressureplates:pressure_plate_stone_off",
|
|
|
|
"mesecons_pressureplates:pressure_plate_stone_on",
|
|
|
|
"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",
|
2012-12-27 22:28:39 +01:00
|
|
|
{{"default:cobble", "default:cobble"}})
|