1
0
Fork 0

Add protection support to composter.

* Add checks for `minetest.is_protected()` and log any violations.
* Add local aliases for global functions.
This commit is contained in:
kabou 2022-04-02 00:31:22 +02:00 committed by cora
parent bba3aabb59
commit 2ba801dfc7
1 changed files with 12 additions and 0 deletions

View File

@ -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)