[mesecons_pistons] unify code style

This commit is contained in:
AFCMS 2021-05-23 11:17:19 +02:00
parent e75a2e3a67
commit c580c1ccad
1 changed files with 151 additions and 120 deletions

View File

@ -2,29 +2,36 @@ local S = minetest.get_translator("mesecons_pistons")
local PISTON_MAXIMUM_PUSH = 12
-- Get mesecon rules of pistons
local piston_rules =
{{x=0, y=0, z=1}, --everything apart from z- (pusher side)
--Get mesecon rules of pistons
--everything apart from z- (pusher side)
local piston_rules = {
{x=0, y=0, z=1},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=1, z=0},
{x=0, y=-1, z=0}}
{x=0, y=-1, z=0},
}
local piston_up_rules =
{{x=0, y=0, z=-1}, --everything apart from y+ (pusher side)
--everything apart from y+ (pusher side)
local piston_up_rules = {
{x=0, y=0, z=-1},
{x=0, y=0, z=1},
{x=-1, y=0, z=0},
{x=1, y=0, z=0},
{x=0, y=-1, z=0}}
{x=0, y=-1, z=0},
}
local piston_down_rules =
{{x=0, y=0, z=-1}, --everything apart from y- (pusher side)
--everything apart from y- (pusher side)
local piston_down_rules = {
{x=0, y=0, z=-1},
{x=0, y=0, z=1},
{x=-1, y=0, z=0},
{x=1, y=0, z=0},
{x=0, y=1, z=0}}
{x=0, y=1, z=0},
}
local piston_get_rules = function (node)
local function piston_get_rules(node)
local rules = piston_rules
for i = 1, node.param2 do
rules = mesecon.rotate_rules_left(rules)
@ -32,7 +39,7 @@ local piston_get_rules = function (node)
return rules
end
local piston_facedir_direction = function (node)
local function piston_facedir_direction(node)
local rules = {{x = 0, y = 0, z = -1}}
for i = 1, node.param2 do
rules = mesecon.rotate_rules_left(rules)
@ -40,7 +47,7 @@ local piston_facedir_direction = function (node)
return rules[1]
end
local piston_get_direction = function (dir, node)
local function piston_get_direction(dir, node)
if type(dir) == "function" then
return dir(node)
else
@ -50,7 +57,7 @@ end
-- Remove pusher of piston.
-- To be used when piston was destroyed or dug.
local piston_remove_pusher = function (pos, oldnode)
local function piston_remove_pusher(pos, oldnode)
local pistonspec = minetest.registered_nodes[oldnode.name].mesecons_piston
local dir = piston_get_direction(pistonspec.dir, oldnode)
@ -70,7 +77,7 @@ end
-- Remove base node of piston.
-- To be used when pusher was destroyed.
local piston_remove_base = function (pos, oldnode)
local function piston_remove_base(pos, oldnode)
local basenodename = minetest.registered_nodes[oldnode.name].corresponding_piston
local pistonspec = minetest.registered_nodes[basenodename].mesecons_piston
@ -89,7 +96,7 @@ local piston_remove_base = function (pos, oldnode)
end
end
local piston_on = function (pos, node)
local function piston_on(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
local dir = piston_get_direction(pistonspec.dir, node)
@ -113,7 +120,7 @@ local piston_on = function (pos, node)
end
end
local piston_off = function (pos, node)
local function piston_off(pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
minetest.swap_node(pos, {param2 = node.param2, name = pistonspec.offname})
piston_remove_pusher (pos, node)
@ -130,7 +137,7 @@ local piston_off = function (pos, node)
end
end
local piston_orientate = function (pos, placer)
local function piston_orientate(pos, placer)
mesecon.mvps_set_owner(pos, placer)
-- not placed by player
@ -158,14 +165,14 @@ local piston_pusher_box = {
fixed = {
{-2/16, -2/16, -.5 + pt, 2/16, 2/16, .5 + pt},
{-.5 , -.5 , -.5 , .5 , .5 , -.5 + pt},
}
},
}
local piston_on_box = {
type = "fixed",
fixed = {
{-.5, -.5, -.5 + pt, .5, .5, .5}
}
},
}
@ -196,17 +203,19 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
"mesecons_piston_back.png",
"mesecons_piston_pusher_front.png"
},
groups = {handy = 1, piston=1},
groups = {handy=1, piston=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
after_place_node = piston_orientate,
mesecons_piston = pistonspec_normal,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_get_rules
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = function(pos, node, user, mode)
@ -228,7 +237,7 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png"
},
groups = {handy=1, piston=1, not_in_creative_inventory = 1},
groups = {handy=1, piston=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -238,10 +247,12 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
selection_box = piston_on_box,
mesecons_piston = pistonspec_normal,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_get_rules
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -260,7 +271,7 @@ minetest.register_node("mesecons_pistons:piston_pusher_normal", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 1 },
groups = {piston_pusher=1},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -307,10 +318,12 @@ minetest.register_node("mesecons_pistons:piston_sticky_off", {
after_place_node = piston_orientate,
mesecons_piston = pistonspec_sticky,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_get_rules
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = function(pos, node, user, mode)
@ -332,7 +345,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png"
},
groups = {handy=1, piston=2, not_in_creative_inventory = 1},
groups = {handy=1, piston=2, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -342,10 +355,12 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
selection_box = piston_on_box,
mesecons_piston = pistonspec_sticky,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_get_rules
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -364,7 +379,7 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 2 },
groups = {piston_pusher=2},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -388,14 +403,14 @@ local piston_up_pusher_box = {
fixed = {
{-2/16, -.5 - pt, -2/16, 2/16, .5 - pt, 2/16},
{-.5 , .5 - pt, -.5 , .5 , .5 , .5},
}
},
}
local piston_up_on_box = {
type = "fixed",
fixed = {
{-.5, -.5, -.5 , .5, .5-pt, .5}
}
},
}
-- Normal
@ -404,7 +419,7 @@ local pistonspec_normal_up = {
offname = "mesecons_pistons:piston_up_normal_off",
onname = "mesecons_pistons:piston_up_normal_on",
dir = {x = 0, y = 1, z = 0},
pusher = "mesecons_pistons:piston_up_pusher_normal"
pusher = "mesecons_pistons:piston_up_pusher_normal",
}
-- offstate
@ -417,16 +432,18 @@ minetest.register_node("mesecons_pistons:piston_up_normal_off", {
"mesecons_piston_bottom.png",
"mesecons_piston_bottom.png",
},
groups = {handy=1, piston=1, not_in_creative_inventory = 1},
groups = {handy=1, piston=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_up,
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_up_rules,
}},
},
},
sounds = mcl_sounds.node_sound_stone_defaults({
footstep = mcl_sounds.node_sound_wood_defaults().footstep
}),
@ -452,7 +469,7 @@ minetest.register_node("mesecons_pistons:piston_up_normal_on", {
"mesecons_piston_bottom.png",
"mesecons_piston_bottom.png",
},
groups = {handy=1, piston_=1, not_in_creative_inventory = 1},
groups = {handy=1, piston_=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -462,10 +479,12 @@ minetest.register_node("mesecons_pistons:piston_up_normal_on", {
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_normal_up,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_up_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -484,7 +503,7 @@ minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 1 },
groups = {piston_pusher=1},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -507,7 +526,7 @@ local pistonspec_sticky_up = {
onname = "mesecons_pistons:piston_up_sticky_on",
dir = {x = 0, y = 1, z = 0},
pusher = "mesecons_pistons:piston_up_pusher_sticky",
sticky = true
sticky = true,
}
-- offstate
@ -520,7 +539,7 @@ minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
"mesecons_piston_bottom.png",
"mesecons_piston_bottom.png",
},
groups = {handy=1, piston=2, not_in_creative_inventory = 1},
groups = {handy=1, piston=2, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -529,10 +548,12 @@ minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
sounds = mcl_sounds.node_sound_stone_defaults({
footstep = mcl_sounds.node_sound_wood_defaults().footstep
}),
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_up_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = function(pos, node, user, mode)
@ -555,7 +576,7 @@ minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
"mesecons_piston_bottom.png",
"mesecons_piston_bottom.png",
},
groups = {handy=1, piston=2, not_in_creative_inventory = 1},
groups = {handy=1, piston=2, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -565,10 +586,12 @@ minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_sticky_up,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_up_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -587,7 +610,7 @@ minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 2 },
groups = {piston_pusher=2},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -611,14 +634,14 @@ local piston_down_pusher_box = {
fixed = {
{-2/16, -.5 + pt, -2/16, 2/16, .5 + pt, 2/16},
{-.5 , -.5 , -.5 , .5 , -.5 + pt, .5},
}
},
}
local piston_down_on_box = {
type = "fixed",
fixed = {
{-.5, -.5+pt, -.5 , .5, .5, .5}
}
},
}
@ -642,17 +665,19 @@ minetest.register_node("mesecons_pistons:piston_down_normal_off", {
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_bottom.png^[transformR180",
},
groups = {handy=1, piston=1, not_in_creative_inventory = 1},
groups = {handy=1, piston=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_down,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_down_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = function(pos, node, user, mode)
@ -675,7 +700,7 @@ minetest.register_node("mesecons_pistons:piston_down_normal_on", {
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_bottom.png^[transformR180",
},
groups = {handy=1, piston=1, not_in_creative_inventory = 1},
groups = {handy=1, piston=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -685,10 +710,12 @@ minetest.register_node("mesecons_pistons:piston_down_normal_on", {
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_normal_down,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_down_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -707,7 +734,7 @@ minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 1 },
groups = {piston_pusher=1},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -727,7 +754,7 @@ local pistonspec_sticky_down = {
offname = "mesecons_pistons:piston_down_sticky_off",
dir = {x = 0, y = -1, z = 0},
pusher = "mesecons_pistons:piston_down_pusher_sticky",
sticky = true
sticky = true,
}
-- offstate
@ -747,10 +774,12 @@ minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
drop = "mesecons_pistons:piston_sticky_off",
mesecons_piston = pistonspec_sticky_down,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_on = piston_on,
rules = piston_down_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = function(pos, node, user, mode)
@ -773,7 +802,7 @@ minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_bottom.png^[transformR180",
},
groups = {handy=1, piston=1, not_in_creative_inventory = 1},
groups = {handy=1, piston=1, not_in_creative_inventory=1},
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
@ -783,10 +812,12 @@ minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_sticky_down,
sounds = mcl_sounds.node_sound_stone_defaults(),
mesecons = {effector={
mesecons = {
effector = {
action_off = piston_off,
rules = piston_down_rules,
}},
},
},
_mcl_blast_resistance = 0.5,
_mcl_hardness = 0.5,
on_rotate = false,
@ -805,7 +836,7 @@ minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
},
paramtype = "light",
paramtype2 = "facedir",
groups = { piston_pusher = 2 },
groups = {piston_pusher=2},
is_ground_content = false,
after_destruct = piston_remove_base,
diggable = false,
@ -839,7 +870,7 @@ minetest.register_craft({
{"group:wood", "group:wood", "group:wood"},
{"mcl_core:cobble", "mcl_core:iron_ingot", "mcl_core:cobble"},
{"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble"},
}
},
})
minetest.register_craft({
@ -847,7 +878,7 @@ minetest.register_craft({
recipe = {
{"mcl_mobitems:slimeball"},
{"mesecons_pistons:piston_normal_off"},
}
},
})
-- Add entry aliases for the Help