add mithril protected chest (works with any protection mod that overrides minetest.is_protected())

This commit is contained in:
Thomas Rudin 2019-02-01 21:20:03 +01:00
parent 4f78a69ffc
commit 5bddd0c7fa
4 changed files with 86 additions and 4 deletions

View File

@ -27,6 +27,8 @@ technic.chests.can_dig = function(pos, player)
return inv:is_empty("main") return inv:is_empty("main")
end end
-- utils for locked chest
local function inv_change(pos, count, player) local function inv_change(pos, count, player)
-- Skip check for pipeworks (fake player) -- Skip check for pipeworks (fake player)
if minetest.is_player(player) and if minetest.is_player(player) and
@ -46,6 +48,27 @@ function technic.chests.inv_take(pos, listname, index, stack, player)
return inv_change(pos, stack:get_count(), player) return inv_change(pos, stack:get_count(), player)
end end
-- utils for protected chest
local function inv_change_protected(pos, count, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return count
end
function technic.chests.inv_move_protected(pos, from_list, from_index, to_list, to_index, count, player)
return inv_change_protected(pos, count, player)
end
function technic.chests.inv_put_protected(pos, listname, index, stack, player)
return inv_change_protected(pos, stack:get_count(), player)
end
function technic.chests.inv_take_protected(pos, listname, index, stack, player)
return inv_change_protected(pos, stack:get_count(), player)
end
-- logging utils
function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_index, count, player) function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name().. minetest.log("action", player:get_player_name()..
" moves stuff in chest at " " moves stuff in chest at "
@ -63,4 +86,3 @@ function technic.chests.on_inv_take(pos, listname, index, stack, player)
" takes " .. stack:get_name() .. " takes " .. stack:get_name() ..
" from chest at " .. minetest.pos_to_string(pos)) " from chest at " .. minetest.pos_to_string(pos))
end end

View File

@ -4,3 +4,5 @@ moreblocks?
moreores? moreores?
pipeworks? pipeworks?
intllib? intllib?
protector?
areas?

View File

@ -26,6 +26,7 @@ minetest.register_craft({
} }
}) })
-- plain chest
technic.chests:register("Mithril", { technic.chests:register("Mithril", {
width = 15, width = 15,
height = 6, height = 6,
@ -36,6 +37,7 @@ technic.chests:register("Mithril", {
locked = false, locked = false,
}) })
-- owned locked chest
technic.chests:register("Mithril", { technic.chests:register("Mithril", {
width = 15, width = 15,
height = 6, height = 6,
@ -46,3 +48,23 @@ technic.chests:register("Mithril", {
locked = true, locked = true,
}) })
if minetest.get_modpath("protector") or minetest.get_modpath("areas") then
-- protected chest (works with any protection mod that overrides minetest.is_protected)
technic.chests:register("Mithril", {
width = 15,
height = 6,
sort = true,
autosort = true,
infotext = false,
color = false,
protected = true,
})
minetest.register_craft({
output = 'technic:mithril_protected_chest 1',
recipe = {
{'basic_materials:padlock'},
{'technic:mithril_locked_chest'},
}
})
end

View File

@ -3,6 +3,8 @@ local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
local pipeworks = rawget(_G, "pipeworks") local pipeworks = rawget(_G, "pipeworks")
local fs_helpers = rawget(_G, "fs_helpers") local fs_helpers = rawget(_G, "fs_helpers")
local has_protector_mod = minetest.get_modpath("protector")
local allow_label = "" local allow_label = ""
local tube_entry = "" local tube_entry = ""
local shift_edit_field = 0 local shift_edit_field = 0
@ -238,14 +240,25 @@ function technic.chests:definition(name, data)
:format(name, meta:get_string("owner"))) :format(name, meta:get_string("owner")))
pipeworks.after_place(pos) pipeworks.after_place(pos)
end end
table.insert(front, "technic_"..lname.."_chest_lock_overlay.png")
else else
locked_after_place = pipeworks.after_place locked_after_place = pipeworks.after_place
end end
if data.locked then
table.insert(front, "technic_"..lname.."_chest_lock_overlay.png")
end
if data.protected and has_protector_mod then
-- use overlay from protector mod
table.insert(front, "protector_logo.png")
end
local desc local desc
if data.locked then if data.locked then
desc = S("%s Locked Chest"):format(name) desc = S("%s Locked Chest"):format(name)
elseif data.protected then
desc = S("%s Protected Chest"):format(name)
else else
desc = S("%s Chest"):format(name) desc = S("%s Chest"):format(name)
end end
@ -326,6 +339,16 @@ function technic.chests:definition(name, data)
return secret, "a locked chest", owner return secret, "a locked chest", owner
end end
elseif data.protected then
def.allow_metadata_inventory_move = self.inv_move_protected
def.allow_metadata_inventory_put = self.inv_put_protected
def.allow_metadata_inventory_take = self.inv_take_protected
def.on_blast = function() end
def.can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and not minetest.is_protected(pos, player:get_player_name())
end
end end
return def return def
end end
@ -333,7 +356,21 @@ end
function technic.chests:register(name, data) function technic.chests:register(name, data)
local def = technic.chests:definition(name, data) local def = technic.chests:definition(name, data)
local nn = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest" -- prefix
local nn = "technic:"..name:lower()
if data.locked then
-- locked chest
nn = nn .. "_locked"
elseif data.protected then
-- protected chest
nn = nn .. "_protected"
end
-- suffix
nn = nn .. "_chest"
minetest.register_node(":"..nn, def) minetest.register_node(":"..nn, def)
if data.color then if data.color then
@ -357,4 +394,3 @@ function technic.chests:register(name, data)
end end
end end