initial commit
commit
78f68e9208
|
@ -0,0 +1,3 @@
|
|||
## Minetest Mod: Junk Removal by SaKeL
|
||||
|
||||
Remove nodes from players what are not anymore listed in the /player directory. Protector, Protector2, locked doors, locked trapdoors, protected chests, basic machines, enchantment tables, easy vending machines, city blocks and locked chest will be removed by defautlt. It's easy to edit what blocks should be removed from init.lua
|
|
@ -0,0 +1 @@
|
|||
Remove nodes from players what are not anymore listed in the /player directory. Protector, Protector2, locked doors, locked trapdoors, protected chests, basic machines, enchantment tables, easy vending machines, city blocks and locked chest will be removed by defautlt. It's easy to edit what blocks should be removed from init.lua
|
|
@ -0,0 +1,118 @@
|
|||
-- JUNK REMOVAL by SaKeL
|
||||
-- Player blocks/items what are not found in the World directory /players will be removed/replaced with leaves and apples. Free up blocked and protected space on the map from players what are not playing anymore or were deleted.
|
||||
|
||||
-- private core variables - for speed
|
||||
local worldpath = minetest.get_worldpath()
|
||||
local junk_removal = {}
|
||||
|
||||
-- list of players i.e. { [1] = "SaKeL", [2] = "ADMIN", ...}
|
||||
junk_removal.playersfilelist = {}
|
||||
|
||||
-- table of players i.e. { ["SaKeL"] = true, ["ADMIN"] = true, ...}
|
||||
-- this will give us much more faster table lookup than iterating through the table (playersfilelist)
|
||||
junk_removal.playerstable = {}
|
||||
|
||||
-- lost of node names for i.e. LBM
|
||||
junk_removal.nodenames = {
|
||||
-- protector
|
||||
"protector:protect",
|
||||
"protector:protect2",
|
||||
"protector:chest",
|
||||
-- chests
|
||||
"default:chest_locked",
|
||||
"default:chest_locked_open",
|
||||
-- doors
|
||||
"doors:door_steel_a",
|
||||
"doors:door_steel_b",
|
||||
"doors:trapdoor_steel",
|
||||
"doors:trapdoor_steel_open",
|
||||
-- basic machines
|
||||
"basic_machines:autocrafter",
|
||||
"basic_machines:ball_spawner",
|
||||
"basic_machines:constructor",
|
||||
"basic_machines:grinder",
|
||||
"basic_machines:mover",
|
||||
"basic_machines:keypad",
|
||||
"basic_machines:detector",
|
||||
"basic_machines:clockgen",
|
||||
"basic_machines:distributor",
|
||||
"basic_machines:battery_0",
|
||||
"basic_machines:battery_1",
|
||||
"basic_machines:battery_2",
|
||||
"basic_machines:recycler",
|
||||
"basic_machines:generator",
|
||||
-- xdecor
|
||||
"xdecor:enchantment_table",
|
||||
-- easyvend
|
||||
"easyvend:vendor",
|
||||
"easyvend:vendor_on",
|
||||
"easyvend:depositor",
|
||||
"easyvend:depositor_on",
|
||||
-- city block
|
||||
"city_block:cityblock",
|
||||
}
|
||||
|
||||
function junk_removal:load()
|
||||
junk_removal.playersfilelist = minetest.get_dir_list(worldpath.."/players", false)
|
||||
-- index table by player name so searching in it is faster
|
||||
for i = 1, #junk_removal.playersfilelist do
|
||||
junk_removal.playerstable[junk_removal.playersfilelist[i]] = true
|
||||
end
|
||||
|
||||
-- print("junk_removal.playersfilelist: ", minetest.serialize(junk_removal.playersfilelist))
|
||||
print("junk_removal.playerstable: ", minetest.serialize(junk_removal.playerstable))
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
if pname == nil then return end
|
||||
|
||||
if not junk_removal.playerstable[pname] then
|
||||
print("adding player: "..pname.." to playersfilelist")
|
||||
junk_removal.playerstable[pname] = true
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "Junk Removal",
|
||||
name = "junk_removal:remove_junk",
|
||||
nodenames = junk_removal.nodenames,
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
local nname = node.name
|
||||
|
||||
if not nname or not meta or not owner then return end
|
||||
|
||||
-- handle city block
|
||||
if owner == "" and nname == "city_block:cityblock" and minetest.global_exists("city_block") then
|
||||
for i, EachBlock in ipairs(city_block.blocks) do
|
||||
if vector.equals(EachBlock.pos, pos) then
|
||||
table.remove(city_block.blocks, i)
|
||||
city_block:save()
|
||||
print("removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos))
|
||||
minetest.set_node(pos, {name = "default:apple"})
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
elseif owner == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local replace_nodename = "default:apple"
|
||||
if math.random(2) == 1 then
|
||||
replace_nodename = "default:leaves"
|
||||
end
|
||||
|
||||
if not junk_removal.playerstable[owner] then
|
||||
print("removing player junk ("..nname.."): "..owner.." at "..minetest.pos_to_string(pos))
|
||||
minetest.set_node(pos, {name = replace_nodename})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
junk_removal:load()
|
||||
|
||||
print ("[Mod] Junk Removal Loaded.")
|
Loading…
Reference in New Issue