From a69dc4b0ec32852d7aac2f4f65c257eadb5cc4aa Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sat, 6 Jan 2018 19:37:58 -0500 Subject: [PATCH] initial commit --- depends.txt | 1 + init.lua | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 depends.txt create mode 100644 init.lua diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..4faf960 --- /dev/null +++ b/init.lua @@ -0,0 +1,83 @@ +-- ANTI GRIEF by rnd +-- Copyright 2016 rnd + +---------------------------------------------------------------------------- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. + +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. + +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +---------------------------------------------------------------------------- + + +-- prevents placing of lava/liquid sources or buckets above 0 + + +--water +--bucket:bucket_water + +function prevent_place_above(name) + + local old_on_place=minetest.registered_craftitems[name];--.on_place; + local old_after_place_node = minetest.registered_nodes[name];--.after_place_node; + --after_place_node = func(pos, placer, itemstack, pointed_thing) + + if old_on_place and old_on_place.on_place then + old_on_place=old_on_place.on_place; + minetest.registered_craftitems[name].on_place=function(itemstack, placer, pointed_thing) + local pos = pointed_thing.above + if pos.y>0 then + minetest.log("action","ANTI GRIEF " .. placer:get_player_name() .. " tried to place " .. name .. " at " .. minetest.pos_to_string(pos)); + return itemstack + else + return old_on_place(itemstack, placer, pointed_thing) + end + end + return; + end + + if old_after_place_node then + + old_after_place_node=old_after_place_node.after_place_node + + local table = minetest.registered_nodes[name]; + local table2 = {} + for i,v in pairs(table) do + table2[i] = v + end + + table2.after_place_node=function(pos, placer, itemstack, pointed_thing) + --after_place_node = func(pos, placer, itemstack, pointed_thing) + local pos = pointed_thing.above + if pos.y>0 then + minetest.log("action","ANTI GRIEF " .. placer:get_player_name() .. " tried to place " .. name .. " at " .. minetest.pos_to_string(pos)); + minetest.set_node(pos, {name = "air"}); + return itemstack + end + end + + + minetest.register_node(":"..name, table2) + return; + end + + + return; +end + + +minetest.after(0, +function () +prevent_place_above("bucket:bucket_water"); +prevent_place_above("default:water_source"); +prevent_place_above("bucket:bucket_lava"); +prevent_place_above("default:lava_source"); +end +) \ No newline at end of file