Speed update of pressureplates up by using node_timers

This commit is contained in:
PilzAdam 2012-12-07 15:52:52 +01:00
parent 7542dd4da0
commit 4a8e20b68e
2 changed files with 59 additions and 58 deletions

View File

@ -1,3 +1,4 @@
-- SETTINGS -- SETTINGS
BLINKY_PLANT_INTERVAL = 3 BLINKY_PLANT_INTERVAL = 3
NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
PRESSURE_PLATE_INTERVAL = 0.1

View File

@ -18,6 +18,22 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_wood_off", {
}, },
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3, mesecon = 2}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3, mesecon = 2},
description="Wood Pressure Plate", description="Wood 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_wood_on"})
mesecon:receptor_on(pos, mesecon:get_rules("pressureplate"))
end
end
return true
end,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
}) })
minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", { minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", {
@ -36,6 +52,19 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_wood_on", {
}, },
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2},
drop='"mesecons_pressureplates:pressure_plate_wood_off" 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, mesecon:get_rules("pressureplate"))
end
return true
end,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
}) })
minetest.register_craft({ minetest.register_craft({
@ -45,35 +74,6 @@ minetest.register_craft({
} }
}) })
minetest.register_abm(
{nodenames = {"mesecons_pressureplates:pressure_plate_wood_off"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
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_wood_on"})
mesecon:receptor_on(pos, mesecon:get_rules("pressureplate"))
end
end
end,
})
minetest.register_abm(
{nodenames = {"mesecons_pressureplates:pressure_plate_wood_on"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
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, mesecon:get_rules("pressureplate"))
end
end,
})
-- PRESSURE PLATE STONE -- PRESSURE PLATE STONE
minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", { minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", {
@ -94,6 +94,22 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_stone_off", {
}, },
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3, mesecon = 2}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3, mesecon = 2},
description="Stone Pressure Plate", 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, mesecon:get_rules("pressureplate"))
end
end
return true
end,
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_node("mesecons_pressureplates:pressure_plate_stone_on", {
@ -112,6 +128,19 @@ minetest.register_node("mesecons_pressureplates:pressure_plate_stone_on", {
}, },
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1, mesecon = 2},
drop='"mesecons_pressureplates:pressure_plate_stone_off" 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, mesecon:get_rules("pressureplate"))
end
return true
end,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end,
}) })
minetest.register_craft({ minetest.register_craft({
@ -121,35 +150,6 @@ minetest.register_craft({
} }
}) })
minetest.register_abm(
{nodenames = {"mesecons_pressureplates:pressure_plate_stone_off"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
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, mesecon:get_rules("pressureplate"))
end
end
end,
})
minetest.register_abm(
{nodenames = {"mesecons_pressureplates:pressure_plate_stone_on"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
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, mesecon:get_rules("pressureplate"))
end
end,
})
mesecon:add_rules("pressureplate", mesecon:add_rules("pressureplate",
{{x=0, y=1, z=-1}, {{x=0, y=1, z=-1},
{x=0, y=0, z=-1}, {x=0, y=0, z=-1},