forked from VoxeLibre/VoxeLibre
[mesecons_pistons] unify code style
This commit is contained in:
parent
e75a2e3a67
commit
c580c1ccad
|
@ -3,28 +3,35 @@ 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)
|
||||
|
||||
--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}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -203,10 +210,12 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
|
|||
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)
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -423,10 +438,12 @@ minetest.register_node("mesecons_pistons:piston_up_normal_off", {
|
|||
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
|
||||
}),
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
@ -649,10 +672,12 @@ minetest.register_node("mesecons_pistons:piston_down_normal_off", {
|
|||
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)
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue