1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 07:20:31 +01:00

Eject items when a node is placed at their current pos

This commit is contained in:
LeMagnesium 2015-08-15 18:06:27 +02:00
parent a6ce72a093
commit 7dc287e014
2 changed files with 31 additions and 0 deletions

28
mods/_misc/eject_entities.lua Executable file
View File

@ -0,0 +1,28 @@
-------------------------------------
-- Eject entities when placing node
--
unwalkable_nodes = {}
minetest.after(0, function()
for itemname, node in pairs(minetest.registered_nodes) do
if node.walkable == false then
table.insert(unwalkable_nodes, 1, itemname)
end
end
end)
minetest.register_on_placenode(function(pos)
local objs = minetest.get_objects_inside_radius(pos, 1)
local minp, maxp = {x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y+1, z=pos.z+1}
local nodes = minetest.find_nodes_in_area(minp, maxp, unwalkable_nodes)
if table.getn(nodes) == 0 then
return
end
for _,obj in pairs(objs) do
if not obj:is_player() and obj:get_entity_name() == "builtin:item" then
obj:setpos(nodes[math.random(1,#nodes)])
end
end
end)

View File

@ -27,3 +27,6 @@ dofile(minetest.get_modpath("_misc").."/uncraft_woll.lua")
-- List players
dofile(minetest.get_modpath("_misc").."/list_players.lua")
-- Eject entites when putting a node
dofile(minetest.get_modpath("_misc").."/eject_entities.lua")