From 2ba801dfc700decfde9e7f011a7b1b11f92062de Mon Sep 17 00:00:00 2001 From: kabou Date: Sat, 2 Apr 2022 00:31:22 +0200 Subject: [PATCH] Add protection support to composter. * Add checks for `minetest.is_protected()` and log any violations. * Add local aliases for global functions. --- mods/ITEMS/mcl_composters/init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mods/ITEMS/mcl_composters/init.lua b/mods/ITEMS/mcl_composters/init.lua index 80afce2599..2729ffb8e0 100644 --- a/mods/ITEMS/mcl_composters/init.lua +++ b/mods/ITEMS/mcl_composters/init.lua @@ -45,6 +45,8 @@ local swap_node = minetest.swap_node local get_node_timer = minetest.get_node_timer local add_item = minetest.add_item local vector_offset = vector.offset +local is_protected = minetest.is_protected +local record_protection_violation = minetest.record_protection_violation local function composter_add_item(pos, node, player, itemstack, pointed_thing) -- @@ -55,6 +57,11 @@ local function composter_add_item(pos, node, player, itemstack, pointed_thing) if not player or (player:get_player_control() and player:get_player_control().sneak) then return itemstack end + local name = player:get_player_name() + if is_protected(pos, name) then + record_protection_violation(pos, name) + return itemstack + end if not itemstack or itemstack:is_empty() then return itemstack end @@ -111,6 +118,11 @@ local function composter_harvest(pos, node, player, itemstack, pointed_thing) if not player or (player:get_player_control() and player:get_player_control().sneak) then return end + local name = player:get_player_name() + if is_protected(pos, name) then + record_protection_violation(pos, name) + return itemstack + end -- reset ready type composter to empty type swap_node(pos, {name="mcl_composters:composter"}) -- spawn bone meal item (wtf dye?! is this how they make white cocoa)