Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply area protections on storage nodes #108

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions nodes/node_battery_holder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local def = {
end,

-- Allow all items with energy storage to be placed in the inventory
allow_metadata_inventory_put = function(_, listname, _, stack)
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
if listname == "batteries" then
if not minetest.global_exists("technic") then
return 0
Expand All @@ -80,18 +80,24 @@ local def = {
-- And specifically if they hold any charge
-- Disregard empty batteries, the player should know better
if md and md.charge > 0 then
if digtron.check_protected_and_record(pos, player) then
return 0
end
return stack:get_count()
else
return 0
end

else
return 0
end
end
return 0
end,

allow_metadata_inventory_move = digtron.protected_allow_metadata_inventory_move,

allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,


can_dig = function(pos)
local meta = minetest.get_meta(pos)
Expand Down
16 changes: 11 additions & 5 deletions nodes/node_builders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ minetest.register_node("digtron:builder", {
digtron.update_builder_item(pos)
end,

allow_metadata_inventory_put = function(pos, listname, index, stack)
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if digtron.check_protected_and_record(pos, player) then
return 0
end

local stack_name = stack:get_name()

if minetest.get_item_group(stack_name, "digtron") ~= 0 then
Expand All @@ -284,10 +288,12 @@ minetest.register_node("digtron:builder", {
return 0
end,

allow_metadata_inventory_take = function(pos, listname, index)
node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack(""))
allow_metadata_inventory_take = function(pos, listname, index, _, player)
if not digtron.check_protected_and_record(pos, player) then
node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack(""))
end
return 0
end,

Expand Down
15 changes: 9 additions & 6 deletions nodes/node_controllers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ minetest.register_node("digtron:auto_controller", {
inv:set_size("stop", 1)
end,

allow_metadata_inventory_put = function(pos, listname, index, stack)
if minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if digtron.check_protected_and_record(pos, player)
or minetest.get_item_group(stack:get_name(), "digtron") ~= 0 then
return 0 -- pointless setting a Digtron node as a stop block
end
node_inventory_table.pos = pos
Expand All @@ -247,10 +248,12 @@ minetest.register_node("digtron:auto_controller", {
return 0
end,

allow_metadata_inventory_take = function(pos, listname, index)
node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack(""))
allow_metadata_inventory_take = function(pos, listname, index, _, player)
if not digtron.check_protected_and_record(pos, player) then
node_inventory_table.pos = pos
local inv = minetest.get_inventory(node_inventory_table)
inv:set_stack(listname, index, ItemStack(""))
end
return 0
end,

Expand Down
10 changes: 9 additions & 1 deletion nodes/node_duplicator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,22 @@ minetest.register_node("digtron:duplicator", {
return inv:is_empty("main")
end,

allow_metadata_inventory_put = function(_, _, _, stack)
allow_metadata_inventory_put = function(pos, _, _, stack, player)
if digtron.check_protected_and_record(pos, player) then
return 0
end

if minetest.get_item_group(stack:get_name(), "digtron") > 0 then
return stack:get_count()
else
return 0
end
end,

allow_metadata_inventory_move = digtron.protected_allow_metadata_inventory_move,

allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,

on_receive_fields = function(pos, _, fields, sender)
local player_name = sender:get_player_name()
if fields.help then
Expand Down
38 changes: 29 additions & 9 deletions nodes/node_storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ minetest.register_node("digtron:inventory", set_logger({
return inv:is_empty("main")
end,

allow_metadata_inventory_put = digtron.protected_allow_metadata_inventory_put,

allow_metadata_inventory_move = digtron.protected_allow_metadata_inventory_move,

allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,

-- Pipeworks compatibility
----------------------------------------------------------------

Expand Down Expand Up @@ -150,17 +156,21 @@ minetest.register_node("digtron:fuelstore", set_logger({
end,

-- Only allow fuel items to be placed in fuel
allow_metadata_inventory_put = function(_, listname, _, stack)
if listname == "fuel" then
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count()
else
return 0
end
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
if digtron.check_protected_and_record(pos, player) then
return 0
end

if listname == "fuel" and minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count()
end
return 0
end,

allow_metadata_inventory_move = digtron.protected_allow_metadata_inventory_move,

allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,

can_dig = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
Expand Down Expand Up @@ -250,7 +260,11 @@ minetest.register_node("digtron:combined_storage", set_logger({
end,

-- Only allow fuel items to be placed in fuel
allow_metadata_inventory_put = function(_, listname, _, stack)
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
if digtron.check_protected_and_record(pos, player) then
return 0
end

if listname == "fuel" then
if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
return stack:get_count()
Expand All @@ -261,7 +275,11 @@ minetest.register_node("digtron:combined_storage", set_logger({
return stack:get_count() -- otherwise, allow all drops
end,

allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, _, count)
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, _, count, player)
if digtron.check_protected_and_record(pos, player) then
return 0
end

if to_list == "main" then
return count
end
Expand All @@ -275,6 +293,8 @@ minetest.register_node("digtron:combined_storage", set_logger({
return 0
end,

allow_metadata_inventory_take = digtron.protected_allow_metadata_inventory_take,

can_dig = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
Expand Down
21 changes: 21 additions & 0 deletions util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,24 @@ digtron.show_offset_markers = function(pos, offset, period)
if entity ~= nil then entity:set_yaw(1.5708) end
end
end

digtron.check_protected_and_record = function(pos, player)
local name = player:get_player_name()
if minetest.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return true
end
return false
end

digtron.protected_allow_metadata_inventory_put = function(pos, _, _, stack, player)
return digtron.check_protected_and_record(pos, player) and 0 or stack:get_count()
end

digtron.protected_allow_metadata_inventory_move = function(pos, _, _, _, _, count, player)
return digtron.check_protected_and_record(pos, player) and 0 or count
end

digtron.protected_allow_metadata_inventory_take = function(pos, _, _, stack, player)
return digtron.check_protected_and_record(pos, player) and 0 or stack:get_count()
end