From 7dc287e014f3bd7b6971ce1a71072ea2b83b79f3 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Sat, 15 Aug 2015 18:06:27 +0200 Subject: [PATCH] Eject items when a node is placed at their current pos --- mods/_misc/eject_entities.lua | 28 ++++++++++++++++++++++++++++ mods/_misc/init.lua | 3 +++ 2 files changed, 31 insertions(+) create mode 100755 mods/_misc/eject_entities.lua diff --git a/mods/_misc/eject_entities.lua b/mods/_misc/eject_entities.lua new file mode 100755 index 00000000..8bba00ed --- /dev/null +++ b/mods/_misc/eject_entities.lua @@ -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) + diff --git a/mods/_misc/init.lua b/mods/_misc/init.lua index 17497039..51707470 100755 --- a/mods/_misc/init.lua +++ b/mods/_misc/init.lua @@ -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")