This commit is contained in:
Vitaliy 2024-01-04 02:12:48 -08:00 committed by GitHub
commit 55c013f4e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View File

@ -4,11 +4,13 @@ local specs = {
normal = {
offname = "mesecons_pistons:piston_normal_off",
onname = "mesecons_pistons:piston_normal_on",
hotname = "mesecons_pistons:piston_normal_overheated",
pusher = "mesecons_pistons:piston_pusher_normal",
},
sticky = {
offname = "mesecons_pistons:piston_sticky_off",
onname = "mesecons_pistons:piston_sticky_on",
hotname = "mesecons_pistons:piston_sticky_overheated",
pusher = "mesecons_pistons:piston_pusher_sticky",
sticky = true,
},
@ -38,6 +40,8 @@ end
local max_push = mesecon.setting("piston_max_push", 15)
local max_pull = mesecon.setting("piston_max_pull", 15)
local cooldown_time = mesecon.setting("piston_cooldown_time", 5.0)
local cooldown_method = mesecon.setting("piston_cooldown_method", "timer")
-- Get mesecon rules of pistons
local function piston_get_rules(node)
@ -82,6 +86,15 @@ end
local piston_on = function(pos, node)
local pistonspec = get_pistonspec(node.name, "offname")
if mesecon.do_overheat(pos) then
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.hotname})
if cooldown_method == "timer" then
minetest.get_node_timer(pos):start(cooldown_time)
elseif cooldown_method == "actionqueue" then
mesecon.queue:add_action(pos, "piston_cooldown", {}, cooldown_time, "piston_cooldown")
end
return
end
local dir = vector.multiply(minetest.facedir_to_dir(node.param2), -1)
local pusher_pos = vector.add(pos, dir)
local meta = minetest.get_meta(pos)
@ -115,6 +128,19 @@ local function piston_off(pos, node)
end
end
local piston_cooldown
if cooldown_method ~= "none" then
function piston_cooldown(pos)
local node = mesecon.get_node_force(pos)
local pistonspec = get_pistonspec(node.name, "hotname")
if not pistonspec then return end
node.name = pistonspec.offname
minetest.swap_node(pos, node)
if mesecon.is_powered(pos) then piston_on(pos, node) end
end
mesecon.queue:add_function("piston_cooldown", piston_cooldown)
end
local orientations = {
[0] = { 4, 8},
{13, 17},
@ -319,6 +345,30 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
on_blast = mesecon.on_blastnode,
})
-- hotstate
minetest.register_node("mesecons_pistons:piston_normal_overheated", {
description = "Piston (overheated)",
tiles = {
"mesecons_piston_top.png",
"mesecons_piston_bottom.png",
"mesecons_piston_left.png",
"mesecons_piston_right.png",
"mesecons_piston_back.png",
"mesecons_piston_pusher_front.png"
},
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
is_ground_content = false,
drop = "mesecons_pistons:piston_normal_off",
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
rules = piston_get_rules, -- провода остаются на месте
}},
on_timer = piston_cooldown,
on_rotate = piston_rotate,
on_blast = mesecon.on_blastnode,
})
-- pusher
minetest.register_node("mesecons_pistons:piston_pusher_normal", {
description = S("Piston Pusher"),
@ -398,6 +448,29 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
on_blast = mesecon.on_blastnode,
})
-- hotstate
minetest.register_node("mesecons_pistons:piston_sticky_overheated", {
description = "Sticky Piston",
tiles = {
"mesecons_piston_top.png",
"mesecons_piston_bottom.png",
"mesecons_piston_left.png",
"mesecons_piston_right.png",
"mesecons_piston_back.png",
"mesecons_piston_pusher_front_sticky.png"
},
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
rules = piston_get_rules, -- провода остаются на месте
}},
on_timer = piston_cooldown,
on_rotate = piston_rotate,
on_blast = mesecon.on_blastnode,
})
-- pusher
minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
description = S("Sticky Piston Pusher"),

View File

@ -56,6 +56,18 @@ mesecon.movestone_max_pull (Max pull) int 50 1 100
mesecon.piston_max_push (Max push) int 15 1 100
mesecon.piston_max_pull (Max pull) int 15 1 100
# Unlike most devices, pistons don't break permanently
# after overheating. They cooldown automatically (unless
# disabled, see piston_cooldown_method) after given amount
# of time, becoming working again.
mesecon.piston_cooldown_time (Piston cooldown time, in seconds) float 5.0 1.0 60.0
# Cooldown method can be choosen:
# - timer: cooldown happens in active blocks only (but the timer itself persists even server restarts)
# - actionqueue: cooldown happens when its time comes. Persists server restarts too.
# - none: disable cooldown. Queued events are discarded.
mesecon.piston_cooldown_method (Piston cooldown method) enum timer timer,actionqueue,none
[mesecons_pressureplates]