Delayer: Combine shared definitions, add protection (#490)

This commit is contained in:
SmallJoker 2019-11-04 20:00:43 +01:00 committed by GitHub
parent b7873e8e02
commit bfd952b51a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 71 deletions

2
.gitignore vendored

@ -1 +1,3 @@
*~ *~
*.patch
*.diff

@ -33,19 +33,9 @@ end
-- Register the 2 (states) x 4 (delay times) delayers -- Register the 2 (states) x 4 (delay times) delayers
for i = 1, 4 do local delaytime = { 0.1, 0.3, 0.5, 1.0 }
local groups = {}
if i == 1 then
groups = {bendy=2,snappy=1,dig_immediate=2}
else
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
end
local delaytime for i = 1, 4 do
if i == 1 then delaytime = 0.1
elseif i == 2 then delaytime = 0.3
elseif i == 3 then delaytime = 0.5
elseif i == 4 then delaytime = 1.0 end
local boxes = { local boxes = {
{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab { -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
@ -61,9 +51,36 @@ local boxes = {
{ 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 } { 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }
} }
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), { -- Delayer definition defaults
description = "Delayer", local def = {
drawtype = "nodebox", drawtype = "nodebox",
walkable = true,
selection_box = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
},
node_box = {
type = "fixed",
fixed = boxes
},
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
delayer_time = delaytime[i],
sounds = default.node_sound_stone_defaults(),
on_blast = mesecon.on_blastnode,
drop = "mesecons_delayer:delayer_off_1",
}
-- Deactivated delayer definition defaults
local off_groups = {bendy=2,snappy=1,dig_immediate=2}
if i > 1 then
off_groups.not_in_creative_inventory = 1
end
local off_state = {
description = "Delayer",
tiles = { tiles = {
"mesecons_delayer_off_"..tostring(i)..".png", "mesecons_delayer_off_"..tostring(i)..".png",
"mesecons_delayer_bottom.png", "mesecons_delayer_bottom.png",
@ -74,35 +91,18 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
}, },
inventory_image = "mesecons_delayer_off_1.png", inventory_image = "mesecons_delayer_off_1.png",
wield_image = "mesecons_delayer_off_1.png", wield_image = "mesecons_delayer_off_1.png",
walkable = true, groups = off_groups,
selection_box = { on_punch = function(pos, node, puncher)
type = "fixed", if minetest.is_protected(pos, puncher and puncher:get_player_name()) then
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }, return
},
node_box = {
type = "fixed",
fixed = boxes
},
groups = groups,
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
drop = 'mesecons_delayer:delayer_off_1',
on_punch = function (pos, node)
if node.name=="mesecons_delayer:delayer_off_1" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_2", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_2" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_3", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_3" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_4", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_off_4" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_1", param2=node.param2})
end end
minetest.swap_node(pos, {
name = "mesecons_delayer:delayer_off_"..tostring(i % 4 + 1),
param2 = node.param2
})
end, end,
delayer_time = delaytime,
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i), delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
sounds = default.node_sound_stone_defaults(),
mesecons = { mesecons = {
receptor = receptor =
{ {
@ -115,13 +115,15 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
action_on = delayer_activate action_on = delayer_activate
} }
}, },
on_blast = mesecon.on_blastnode, }
}) for k, v in pairs(def) do
off_state[k] = off_state[k] or v
end
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), off_state)
-- Activated delayer definition defaults
minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), { local on_state = {
description = "You hacker you", description = "You hacker you",
drawtype = "nodebox",
tiles = { tiles = {
"mesecons_delayer_on_"..tostring(i)..".png", "mesecons_delayer_on_"..tostring(i)..".png",
"mesecons_delayer_bottom.png", "mesecons_delayer_bottom.png",
@ -130,35 +132,18 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
"mesecons_delayer_sides_on.png", "mesecons_delayer_sides_on.png",
"mesecons_delayer_sides_on.png" "mesecons_delayer_sides_on.png"
}, },
walkable = true,
selection_box = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
},
node_box = {
type = "fixed",
fixed = boxes
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1}, groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
paramtype = "light", on_punch = function(pos, node, puncher)
paramtype2 = "facedir", if minetest.is_protected(pos, puncher and puncher:get_player_name()) then
sunlight_propagates = true, return
is_ground_content = false,
drop = 'mesecons_delayer:delayer_off_1',
on_punch = function (pos, node)
if node.name=="mesecons_delayer:delayer_on_1" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_2", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_2" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_3", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_3" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_4", param2=node.param2})
elseif node.name=="mesecons_delayer:delayer_on_4" then
minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_1", param2=node.param2})
end end
minetest.swap_node(pos, {
name = "mesecons_delayer:delayer_on_"..tostring(i % 4 + 1),
param2 = node.param2
})
end, end,
delayer_time = delaytime,
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i), delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
sounds = default.node_sound_stone_defaults(),
mesecons = { mesecons = {
receptor = receptor =
{ {
@ -171,8 +156,12 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
action_off = delayer_deactivate action_off = delayer_deactivate
} }
}, },
on_blast = mesecon.on_blastnode, }
}) for k, v in pairs(def) do
on_state[k] = on_state[k] or v
end
minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), on_state)
end end
minetest.register_craft({ minetest.register_craft({