[mod] No messy spawn [nospawntrash]

User avatar
JoshMars
Member
 
Posts: 103
Joined: Sat May 17, 2014 23:24
In-game: rubber UbuntuJosh

[mod] No messy spawn [nospawntrash]

by JoshMars » Sat Dec 17, 2016 21:13

Ten minutes of googling got me nothing, so I wrote this little mod that prevents players from placing certain blocks near spawn in the future. Spawn was getting a lil' crowded in FREE PIZZA SERVER!!

init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local bannedblocks = {
   "mesecons_pistons:piston_normal_off",
   "mesecons_pistons:piston_sticky_off",
   "smartshop:shop",
   "travelnet:travelnet"
}
local staticspawn = minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 2, z = 0}
nospawntrash = {}
function nospawntrash.check(itemstack, placer, pointed_thing)
   if vector.distance(pointed_thing.above, staticspawn) < 35 then

      minetest.chat_send_player(placer:get_player_name(),
         "Too close to spawn.")

      return itemstack
   end

   return minetest.item_place(itemstack, placer, pointed_thing)

end
for b = 1, 4 do
   minetest.override_item(bannedblocks[b], {
   on_place = nospawntrash.check,
   })
end


depends.txt
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
mesecons_pistons
smartshop
travelnet


License:WTFPL
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: [mod] No messy spawn [nospawntrash]

by orwell » Tue Dec 20, 2016 19:24

This may break nodes that have a on_place set, but that should be less of a problem since most nodes use after_place_node instead of on_place
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 9 guests

cron