Compare commits

...

2 Commits
master ... next

1 changed files with 56 additions and 445 deletions

View File

@ -1,63 +1,62 @@
-- Get mesecon rules of pistons
piston_rules =
{{x=0, y=0, z=1}, --everything apart from z- (pusher side)
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=1, y=1, z=0},
{x=1, y=-1, z=0},
{x=-1, y=1, z=0},
{x=-1, y=-1, z=0},
{x=0, y=1, z=1},
{x=0, y=-1, z=1}}
local piston_rules =
{{x = 0, z = 0, y = 1}, -- everything apart from pusher side
{x = 1, z = 0, y = 1},
{x = 1, z = 1, y = 1},
{x = 0, z = 1, y = 1},
{x =-1, z = 0, y = 1},
{x =-1, z =-1, y = 1},
{x = 0, z =-1, y = 1},
{x = 1, z =-1, y = 1},
{x =-1, z = 1, y = 1},
local piston_up_rules =
{{x=0, y=0, z=-1}, --everything apart from y+ (pusher side)
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=0, z=1},
{x=1, y=-1, z=0},
{x=-1, y=-1, z=0},
{x=0, y=-1, z=1},
{x=0, y=-1, z=-1}}
{x = 1, z = 0, y = 0},
{x = 1, z = 1, y = 0},
{x = 0, z = 1, y = 0},
{x =-1, z = 0, y = 0},
{x =-1, z =-1, y = 0},
--{x = 0, z =-1, y = 0}, pusher side --> disabled
{x = 1, z =-1, y = 0},
{x =-1, z = 1, y = 0},
local piston_down_rules =
{{x=0, y=0, z=-1}, --everything apart from y- (pusher side)
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=0, z=1},
{x=1, y=1, z=0},
{x=-1, y=1, z=0},
{x=0, y=1, z=1},
{x=0, y=1, z=-1}}
{x = 0, z = 0, y =-1},
{x = 1, z = 0, y =-1},
{x = 1, z = 1, y =-1},
{x = 0, z = 1, y =-1},
{x =-1, z = 0, y =-1},
{x =-1, z =-1, y =-1},
{x = 0, z =-1, y =-1},
{x = 1, z =-1, y =-1},
{x =-1, z = 1, y =-1}}
local piston_get_rules = function (node)
local rules = piston_rules
for i = 1, node.param2 do
local piston_rotate_rules = function(param2, rules)
if param2 == 4 then
return mesecon:rotate_rules_up(mesecon:rotate_rules_left(rules))
end -- face up
if param2 == 6 then
return mesecon:rotate_rules_down(mesecon:rotate_rules_left(rules))
end -- face up
rules = mesecon:rotate_rules_down(rules)
for i = 1, param2 do
rules = mesecon:rotate_rules_left(rules)
end
return rules
end
piston_facedir_direction = function (node)
local rules = {{x = 0, y = 0, z = -1}}
for i = 1, node.param2 do
rules = mesecon:rotate_rules_left(rules)
end
return rules[1]
local piston_get_rules = function (node)
return piston_rotate_rules(node.param2, piston_rules)
end
piston_get_direction = function (dir, node)
if type(dir) == "function" then
return dir(node)
else
return dir
end
piston_facedir_direction = function (node)
local rules = piston_rotate_rules(node.param2, {{x = 0, y = 0, z =-1}})
return rules[1]
end
local piston_remove_pusher = function (pos, node)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node)
dir = piston_facedir_direction(node)
local pusherpos = mesecon:addPosRule(pos, dir)
local pushername = minetest.env:get_node(pusherpos).name
@ -70,7 +69,7 @@ end
local piston_on = function (pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node)
dir = piston_facedir_direction(node)
local np = mesecon:addPosRule(pos, dir)
success, stack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
if success then
@ -86,7 +85,7 @@ local piston_off = function (pos, node)
piston_remove_pusher (pos, node)
if pistonspec.sticky then
dir = piston_get_direction(pistonspec.dir, node)
dir = piston_facedir_direction(node)
pullpos = mesecon:addPosRule(pos, dir)
stack = mesecon:mvps_pull_single(pullpos, dir)
mesecon:mvps_process_stack(stack)
@ -101,16 +100,20 @@ local piston_orientate = function (pos, placer)
local pitch = placer:get_look_pitch() * (180 / math.pi)
local node = minetest.env:get_node(pos)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
if pitch > 55 then --looking upwards
minetest.env:add_node(pos, {name=pistonspec.piston_down})
elseif pitch < -55 then --looking downwards
minetest.env:add_node(pos, {name=pistonspec.piston_up})
if pitch > 55 then --looking upwards --> face down
minetest.env:set_node(pos, {name = node.name, param2 = 6})
elseif pitch < -55 then --looking downwards --> face up
minetest.env:set_node(pos, {name = node.name, param2 = 4})
end
end
--
--
-- Node Registration
--
--
-- Horizontal pistons
local pt = 3/16 -- pusher thickness
@ -135,7 +138,6 @@ local piston_on_box = {
local pistonspec_normal = {
offname = "mesecons_pistons:piston_normal_off",
onname = "mesecons_pistons:piston_normal_on",
dir = piston_facedir_direction,
pusher = "mesecons_pistons:piston_pusher_normal",
piston_down = "mesecons_pistons:piston_down_normal_off",
piston_up = "mesecons_pistons:piston_up_normal_off",
@ -215,7 +217,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_normal", {
local pistonspec_sticky = {
offname = "mesecons_pistons:piston_sticky_off",
onname = "mesecons_pistons:piston_sticky_on",
dir = piston_facedir_direction,
pusher = "mesecons_pistons:piston_pusher_sticky",
sticky = true,
piston_down = "mesecons_pistons:piston_down_sticky_off",
@ -291,372 +292,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
node_box = piston_pusher_box,
})
--
--
-- UP
--
--
local piston_up_pusher_box = {
type = "fixed",
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
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"
}
-- offstate
minetest.register_node("mesecons_pistons:piston_up_normal_off", {
tiles = {
"mesecons_piston_pusher_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_up,
mesecons = {effector={
action_on = piston_on,
rules = piston_up_rules,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_up_normal_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_on_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_up_on_box,
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_normal_up,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_off = piston_off,
rules = piston_up_rules,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_front.png",
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_left.png^[transformR270",
"mesecons_piston_pusher_right.png^[transformR90",
"mesecons_piston_pusher_bottom.png",
"mesecons_piston_pusher_top.png^[transformR180",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_up_normal_on",
selection_box = piston_up_pusher_box,
node_box = piston_up_pusher_box,
})
-- Sticky
local pistonspec_sticky_up = {
offname = "mesecons_pistons:piston_up_sticky_off",
onname = "mesecons_pistons:piston_up_sticky_on",
dir = {x = 0, y = 1, z = 0},
pusher = "mesecons_pistons:piston_up_pusher_sticky",
sticky = true
}
-- offstate
minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
tiles = {
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
"mesecons_piston_tb.png"
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
mesecons_piston = pistonspec_sticky_up,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_on = piston_on,
rules = piston_up_rules,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_on_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_up_on_box,
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_sticky_up,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_off = piston_off,
rules = piston_up_rules,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_left.png^[transformR270",
"mesecons_piston_pusher_right.png^[transformR90",
"mesecons_piston_pusher_bottom.png",
"mesecons_piston_pusher_top.png^[transformR180",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_up_sticky_on",
selection_box = piston_up_pusher_box,
node_box = piston_up_pusher_box,
})
--
--
-- DOWN
--
--
local piston_down_pusher_box = {
type = "fixed",
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}
}
}
-- Normal
local pistonspec_normal_down = {
offname = "mesecons_pistons:piston_down_normal_off",
onname = "mesecons_pistons:piston_down_normal_on",
dir = {x = 0, y = -1, z = 0},
pusher = "mesecons_pistons:piston_down_pusher_normal",
}
-- offstate
minetest.register_node("mesecons_pistons:piston_down_normal_off", {
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_pusher_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_down,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_on = piston_on,
rules = piston_down_rules,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_down_normal_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_down_on_box,
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_normal_down,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_off = piston_off,
rules = piston_down_rules,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_front.png",
"mesecons_piston_pusher_left.png^[transformR90",
"mesecons_piston_pusher_right.png^[transformR270",
"mesecons_piston_pusher_bottom.png^[transformR180",
"mesecons_piston_pusher_top.png",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_down_normal_on",
selection_box = piston_down_pusher_box,
node_box = piston_down_pusher_box,
})
-- Sticky
local pistonspec_sticky_down = {
onname = "mesecons_pistons:piston_down_sticky_on",
offname = "mesecons_pistons:piston_down_sticky_off",
dir = {x = 0, y = -1, z = 0},
pusher = "mesecons_pistons:piston_down_pusher_sticky",
sticky = true
}
-- offstate
minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
mesecons_piston = pistonspec_sticky_down,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_on = piston_on,
rules = piston_down_rules,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
after_dig_node = piston_remove_pusher,
node_box = piston_down_on_box,
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_sticky_down,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={
action_off = piston_off,
rules = piston_down_rules,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_pusher_left.png^[transformR90",
"mesecons_piston_pusher_right.png^[transformR270",
"mesecons_piston_pusher_bottom.png^[transformR180",
"mesecons_piston_pusher_top.png",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_down_sticky_on",
selection_box = piston_down_pusher_box,
node_box = piston_down_pusher_box,
})
-- Register pushers as stoppers if they would be seperated from the piston
local piston_pusher_get_stopper = function (node, dir, stack, stackid)
if (stack[stackid + 1]
@ -683,27 +318,9 @@ end
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky", piston_pusher_up_down_get_stopper)
-- Register pistons as stoppers if they would be seperated from the stopper
local piston_up_down_get_stopper = function (node, dir, stack, stackid)
if (stack[stackid + 1]
and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher)
or (stack[stackid - 1]
and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher) then
return false
end
return true
end
local piston_get_stopper = function (node, dir, stack, stackid)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node)
dir = piston_facedir_direction(node)
local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
local pushernode = minetest.env:get_node(pusherpos)
@ -721,12 +338,6 @@ end
mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_normal_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_sticky_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_normal_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_up_down_get_stopper)
--craft recipes
minetest.register_craft({
output = 'mesecons_pistons:piston_normal_off 2',