mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-25 02:00:37 +01:00
Updated mesecons and pipeworks
- Added security on devices from pipeworks (breaker,placer) - Added new mod in mesecons : mesecons_stickyblocks
This commit is contained in:
parent
fee70f8fc3
commit
a6bfdd377c
@ -31,6 +31,14 @@ mesecon.rules.flat =
|
|||||||
{x = 0, y = 0, z = 1},
|
{x = 0, y = 0, z = 1},
|
||||||
{x = 0, y = 0, z =-1}}
|
{x = 0, y = 0, z =-1}}
|
||||||
|
|
||||||
|
mesecon.rules.alldirs =
|
||||||
|
{{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= 0, z= 1},
|
||||||
|
{x= 0, y= 0, z=-1}}
|
||||||
|
|
||||||
mesecon.rules.buttonlike_get = function(node)
|
mesecon.rules.buttonlike_get = function(node)
|
||||||
local rules = mesecon.rules.buttonlike
|
local rules = mesecon.rules.buttonlike
|
||||||
if node.param2 == 2 then
|
if node.param2 == 2 then
|
||||||
|
@ -135,8 +135,12 @@ end
|
|||||||
|
|
||||||
-- returns true if player was found, false if not
|
-- returns true if player was found, false if not
|
||||||
local node_detector_scan = function (pos)
|
local node_detector_scan = function (pos)
|
||||||
local node = minetest.get_node(pos)
|
if not pos then return end
|
||||||
local frontpos = vector.subtract(pos, minetest.facedir_to_dir(node.param2))
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if not node then return end
|
||||||
|
local scandir = minetest.facedir_to_dir(node.param2)
|
||||||
|
if not scandir then return end
|
||||||
|
local frontpos = vector.subtract(pos, scandir)
|
||||||
local frontnode = minetest.get_node(frontpos)
|
local frontnode = minetest.get_node(frontpos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
return (frontnode.name == meta:get_string("scanname")) or
|
return (frontnode.name == meta:get_string("scanname")) or
|
||||||
|
@ -19,7 +19,6 @@ function mesecon.is_mvps_stopper(node, pushdir, stack, stackid)
|
|||||||
if type (get_stopper) == "function" then
|
if type (get_stopper) == "function" then
|
||||||
get_stopper = get_stopper(node, pushdir, stack, stackid)
|
get_stopper = get_stopper(node, pushdir, stack, stackid)
|
||||||
end
|
end
|
||||||
if (get_stopper) then print(node.name) end
|
|
||||||
return get_stopper
|
return get_stopper
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,27 +47,76 @@ function mesecon.mvps_process_stack(stack)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon.mvps_get_stack(pos, dir, maximum)
|
function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky)
|
||||||
-- determine the number of nodes to be pushed
|
-- determine the number of nodes to be pushed
|
||||||
local np = {x = pos.x, y = pos.y, z = pos.z}
|
|
||||||
local nodes = {}
|
local nodes = {}
|
||||||
while true do
|
local frontiers = {pos}
|
||||||
local nn = minetest.get_node_or_nil(np)
|
|
||||||
if not nn or #nodes > maximum then
|
|
||||||
-- don't push at all, something is in the way (unloaded map or too many nodes)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if nn.name == "air"
|
while #frontiers > 0 do
|
||||||
or (minetest.registered_nodes[nn.name]
|
local np = frontiers[1]
|
||||||
and minetest.registered_nodes[nn.name].liquidtype ~= "none") then --is liquid
|
local nn = minetest.get_node(np)
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if nn.name ~= "air"
|
||||||
|
and minetest.registered_nodes[nn.name]
|
||||||
|
and minetest.registered_nodes[nn.name].liquidtype == "none" then
|
||||||
table.insert(nodes, {node = nn, pos = np})
|
table.insert(nodes, {node = nn, pos = np})
|
||||||
|
if #nodes > maximum then return nil end
|
||||||
|
|
||||||
np = mesecon.addPosRule(np, dir)
|
-- add connected nodes to frontiers, connected is a vector list
|
||||||
|
-- the vectors must be absolute positions
|
||||||
|
local connected = {}
|
||||||
|
if minetest.registered_nodes[nn.name]
|
||||||
|
and minetest.registered_nodes[nn.name].mvps_sticky then
|
||||||
|
connected = minetest.registered_nodes[nn.name].mvps_sticky(np, nn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
table.insert(connected, vector.add(np, dir))
|
||||||
|
|
||||||
|
-- If adjacent node is sticky block and connects add that
|
||||||
|
-- position to the connected table
|
||||||
|
for _, r in ipairs(mesecon.rules.alldirs) do
|
||||||
|
local adjpos = vector.add(np, r)
|
||||||
|
local adjnode = minetest.get_node(adjpos)
|
||||||
|
if minetest.registered_nodes[adjnode.name]
|
||||||
|
and minetest.registered_nodes[adjnode.name].mvps_sticky then
|
||||||
|
local sticksto = minetest.registered_nodes[adjnode.name]
|
||||||
|
.mvps_sticky(adjpos, adjnode)
|
||||||
|
|
||||||
|
-- connects to this position?
|
||||||
|
for _, link in ipairs(sticksto) do
|
||||||
|
if vector.equals(link, np) then
|
||||||
|
table.insert(connected, adjpos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if all_pull_sticky then
|
||||||
|
table.insert(connected, vector.subtract(np, dir))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Make sure there are no duplicates in frontiers / nodes before
|
||||||
|
-- adding nodes in "connected" to frontiers
|
||||||
|
for _, cp in ipairs(connected) do
|
||||||
|
local duplicate = false
|
||||||
|
for _, rp in ipairs(nodes) do
|
||||||
|
if vector.equals(cp, rp.pos) then
|
||||||
|
duplicate = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _, fp in ipairs(frontiers) do
|
||||||
|
if vector.equals(cp, fp) then
|
||||||
|
duplicate = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not duplicate then
|
||||||
|
table.insert(frontiers, cp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.remove(frontiers, 1)
|
||||||
|
end
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -77,11 +125,19 @@ function mesecon.mvps_push(pos, dir, maximum)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mesecon.mvps_pull_all(pos, dir, maximum)
|
function mesecon.mvps_pull_all(pos, dir, maximum)
|
||||||
|
return mesecon.mvps_push_or_pull(pos, vector.multiply(dir, -1), dir, maximum, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
function mesecon.mvps_pull_single(pos, dir, maximum)
|
||||||
return mesecon.mvps_push_or_pull(pos, vector.multiply(dir, -1), dir, maximum)
|
return mesecon.mvps_push_or_pull(pos, vector.multiply(dir, -1), dir, maximum)
|
||||||
end
|
end
|
||||||
|
|
||||||
function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum) -- pos: pos of mvps; stackdir: direction of building the stack; movedir: direction of actual movement; maximum: maximum nodes to be pushed
|
-- pos: pos of mvps; stackdir: direction of building the stack
|
||||||
local nodes = mesecon.mvps_get_stack(pos, stackdir, maximum)
|
-- movedir: direction of actual movement
|
||||||
|
-- maximum: maximum nodes to be pushed
|
||||||
|
-- all_pull_sticky: All nodes are sticky in the direction that they are pulled from
|
||||||
|
function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sticky)
|
||||||
|
local nodes = mesecon.mvps_get_stack(pos, movedir, maximum, all_pull_sticky)
|
||||||
|
|
||||||
if not nodes then return end
|
if not nodes then return end
|
||||||
-- determine if one of the nodes blocks the push / pull
|
-- determine if one of the nodes blocks the push / pull
|
||||||
@ -133,27 +189,6 @@ mesecon.register_on_mvps_move(function(moved_nodes)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mesecon.mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: direction of pull (matches push direction for sticky pistons)
|
|
||||||
local np = mesecon.addPosRule(pos, dir)
|
|
||||||
local nn = minetest.get_node(np)
|
|
||||||
|
|
||||||
if ((not minetest.registered_nodes[nn.name]) --unregistered node
|
|
||||||
or minetest.registered_nodes[nn.name].liquidtype == "none") --non-liquid node
|
|
||||||
and not mesecon.is_mvps_stopper(nn, dir, {{pos = np, node = nn}}, 1) then --non-stopper node
|
|
||||||
local meta = minetest.get_meta(np):to_table()
|
|
||||||
minetest.remove_node(np)
|
|
||||||
minetest.add_node(pos, nn)
|
|
||||||
minetest.get_meta(pos):from_table(meta)
|
|
||||||
|
|
||||||
nodeupdate(np)
|
|
||||||
nodeupdate(pos)
|
|
||||||
mesecon.on_dignode(np, nn)
|
|
||||||
mesecon.update_autoconnect(np)
|
|
||||||
on_mvps_move({{pos = pos, oldpos = np, node = nn, meta = meta}})
|
|
||||||
end
|
|
||||||
return {{pos = np, node = {param2 = 0, name = "air"}}, {pos = pos, node = nn}}
|
|
||||||
end
|
|
||||||
|
|
||||||
function mesecon.mvps_move_objects(pos, dir, nodestack)
|
function mesecon.mvps_move_objects(pos, dir, nodestack)
|
||||||
local objects_to_move = {}
|
local objects_to_move = {}
|
||||||
|
|
||||||
|
@ -100,9 +100,10 @@ local piston_off = function(pos, node)
|
|||||||
piston_remove_pusher(pos, node)
|
piston_remove_pusher(pos, node)
|
||||||
|
|
||||||
if pistonspec.sticky then
|
if pistonspec.sticky then
|
||||||
|
local maxpull = mesecon.setting("piston_max_pull", 15)
|
||||||
local dir = piston_get_direction(pistonspec.dir, node)
|
local dir = piston_get_direction(pistonspec.dir, node)
|
||||||
local pullpos = mesecon.addPosRule(pos, dir)
|
local pullpos = vector.add(pos, vector.multiply(dir, 2))
|
||||||
local stack = mesecon.mvps_pull_single(pullpos, dir)
|
local stack = mesecon.mvps_pull_single(pullpos, vector.multiply(dir, -1), maxpull)
|
||||||
mesecon.mvps_process_stack(pos, dir, stack)
|
mesecon.mvps_process_stack(pos, dir, stack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
2
mods/mesecons/mesecons_stickyblocks/depends.txt
Normal file
2
mods/mesecons/mesecons_stickyblocks/depends.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
mesecons
|
||||||
|
mesecons_mvps
|
16
mods/mesecons/mesecons_stickyblocks/init.lua
Normal file
16
mods/mesecons/mesecons_stickyblocks/init.lua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
-- Sticky blocks can be used together with pistons or movestones to push / pull
|
||||||
|
-- structures that are "glued" together using sticky blocks
|
||||||
|
|
||||||
|
-- All sides sticky block
|
||||||
|
minetest.register_node("mesecons_stickyblocks:sticky_block_all", {
|
||||||
|
description = "All-sides sticky block",
|
||||||
|
tiles = {"default_grass_footsteps.png"},
|
||||||
|
groups = {dig_immediate=2},
|
||||||
|
mvps_sticky = function (pos, node)
|
||||||
|
local connected = {}
|
||||||
|
for _, r in ipairs(mesecon.rules.alldirs) do
|
||||||
|
table.insert(connected, vector.add(pos, r))
|
||||||
|
end
|
||||||
|
return connected
|
||||||
|
end
|
||||||
|
})
|
@ -283,8 +283,9 @@ minetest.register_node("pipeworks:entry_panel_empty", {
|
|||||||
selection_box = panel_cbox,
|
selection_box = panel_cbox,
|
||||||
collision_box = panel_cbox,
|
collision_box = panel_cbox,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
if not pipeworks.node_is_owned(pointed_thing.under, placer)
|
local playername = placer:get_player_name()
|
||||||
and not pipeworks.node_is_owned(pointed_thing.above, placer) then
|
if not minetest.is_protected(pointed_thing.under, playername)
|
||||||
|
and not minetest.is_protected(pointed_thing.above, playername) then
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
|
|
||||||
if not minetest.registered_nodes[node.name]
|
if not minetest.registered_nodes[node.name]
|
||||||
|
@ -68,39 +68,6 @@ function pipeworks.may_configure(pos, player)
|
|||||||
return not minetest.is_protected(pos, name)
|
return not minetest.is_protected(pos, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pipeworks.node_is_owned(pos, placer)
|
|
||||||
local ownername = false
|
|
||||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
|
||||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
|
||||||
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
|
|
||||||
if type(getLastOwner) == "function" then -- ...is an old version
|
|
||||||
ownername = getLastOwner(pos)
|
|
||||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
|
||||||
ownername = GetNodeOwnerName(pos)
|
|
||||||
else
|
|
||||||
ownername = S("someone")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
|
||||||
if not isprotect(5, pos, placer) then
|
|
||||||
ownername = S("someone")
|
|
||||||
end
|
|
||||||
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
|
|
||||||
if not protector.can_dig(5, pos, placer) then
|
|
||||||
ownername = S("someone")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ownername ~= false then
|
|
||||||
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function pipeworks.replace_name(tbl,tr,name)
|
function pipeworks.replace_name(tbl,tr,name)
|
||||||
local ntbl={}
|
local ntbl={}
|
||||||
for key,i in pairs(tbl) do
|
for key,i in pairs(tbl) do
|
||||||
|
Loading…
Reference in New Issue
Block a user