1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-19 16:50:31 +01:00
server-nalc/mods/mesecons/mesecons_pressureplates/init.lua

101 lines
3.6 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
local pp_box_off = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
}
local pp_box_on = {
type = "fixed",
fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
}
pp_on_timer = function (pos, elapsed)
2014-11-29 15:40:55 +01:00
local node = minetest.get_node(pos)
local basename = minetest.registered_nodes[node.name].pressureplate_basename
2014-10-28 18:01:32 +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-29 15:40:55 +01:00
if not basename then return end
2014-10-28 18:01:32 +01:00
local objs = minetest.get_objects_inside_radius(pos, 1)
2014-11-29 15:40:55 +01:00
local two_below = mesecon.addPosRule(pos, {x = 0, y = -2, z = 0})
2014-10-28 18:01:32 +01:00
2014-11-29 15:40:55 +01:00
if objs[1] == nil and node.name == basename .. "_on" then
minetest.add_node(pos, {name = basename .. "_off"})
mesecon.receptor_off(pos, mesecon.rules.pplate)
2014-10-28 18:01:32 +01:00
-- force deactivation of mesecon two blocks below (hacky)
2014-11-29 15:40:55 +01:00
if not mesecon.connected_to_receptor(two_below) then
mesecon.turnoff(two_below)
2014-10-28 18:01:32 +01:00
end
else
for k, obj in pairs(objs) do
local objpos = obj:getpos()
if objpos.y > pos.y-1 and objpos.y < pos.y then
2014-11-29 15:40:55 +01:00
minetest.add_node(pos, {name = basename .. "_on"})
mesecon.receptor_on(pos, mesecon.rules.pplate )
2014-10-28 18:01:32 +01:00
-- force activation of mesecon two blocks below (hacky)
2014-11-29 15:40:55 +01:00
mesecon.turnon(two_below)
2014-10-28 18:01:32 +01:00
end
end
end
return true
end
-- Register a Pressure Plate
-- offstate: name of the pressure plate when inactive
-- onstate: name of the pressure plate when active
-- 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
-- image: inventory and wield image of the pressure plate
-- recipe: crafting recipe of the pressure plate
2014-11-29 15:40:55 +01:00
function mesecon.register_pressure_plate(basename, description, textures_off, textures_on, image_w, image_i, recipe)
mesecon.register_node(basename, {
2014-10-28 18:01:32 +01:00
drawtype = "nodebox",
inventory_image = image_i,
wield_image = image_w,
paramtype = "light",
description = description,
2014-11-29 15:40:55 +01:00
pressureplate_basename = basename,
2014-10-28 18:01:32 +01:00
on_timer = pp_on_timer,
on_construct = function(pos)
2014-11-29 15:40:55 +01:00
minetest.get_node_timer(pos):start(mesecon.setting("pplate_interval", 0.1))
2014-10-28 18:01:32 +01:00
end,
2014-11-29 15:40:55 +01:00
},{
mesecons = {receptor = { state = mesecon.state.off, rules = mesecon.rules.pplate }},
node_box = pp_box_off,
selection_box = pp_box_off,
groups = {snappy = 2, oddly_breakable_by_hand = 3},
tiles = textures_off
},{
mesecons = {receptor = { state = mesecon.state.on, rules = mesecon.rules.pplate }},
2014-10-28 18:01:32 +01:00
node_box = pp_box_on,
2014-11-29 15:40:55 +01:00
selection_box = pp_box_on,
2014-10-28 18:01:32 +01:00
groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
2014-11-29 15:40:55 +01:00
tiles = textures_on
2014-10-28 18:01:32 +01:00
})
minetest.register_craft({
2014-11-29 15:40:55 +01:00
output = basename .. "_off",
2014-10-28 18:01:32 +01:00
recipe = recipe,
})
end
2014-11-29 15:40:55 +01:00
mesecon.register_pressure_plate(
"mesecons_pressureplates:pressure_plate_wood",
2014-10-28 18:01:32 +01:00
"Wooden Pressure Plate",
{"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",
{{"group:wood", "group:wood"}})
2014-11-29 15:40:55 +01:00
mesecon.register_pressure_plate(
"mesecons_pressureplates:pressure_plate_stone",
2014-10-28 18:01:32 +01:00
"Stone Pressure Plate",
{"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",
{{"default:cobble", "default:cobble"}})