From 1d57b3d0afe3f6a1cdc8df848c68b2579ab5db81 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sun, 5 May 2019 17:23:45 -0500 Subject: [PATCH] Return: default metadata on move, take, put --- chatcommands.lua | 2 +- config.lua | 29 -------------------- factions.lua | 2 +- hud.lua | 4 +-- nodes.lua | 69 ++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 59 insertions(+), 47 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 0a96c24..07d5406 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -109,7 +109,7 @@ factions.register_command = function(cmd_name, cmd, ignore_param_count, or_perm, end -- get some more data - local pos = minetest.get_player_by_name(player):getpos() + local pos = minetest.get_player_by_name(player):get_pos() local parcelpos = factions.get_parcel_pos(pos) return self.on_success(player, player_faction, pos, parcelpos, args) end, diff --git a/config.lua b/config.lua index 6656b0f..a1c4cac 100644 --- a/config.lua +++ b/config.lua @@ -1,6 +1,4 @@ factions_config = {} --- If you want to hardcode the config settings just delete settingstypes.txt, and the line up to END. And then uncomment the hardcoded settings below and change it to whatever you want. --- settingstypes local flip = tonumber(minetest.settings:get("protection_max_depth")) or 512 factions_config.protection_max_depth = -flip factions_config.protection_max_height = tonumber(minetest.settings:get("protection_max_height")) or 10000 @@ -25,30 +23,3 @@ factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomac factions_config.spawn_teleport = minetest.settings:get_bool("spawn_teleport") or false factions_config.protection_style = minetest.settings:get("protection_style") or "2d" factions_config.faction_user_priv = minetest.settings:get("faction_user_priv") or false --- END ---[[ --- hardcoded config settings -factions_config.protection_max_depth = -512 -factions_config.protection_max_height = 10000 -factions_config.power_per_parcel = 1 -factions_config.power_per_death = 1 -factions_config.power_per_tick = 2 -factions_config.tick_time = 60 -factions_config.power_per_attack = 10 -factions_config.faction_name_max_length = 50 -factions_config.rank_name_max_length = 25 -factions_config.maximum_faction_inactivity = 604800 -factions_config.maximum_parcelless_faction_time = 10800 -factions_config.power = 12 -factions_config.maxpower = 0 -factions_config.power_per_player = 1 -factions_config.powermax_per_player = 12 -factions_config.parcel_size = 16 -factions_config.protection_depth_height_limit = true -factions_config.enable_power_per_player = true -factions_config.attack_parcel = false -factions_config.faction_diplomacy = true -factions_config.spawn_teleport = false -factions_config.protection_style = "2d" -factions_config.faction_user_priv = false ---]] \ No newline at end of file diff --git a/factions.lua b/factions.lua index 95ab891..2f5cf27 100644 --- a/factions.lua +++ b/factions.lua @@ -489,7 +489,7 @@ end function factions.get_faction_at(pos) local y = pos.y if factions_config.protection_depth_height_limit and (pos.y < factions_config.protection_max_depth or pos.y > factions_config.protection_max_height) then - return nil + return nil end local parcelpos = factions.get_parcel_pos(pos) return factions.get_parcel_faction(parcelpos) diff --git a/hud.lua b/hud.lua index 8feb527..567b71f 100644 --- a/hud.lua +++ b/hud.lua @@ -112,7 +112,7 @@ function hudUpdateClaimInfo() for i in pairs(playerslist) do local player = playerslist[i] local name = player:get_player_name() - local faction, facname = factions.get_faction_at(player:getpos()) + local faction, facname = factions.get_faction_at(player:get_pos()) local id_name = name .. "factionLand" if hud_ids[id_name] then @@ -124,4 +124,4 @@ function hudUpdateClaimInfo() end end minetest.after(3, hudUpdateClaimInfo) -end \ No newline at end of file +end diff --git a/nodes.lua b/nodes.lua index 467f3d5..b31ec20 100644 --- a/nodes.lua +++ b/nodes.lua @@ -30,6 +30,7 @@ if minetest.registered_nodes["default:chest"] then end end }) + local dc = minetest.registered_nodes["default:chest"] local def_on_rightclick = dc.on_rightclick @@ -43,37 +44,77 @@ if minetest.registered_nodes["default:chest"] then name .. ")") end end + local can_dig = function(pos, player) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("main") and factions.can_use_node(pos, player:get_player_name(), "container") end - local allow_metadata_inventory_move = function(pos, from_list, from_index, - to_list, to_index, count, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + + local allow_metadata_inventory_move + local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move + if def_allow_metadata_inventory_move then + allow_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) end - return count - end - local allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + else + allow_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return count end - return stack:get_count() end - local allow_metadata_inventory_take = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + + local allow_metadata_inventory_put + local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put + if def_allow_metadata_inventory_put then + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_put(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return stack:get_count() end - return stack:get_count() end + + local allow_metadata_inventory_take + local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take + if def_allow_metadata_inventory_take then + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_take(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return stack:get_count() + end + end + local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not factions.can_use_node(pos, clicker:get_player_name(), "container") then return itemstack end return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) end + minetest.override_item("default:chest", {after_place_node = after_place_node, can_dig = can_dig, allow_metadata_inventory_move = allow_metadata_inventory_move,