forked from minetest-mods/mesecons
Rework the next nodes: Pressure Plates
This commit is contained in:
parent
72d58d2018
commit
2bbc9dd4b7
|
@ -1,159 +1,113 @@
|
||||||
-- PRESSURE PLATE WOOD
|
local pp_box_off = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
||||||
|
}
|
||||||
|
|
||||||
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", {
|
local pp_box_on = {
|
||||||
drawtype = "nodebox",
|
type = "fixed",
|
||||||
tiles = {"jeija_pressure_plate_wood_off.png"},
|
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
||||||
inventory_image = "jeija_pressure_plate_wood_off.png",
|
}
|
||||||
wield_image = "jeija_pressure_plate_wood_off.png",
|
|
||||||
paramtype = "light",
|
pp_on_timer = function (pos, elapsed)
|
||||||
is_ground_content = true,
|
local node = minetest.env:get_node(pos)
|
||||||
walkable = true,
|
local ppspec = minetest.registered_nodes[node.name].pressureplate
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
-- This is a workaround for a strange bug that occurs when the server is started
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
-- For some reason the first time on_timer is called, the pos is wrong
|
||||||
},
|
if not ppspec then return end
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
|
||||||
},
|
if objs[1] == nil and node.name == ppspec.onstate then
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
|
minetest.env:add_node(pos, {name = ppspec.offstate})
|
||||||
description="Wood Pressure Plate",
|
mesecon:receptor_off(pos)
|
||||||
|
-- force deactivation of mesecon two blocks below (hacky)
|
||||||
on_timer = function(pos, elapsed)
|
mesecon:turnoff(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
else
|
||||||
for k, obj in pairs(objs) do
|
for k, obj in pairs(objs) do
|
||||||
local objpos=obj:getpos()
|
local objpos = obj:getpos()
|
||||||
if objpos.y>pos.y-1 and objpos.y<pos.y then
|
if objpos.y > pos.y-1 and objpos.y < pos.y then
|
||||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_on"})
|
minetest.env:add_node(pos, {name=ppspec.onstate})
|
||||||
mesecon:receptor_on(pos)
|
mesecon:receptor_on(pos)
|
||||||
|
-- force activation of mesecon two blocks below (hacky)
|
||||||
|
mesecon:turnon(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
end
|
||||||
end,
|
return true
|
||||||
mesecons = {receptor = {
|
end
|
||||||
state = mesecon.state.off
|
|
||||||
}},
|
|
||||||
on_construct = function(pos)
|
|
||||||
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", {
|
-- Register a Pressure Plate
|
||||||
drawtype = "nodebox",
|
-- offstate: name of the pressure plate when inactive
|
||||||
tiles = {"jeija_pressure_plate_wood_on.png"},
|
-- onstate: name of the pressure plate when active
|
||||||
paramtype = "light",
|
-- description: description displayed in the player's inventory
|
||||||
is_ground_content = true,
|
-- tiles_off: textures of the pressure plate when inactive
|
||||||
walkable = true,
|
-- tiles_on: textures of the pressure plate when active
|
||||||
selection_box = {
|
-- image: inventory and wield image of the pressure plate
|
||||||
type = "fixed",
|
-- recipe: crafting recipe of the pressure plate
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
|
||||||
},
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
|
|
||||||
},
|
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
|
|
||||||
drop='"mesecons_pressureplates:pressure_plate_wood_off" 1',
|
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
|
||||||
if objs[1]==nil then
|
|
||||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_wood_off"})
|
|
||||||
mesecon:receptor_off(pos)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
mesecons = {receptor = {
|
|
||||||
state = mesecon.state.on
|
|
||||||
}},
|
|
||||||
on_construct = function(pos)
|
|
||||||
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
function mesecon:register_pressure_plate(offstate, onstate, description, texture_off, texture_on, recipe)
|
||||||
output = '"mesecons_pressureplates:pressure_plate_wood_off" 1',
|
local ppspec = {
|
||||||
recipe = {
|
offstate = offstate,
|
||||||
{'"default:wood"', '"default:wood"'},
|
onstate = onstate
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
-- PRESSURE PLATE STONE
|
minetest.register_node(offstate, {
|
||||||
|
drawtype = "nodebox",
|
||||||
|
tiles = {texture_off},
|
||||||
|
inventory_image = texture_off,
|
||||||
|
wield_image = image,
|
||||||
|
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("mesecons_pressureplates:pressure_plate_stone_off", {
|
minetest.register_node(onstate, {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
tiles = {"jeija_pressure_plate_stone_off.png"},
|
tiles = {texture_on},
|
||||||
inventory_image = "jeija_pressure_plate_stone_off.png",
|
paramtype = "light",
|
||||||
wield_image = "jeija_pressure_plate_stone_off.png",
|
selection_box = pp_box_on,
|
||||||
paramtype = "light",
|
node_box = pp_box_on,
|
||||||
is_ground_content = true,
|
groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
|
||||||
walkable = true,
|
drop = offstate,
|
||||||
selection_box = {
|
pressureplate = ppspec,
|
||||||
type = "fixed",
|
on_timer = pp_on_timer,
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
mesecons = {receptor = {
|
||||||
},
|
state = mesecon.state.on
|
||||||
node_box = {
|
}},
|
||||||
type = "fixed",
|
on_construct = function(pos)
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
||||||
},
|
end,
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3},
|
})
|
||||||
description="Stone Pressure Plate",
|
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
|
||||||
for k, obj in pairs(objs) do
|
|
||||||
local objpos=obj:getpos()
|
|
||||||
if objpos.y>pos.y-1 and objpos.y<pos.y then
|
|
||||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_on"})
|
|
||||||
mesecon:receptor_on(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
mesecons = {receptor = {
|
|
||||||
state = mesecon.state.off
|
|
||||||
}},
|
|
||||||
on_construct = function(pos)
|
|
||||||
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", {
|
minetest.register_craft({
|
||||||
drawtype = "nodebox",
|
output = offstate,
|
||||||
tiles = {"jeija_pressure_plate_stone_on.png"},
|
recipe = recipe,
|
||||||
paramtype = "light",
|
})
|
||||||
is_ground_content = true,
|
end
|
||||||
walkable = true,
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
|
|
||||||
},
|
|
||||||
node_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = { -7/16, -8/16, -7/16, 7/16, -31/64, 7/16 },
|
|
||||||
},
|
|
||||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
|
|
||||||
drop='"mesecons_pressureplates:pressure_plate_stone_off" 1',
|
|
||||||
|
|
||||||
on_timer = function(pos, elapsed)
|
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
|
||||||
if objs[1]==nil then
|
|
||||||
minetest.env:add_node(pos, {name="mesecons_pressureplates:pressure_plate_stone_off"})
|
|
||||||
mesecon:receptor_off(pos)
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
mesecons = {receptor = {
|
|
||||||
state = mesecon.state.on
|
|
||||||
}},
|
|
||||||
on_construct = function(pos)
|
|
||||||
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
mesecon:register_pressure_plate(
|
||||||
output = '"mesecons_pressureplates:pressure_plate_stone_off" 1',
|
"mesecons_pressureplates:pressure_plate_wood_off",
|
||||||
recipe = {
|
"mesecons_pressureplates:pressure_plate_wood_on",
|
||||||
{'"default:cobble"', '"default:cobble"'},
|
"Wooden Pressure Plate",
|
||||||
}
|
"jeija_pressure_plate_wood_off.png",
|
||||||
})
|
"jeija_pressure_plate_wood_on.png",
|
||||||
|
{{"default:wood", "default:wood"}})
|
||||||
|
|
||||||
|
mesecon:register_pressure_plate(
|
||||||
|
"mesecons_pressureplates:pressure_plate_stone_off",
|
||||||
|
"mesecons_pressureplates:pressure_plate_stone_on",
|
||||||
|
"Stone Pressure Plate",
|
||||||
|
"jeija_pressure_plate_stone_off.png",
|
||||||
|
"jeija_pressure_plate_stone_on.png",
|
||||||
|
{{"default:cobble", "default:cobble"}})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user