mirror of
https://github.com/minetest-mods/mesecons.git
synced 2025-01-12 09:50:23 +01:00
Make some fixes to movement and rotation (#584)
This commit is contained in:
parent
dfa43d6c0c
commit
960b7c4915
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
mesecon.on_placenode = function(pos, node)
|
mesecon.on_placenode = function(pos, node)
|
||||||
mesecon.execute_autoconnect_hooks_now(pos, node)
|
mesecon.execute_autoconnect_hooks_now(pos, node)
|
||||||
|
node = minetest.get_node(pos) -- Update the node in case it was just changed.
|
||||||
|
|
||||||
-- Receptors: Send on signal when active
|
-- Receptors: Send on signal when active
|
||||||
if mesecon.is_receptor_on(node.name) then
|
if mesecon.is_receptor_on(node.name) then
|
||||||
@ -11,18 +12,20 @@ mesecon.on_placenode = function(pos, node)
|
|||||||
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
||||||
-- if placed conductor is an onstate one
|
-- if placed conductor is an onstate one
|
||||||
if mesecon.is_conductor(node.name) then
|
if mesecon.is_conductor(node.name) then
|
||||||
|
local conductor = mesecon.get_conductor(node.name)
|
||||||
|
if conductor.state ~= mesecon.state.off then
|
||||||
|
-- Turn the conductor off.
|
||||||
|
node.name = conductor.offstate or conductor.states[1]
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
local sources = mesecon.is_powered(pos)
|
local sources = mesecon.is_powered(pos)
|
||||||
if sources then
|
if sources then
|
||||||
-- also call receptor_on if itself is powered already, so that neighboring
|
mesecon.vm_begin()
|
||||||
-- conductors will be activated (when pushing an on-conductor with a piston)
|
|
||||||
for _, s in ipairs(sources) do
|
for _, s in ipairs(sources) do
|
||||||
local rule = vector.subtract(s, pos)
|
local rule = vector.subtract(s, pos)
|
||||||
mesecon.turnon(pos, rule)
|
mesecon.turnon(pos, rule)
|
||||||
end
|
end
|
||||||
--mesecon.receptor_on (pos, mesecon.conductor_get_rules(node))
|
mesecon.vm_commit()
|
||||||
elseif mesecon.is_conductor_on(node) then
|
|
||||||
node.name = mesecon.get_conductor_off(node)
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,6 +6,24 @@ function mesecon.move_node(pos, newpos)
|
|||||||
minetest.get_meta(pos):from_table(meta)
|
minetest.get_meta(pos):from_table(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- An on_rotate callback for mesecons components.
|
||||||
|
function mesecon.on_rotate(pos, node, _, _, new_param2)
|
||||||
|
local new_node = {name = node.name, param1 = node.param1, param2 = new_param2}
|
||||||
|
minetest.swap_node(pos, new_node)
|
||||||
|
mesecon.on_dignode(pos, node)
|
||||||
|
mesecon.on_placenode(pos, new_node)
|
||||||
|
minetest.check_for_falling(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- An on_rotate callback for components which stay horizontal.
|
||||||
|
function mesecon.on_rotate_horiz(pos, node, user, mode, new_param2)
|
||||||
|
if not minetest.global_exists("screwdriver") or mode ~= screwdriver.ROTATE_FACE then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return mesecon.on_rotate(pos, node, user, mode, new_param2)
|
||||||
|
end
|
||||||
|
|
||||||
-- Rules rotation Functions:
|
-- Rules rotation Functions:
|
||||||
function mesecon.rotate_rules_right(rules)
|
function mesecon.rotate_rules_right(rules)
|
||||||
local nr = {}
|
local nr = {}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
local screwdriver_exists = minetest.global_exists("screwdriver")
|
|
||||||
|
|
||||||
local corner_selectionbox = {
|
local corner_selectionbox = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = { -16/32, -16/32, -16/32, 5/32, -12/32, 5/32 },
|
fixed = { -16/32, -16/32, -16/32, 5/32, -12/32, 5/32 },
|
||||||
@ -40,7 +38,7 @@ minetest.register_node("mesecons_extrawires:corner_on", {
|
|||||||
offstate = "mesecons_extrawires:corner_off"
|
offstate = "mesecons_extrawires:corner_off"
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_extrawires:corner_off", {
|
minetest.register_node("mesecons_extrawires:corner_off", {
|
||||||
@ -66,7 +64,7 @@ minetest.register_node("mesecons_extrawires:corner_off", {
|
|||||||
onstate = "mesecons_extrawires:corner_on"
|
onstate = "mesecons_extrawires:corner_on"
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
local rotate
|
|
||||||
if minetest.global_exists("screwdriver") then rotate = screwdriver.rotate_simple end
|
|
||||||
|
|
||||||
local doublecorner_selectionbox = {
|
local doublecorner_selectionbox = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
||||||
@ -69,7 +66,7 @@ for k, state in ipairs(doublecorner_states) do
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = rotate,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
name = mesecons_extrawires
|
name = mesecons_extrawires
|
||||||
depends = mesecons, mesecons_gamecompat
|
depends = mesecons, mesecons_gamecompat
|
||||||
optional_depends = screwdriver
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
local screwdriver_exists = minetest.global_exists("screwdriver")
|
|
||||||
|
|
||||||
local tjunction_nodebox = {
|
local tjunction_nodebox = {
|
||||||
type = "fixed",
|
type = "fixed",
|
||||||
-- ±0.001 is to prevent z-fighting
|
-- ±0.001 is to prevent z-fighting
|
||||||
@ -52,7 +50,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
|
|||||||
offstate = "mesecons_extrawires:tjunction_off"
|
offstate = "mesecons_extrawires:tjunction_off"
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_extrawires:tjunction_off", {
|
minetest.register_node("mesecons_extrawires:tjunction_off", {
|
||||||
@ -82,7 +80,7 @@ minetest.register_node("mesecons_extrawires:tjunction_off", {
|
|||||||
onstate = "mesecons_extrawires:tjunction_on"
|
onstate = "mesecons_extrawires:tjunction_on"
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -84,6 +84,7 @@ local function register_gate(name, inputnumber, assess, recipe, description)
|
|||||||
offstate = basename.."_off",
|
offstate = basename.."_off",
|
||||||
inputnumber = inputnumber,
|
inputnumber = inputnumber,
|
||||||
after_dig_node = mesecon.do_cooldown,
|
after_dig_node = mesecon.do_cooldown,
|
||||||
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
},{
|
},{
|
||||||
tiles = {
|
tiles = {
|
||||||
"jeija_microcontroller_bottom.png^".."jeija_gate_off.png^"..
|
"jeija_microcontroller_bottom.png^".."jeija_gate_off.png^"..
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
local screwdriver_exists = minetest.global_exists("screwdriver")
|
|
||||||
|
|
||||||
local function insulated_wire_get_rules(node)
|
local function insulated_wire_get_rules(node)
|
||||||
local rules = {{x = 1, y = 0, z = 0},
|
local rules = {{x = 1, y = 0, z = 0},
|
||||||
{x =-1, y = 0, z = 0}}
|
{x =-1, y = 0, z = 0}}
|
||||||
@ -43,7 +41,7 @@ minetest.register_node("mesecons_insulated:insulated_on", {
|
|||||||
rules = insulated_wire_get_rules
|
rules = insulated_wire_get_rules
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("mesecons_insulated:insulated_off", {
|
minetest.register_node("mesecons_insulated:insulated_off", {
|
||||||
@ -79,7 +77,7 @@ minetest.register_node("mesecons_insulated:insulated_off", {
|
|||||||
rules = insulated_wire_get_rules
|
rules = insulated_wire_get_rules
|
||||||
}},
|
}},
|
||||||
on_blast = mesecon.on_blastnode,
|
on_blast = mesecon.on_blastnode,
|
||||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
on_rotate = mesecon.on_rotate_horiz,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
name = mesecons_insulated
|
name = mesecons_insulated
|
||||||
depends = mesecons, mesecons_gamecompat
|
depends = mesecons, mesecons_gamecompat
|
||||||
optional_depends = screwdriver
|
|
||||||
|
@ -220,6 +220,8 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
|||||||
minetest.remove_node(n.pos)
|
minetest.remove_node(n.pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local oldstack = mesecon.tablecopy(nodes)
|
||||||
|
|
||||||
-- update mesecons for removed nodes ( has to be done after all nodes have been removed )
|
-- update mesecons for removed nodes ( has to be done after all nodes have been removed )
|
||||||
for _, n in ipairs(nodes) do
|
for _, n in ipairs(nodes) do
|
||||||
mesecon.on_dignode(n.pos, n.node)
|
mesecon.on_dignode(n.pos, n.node)
|
||||||
@ -229,6 +231,12 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
|||||||
for _, n in ipairs(nodes) do
|
for _, n in ipairs(nodes) do
|
||||||
local np = vector.add(n.pos, movedir)
|
local np = vector.add(n.pos, movedir)
|
||||||
|
|
||||||
|
-- Turn off conductors in transit
|
||||||
|
local conductor = mesecon.get_conductor(n.node.name)
|
||||||
|
if conductor and conductor.state ~= mesecon.state.off then
|
||||||
|
n.node.name = conductor.offstate or conductor.states[1]
|
||||||
|
end
|
||||||
|
|
||||||
minetest.set_node(np, n.node)
|
minetest.set_node(np, n.node)
|
||||||
minetest.get_meta(np):from_table(n.meta)
|
minetest.get_meta(np):from_table(n.meta)
|
||||||
if n.node_timer then
|
if n.node_timer then
|
||||||
@ -237,7 +245,6 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
|||||||
end
|
end
|
||||||
|
|
||||||
local moved_nodes = {}
|
local moved_nodes = {}
|
||||||
local oldstack = mesecon.tablecopy(nodes)
|
|
||||||
for i in ipairs(nodes) do
|
for i in ipairs(nodes) do
|
||||||
moved_nodes[i] = {}
|
moved_nodes[i] = {}
|
||||||
moved_nodes[i].oldpos = nodes[i].pos
|
moved_nodes[i].oldpos = nodes[i].pos
|
||||||
|
@ -209,8 +209,10 @@ function mesecon.receiver_place(rcpt_pos)
|
|||||||
local param2 = minetest.dir_to_facedir(minetest.facedir_to_dir(node.param2))
|
local param2 = minetest.dir_to_facedir(minetest.facedir_to_dir(node.param2))
|
||||||
|
|
||||||
if string.find(nn.name, "mesecons:wire_") ~= nil then
|
if string.find(nn.name, "mesecons:wire_") ~= nil then
|
||||||
minetest.set_node(pos, {name = rcvtype, param2 = param2})
|
local rcv_node = {name = rcvtype, param2 = param2}
|
||||||
mesecon.on_placenode(pos, nn)
|
minetest.set_node(pos, rcv_node)
|
||||||
|
mesecon.on_dignode(pos, nn)
|
||||||
|
mesecon.on_placenode(pos, rcv_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -220,6 +222,7 @@ function mesecon.receiver_remove(rcpt_pos, dugnode)
|
|||||||
if string.find(nn.name, "mesecons_receiver:receiver_") ~= nil then
|
if string.find(nn.name, "mesecons_receiver:receiver_") ~= nil then
|
||||||
local node = {name = "mesecons:wire_00000000_off"}
|
local node = {name = "mesecons:wire_00000000_off"}
|
||||||
minetest.set_node(pos, node)
|
minetest.set_node(pos, node)
|
||||||
|
mesecon.on_dignode(pos, nn)
|
||||||
mesecon.on_placenode(pos, node)
|
mesecon.on_placenode(pos, node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -257,7 +260,13 @@ minetest.register_on_placenode(function (pos, node)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mesecon.buttonlike_onrotate(pos, node)
|
function mesecon.buttonlike_onrotate(pos, node, _, _, new_param2)
|
||||||
minetest.after(0, mesecon.receiver_remove, pos, node)
|
local new_node = {name = node.name, param1 = node.param1, param2 = new_param2}
|
||||||
minetest.after(0, mesecon.receiver_place, pos)
|
minetest.swap_node(pos, new_node)
|
||||||
|
mesecon.receiver_remove(pos, node)
|
||||||
|
mesecon.on_dignode(pos, node)
|
||||||
|
mesecon.on_placenode(pos, new_node)
|
||||||
|
mesecon.receiver_place(pos)
|
||||||
|
minetest.check_for_falling(pos)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user