mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-24 17:30:19 +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.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
|
||||
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
|
||||
-- if placed conductor is an onstate one
|
||||
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)
|
||||
if sources then
|
||||
-- also call receptor_on if itself is powered already, so that neighboring
|
||||
-- conductors will be activated (when pushing an on-conductor with a piston)
|
||||
mesecon.vm_begin()
|
||||
for _, s in ipairs(sources) do
|
||||
local rule = vector.subtract(s, pos)
|
||||
mesecon.turnon(pos, rule)
|
||||
end
|
||||
--mesecon.receptor_on (pos, mesecon.conductor_get_rules(node))
|
||||
elseif mesecon.is_conductor_on(node) then
|
||||
node.name = mesecon.get_conductor_off(node)
|
||||
minetest.swap_node(pos, node)
|
||||
mesecon.vm_commit()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -6,6 +6,24 @@ function mesecon.move_node(pos, newpos)
|
||||
minetest.get_meta(pos):from_table(meta)
|
||||
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:
|
||||
function mesecon.rotate_rules_right(rules)
|
||||
local nr = {}
|
||||
|
@ -1,5 +1,3 @@
|
||||
local screwdriver_exists = minetest.global_exists("screwdriver")
|
||||
|
||||
local corner_selectionbox = {
|
||||
type = "fixed",
|
||||
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"
|
||||
}},
|
||||
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", {
|
||||
@ -66,7 +64,7 @@ minetest.register_node("mesecons_extrawires:corner_off", {
|
||||
onstate = "mesecons_extrawires:corner_on"
|
||||
}},
|
||||
on_blast = mesecon.on_blastnode,
|
||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
||||
on_rotate = mesecon.on_rotate_horiz,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -1,6 +1,3 @@
|
||||
local rotate
|
||||
if minetest.global_exists("screwdriver") then rotate = screwdriver.rotate_simple end
|
||||
|
||||
local doublecorner_selectionbox = {
|
||||
type = "fixed",
|
||||
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_rotate = rotate,
|
||||
on_rotate = mesecon.on_rotate_horiz,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
name = mesecons_extrawires
|
||||
depends = mesecons, mesecons_gamecompat
|
||||
optional_depends = screwdriver
|
||||
|
@ -1,5 +1,3 @@
|
||||
local screwdriver_exists = minetest.global_exists("screwdriver")
|
||||
|
||||
local tjunction_nodebox = {
|
||||
type = "fixed",
|
||||
-- ±0.001 is to prevent z-fighting
|
||||
@ -52,7 +50,7 @@ minetest.register_node("mesecons_extrawires:tjunction_on", {
|
||||
offstate = "mesecons_extrawires:tjunction_off"
|
||||
}},
|
||||
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", {
|
||||
@ -82,7 +80,7 @@ minetest.register_node("mesecons_extrawires:tjunction_off", {
|
||||
onstate = "mesecons_extrawires:tjunction_on"
|
||||
}},
|
||||
on_blast = mesecon.on_blastnode,
|
||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
||||
on_rotate = mesecon.on_rotate_horiz,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -84,6 +84,7 @@ local function register_gate(name, inputnumber, assess, recipe, description)
|
||||
offstate = basename.."_off",
|
||||
inputnumber = inputnumber,
|
||||
after_dig_node = mesecon.do_cooldown,
|
||||
on_rotate = mesecon.on_rotate_horiz,
|
||||
},{
|
||||
tiles = {
|
||||
"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 rules = {{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
|
||||
}},
|
||||
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", {
|
||||
@ -79,7 +77,7 @@ minetest.register_node("mesecons_insulated:insulated_off", {
|
||||
rules = insulated_wire_get_rules
|
||||
}},
|
||||
on_blast = mesecon.on_blastnode,
|
||||
on_rotate = screwdriver_exists and screwdriver.rotate_simple,
|
||||
on_rotate = mesecon.on_rotate_horiz,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -1,3 +1,2 @@
|
||||
name = mesecons_insulated
|
||||
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)
|
||||
end
|
||||
|
||||
local oldstack = mesecon.tablecopy(nodes)
|
||||
|
||||
-- update mesecons for removed nodes ( has to be done after all nodes have been removed )
|
||||
for _, n in ipairs(nodes) do
|
||||
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
|
||||
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.get_meta(np):from_table(n.meta)
|
||||
if n.node_timer then
|
||||
@ -237,7 +245,6 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
|
||||
end
|
||||
|
||||
local moved_nodes = {}
|
||||
local oldstack = mesecon.tablecopy(nodes)
|
||||
for i in ipairs(nodes) do
|
||||
moved_nodes[i] = {}
|
||||
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))
|
||||
|
||||
if string.find(nn.name, "mesecons:wire_") ~= nil then
|
||||
minetest.set_node(pos, {name = rcvtype, param2 = param2})
|
||||
mesecon.on_placenode(pos, nn)
|
||||
local rcv_node = {name = rcvtype, param2 = param2}
|
||||
minetest.set_node(pos, rcv_node)
|
||||
mesecon.on_dignode(pos, nn)
|
||||
mesecon.on_placenode(pos, rcv_node)
|
||||
end
|
||||
end
|
||||
|
||||
@ -220,6 +222,7 @@ function mesecon.receiver_remove(rcpt_pos, dugnode)
|
||||
if string.find(nn.name, "mesecons_receiver:receiver_") ~= nil then
|
||||
local node = {name = "mesecons:wire_00000000_off"}
|
||||
minetest.set_node(pos, node)
|
||||
mesecon.on_dignode(pos, nn)
|
||||
mesecon.on_placenode(pos, node)
|
||||
end
|
||||
end
|
||||
@ -257,7 +260,13 @@ minetest.register_on_placenode(function (pos, node)
|
||||
end
|
||||
end)
|
||||
|
||||
function mesecon.buttonlike_onrotate(pos, node)
|
||||
minetest.after(0, mesecon.receiver_remove, pos, node)
|
||||
minetest.after(0, mesecon.receiver_place, pos)
|
||||
function mesecon.buttonlike_onrotate(pos, node, _, _, new_param2)
|
||||
local new_node = {name = node.name, param1 = node.param1, param2 = new_param2}
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user