From 8ab2107d37cbf94f9862a5e1397ec612b0b404ab Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Tue, 20 Jul 2021 14:31:30 -0700 Subject: [PATCH] Add simple_protection support --- README.md | 2 +- changelog.txt | 3 ++- mod.conf | 2 +- tnt_function.lua | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d8b26ea..ec8ee93 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Settings documented in [reference][]. ### Requirements: - Depends: default, tnt -- Optional depends: nether, sounds +- Optional depends: nether, sounds, simple_protection ### Links: diff --git a/changelog.txt b/changelog.txt index 40a3563..e612110 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,10 +1,11 @@ -v1.1 +v1.0-1 ---- - added sound when hit - fixed entity vertical positioning - fixed tnt:boom node left after explosion - added setting to customize spawn nodes +- added simple_protection support v1.0 ---- diff --git a/mod.conf b/mod.conf index 708f340..d6f8a32 100644 --- a/mod.conf +++ b/mod.conf @@ -4,4 +4,4 @@ description = An explosive nuisance. version = 1.0 author = Rui depends = default, tnt -optional_depends = nether, sounds +optional_depends = nether, sounds, simple_protection diff --git a/tnt_function.lua b/tnt_function.lua index 21a6a3a..11ef340 100644 --- a/tnt_function.lua +++ b/tnt_function.lua @@ -164,8 +164,21 @@ local function add_drop(drops, item) end end +local function is_protected(pos, name) return core.is_protected(pos, name) end +if core.global_exists("s_protect") then + is_protected = function(pos, name) + local s_protect_name = name + -- simple_protection ignores names with empty strings + if s_protect_name == "" then + s_protect_name = " " + end + + return core.is_protected(pos, name) or not s_protect.can_access(pos, s_protect_name) + end +end + local function destroy(drops, pos, cid) - if core.is_protected(pos, "") then + if is_protected(pos, "") then return end local def = cid_data[cid]