1
0
mirror of https://github.com/minetest-mods/3d_armor.git synced 2024-12-27 11:10:39 +01:00

Depreciate global configs, closes #68

This commit is contained in:
stujones11 2017-03-18 17:23:50 +00:00
parent e46ff3488b
commit 701215c22f
6 changed files with 171 additions and 77 deletions

View File

@ -14,10 +14,53 @@ Overall level is boosted by 10% when wearing a full matching set.
Fire protection added by TenPlus1 when using crystal armor if Ethereal mod active, level 1
protects against torches, level 2 for crystal spike, level 3 for fire, level 5 for lava.
Configuration
-------------
Armor Configuration
-------------------
Armor can be configured by adding a file called armor.conf in 3d_armor mod and/or world directory.
see armor.conf.example for all available options.
Override the following default settings by adding them to your minetest.conf file.
-- Set false to disable individual armor materials.
armor_material_wood = true
armor_material_cactus = true
armor_material_steel = true
armor_material_bronze = true
armor_material_diamond = true
armor_material_gold = true
armor_material_mithril = true
armor_material_crystal = true
-- Increase this if you get initialization glitches when a player first joins.
armor_init_delay = 1
-- Number of initialization attempts.
-- Use in conjunction with ARMOR_INIT_DELAY if initialization problems persist.
armor_init_times = 1
-- Increase this if armor is not getting into bones due to server lag.
armor_bones_delay = 1
-- How often player armor items are updated.
armor_update_time = 1
-- Drop armor when a player dies.
-- Uses bones mod if present, otherwise items are dropped around the player.
armor_drop = true
-- Pulverise armor when a player dies, overrides armor_drop.
armor_destroy = false
-- You can use this to increase or decrease overall armor effectiveness,
-- eg: level_multiplier = 0.5 will reduce armor level by half.
armor_level_multiplier = 1
-- You can use this to increase or decrease overall armor healing,
-- eg: armor_heal_multiplier = 0 will disable healing altogether.
armor_heal_multiplier = 1
-- You can use this to increase or decrease overall armor radiation protection,
-- eg: armor_radiation_multiplier = 0 will completely disable radiation protection.
armor_radiation_multiplier = 1
-- Enable fire protection (defaults true if using ethereal mod)
armor_fire_protect = false
Note: worldpath config settings override any settings made in the mod's directory.

View File

@ -21,9 +21,51 @@ armor = {
def = {},
textures = {},
default_skin = "character",
materials = {
wood = "group:wood",
cactus = "default:cactus",
steel = "default:steel_ingot",
bronze = "default:bronze_ingot",
diamond = "default:diamond",
gold = "default:gold_ingot",
mithril = "moreores:mithril_ingot",
crystal = "ethereal:crystal_ingot",
},
fire_nodes = {
{"default:lava_source", 5, 8},
{"default:lava_flowing", 5, 8},
{"fire:basic_flame", 3, 4},
{"fire:permanent_flame", 3, 4},
{"ethereal:crystal_spike", 2, 1},
{"ethereal:fire_flower", 2, 1},
{"default:torch", 1, 1},
{"default:torch_ceiling", 1, 1},
{"default:torch_wall", 1, 1},
},
version = "0.4.8",
}
armor.config = {
init_delay = 1,
init_times = 1,
bones_delay = 1,
update_time = 1,
drop = minetest.get_modpath("bones") ~= nil,
destroy = false,
level_multiplier = 1,
heal_multiplier = 1,
radiation_multiplier = 1,
material_wood = true,
material_cactus = true,
material_steel = true,
material_bronze = true,
material_diamond = true,
material_gold = true,
material_mithril = true,
material_crystal = true,
fire_protect = minetest.get_modpath("ethereal") ~= nil
}
armor.update_player_visuals = function(self, player)
if not player then
return
@ -104,9 +146,9 @@ armor.set_player_armor = function(self, player)
if material.type and material.count == #self.elements then
armor_level = armor_level * 1.1
end
armor_level = armor_level * ARMOR_LEVEL_MULTIPLIER
armor_heal = armor_heal * ARMOR_HEAL_MULTIPLIER
armor_radiation = armor_radiation * ARMOR_RADIATION_MULTIPLIER
armor_level = armor_level * self.config.level_multiplier
armor_heal = armor_heal * self.config.heal_multiplier
armor_radiation = armor_radiation * self.config.radiation_multiplier
if #textures > 0 then
armor_texture = table.concat(textures, "^")
end

View File

@ -1,3 +1,7 @@
-- DEPRECIATED, will not be supported in future versions
-- See README.txt for new configuration options.
-- Armor Configuration (defaults)
-- You can remove any unwanted armor materials from this table.

View File

@ -47,7 +47,7 @@ minetest.register_tool("3d_armor:boots_admin", {
end,
})
if ARMOR_MATERIALS.wood then
if armor.materials.wood then
minetest.register_tool("3d_armor:helmet_wood", {
description = "Wood Helmet",
inventory_image = "3d_armor_inv_helmet_wood.png",
@ -74,7 +74,7 @@ if ARMOR_MATERIALS.wood then
})
end
if ARMOR_MATERIALS.cactus then
if armor.materials.cactus then
minetest.register_tool("3d_armor:helmet_cactus", {
description = "Cactus Helmet",
inventory_image = "3d_armor_inv_helmet_cactus.png",
@ -101,7 +101,7 @@ if ARMOR_MATERIALS.cactus then
})
end
if ARMOR_MATERIALS.steel then
if armor.materials.steel then
minetest.register_tool("3d_armor:helmet_steel", {
description = "Steel Helmet",
inventory_image = "3d_armor_inv_helmet_steel.png",
@ -128,7 +128,7 @@ if ARMOR_MATERIALS.steel then
})
end
if ARMOR_MATERIALS.bronze then
if armor.materials.bronze then
minetest.register_tool("3d_armor:helmet_bronze", {
description = "Bronze Helmet",
inventory_image = "3d_armor_inv_helmet_bronze.png",
@ -155,7 +155,7 @@ if ARMOR_MATERIALS.bronze then
})
end
if ARMOR_MATERIALS.diamond then
if armor.materials.diamond then
minetest.register_tool("3d_armor:helmet_diamond", {
description = "Diamond Helmet",
inventory_image = "3d_armor_inv_helmet_diamond.png",
@ -182,7 +182,7 @@ if ARMOR_MATERIALS.diamond then
})
end
if ARMOR_MATERIALS.gold then
if armor.materials.gold then
minetest.register_tool("3d_armor:helmet_gold", {
description = "Gold Helmet",
inventory_image = "3d_armor_inv_helmet_gold.png",
@ -209,7 +209,7 @@ if ARMOR_MATERIALS.gold then
})
end
if ARMOR_MATERIALS.mithril then
if armor.materials.mithril then
minetest.register_tool("3d_armor:helmet_mithril", {
description = "Mithril Helmet",
inventory_image = "3d_armor_inv_helmet_mithril.png",
@ -236,7 +236,7 @@ if ARMOR_MATERIALS.mithril then
})
end
if ARMOR_MATERIALS.crystal then
if armor.materials.crystal then
minetest.register_tool("3d_armor:helmet_crystal", {
description = "Crystal Helmet",
inventory_image = "3d_armor_inv_helmet_crystal.png",
@ -263,7 +263,7 @@ if ARMOR_MATERIALS.crystal then
})
end
for k, v in pairs(ARMOR_MATERIALS) do
for k, v in pairs(armor.materials) do
minetest.register_craft({
output = "3d_armor:helmet_"..k,
recipe = {

View File

@ -1,38 +1,11 @@
ARMOR_MOD_NAME = minetest.get_current_modname()
ARMOR_INIT_DELAY = 1
ARMOR_INIT_TIMES = 1
ARMOR_BONES_DELAY = 1
ARMOR_UPDATE_TIME = 1
ARMOR_DROP = minetest.get_modpath("bones") ~= nil
ARMOR_DESTROY = false
ARMOR_LEVEL_MULTIPLIER = 1
ARMOR_HEAL_MULTIPLIER = 1
ARMOR_RADIATION_MULTIPLIER = 1
ARMOR_MATERIALS = {
wood = "group:wood",
cactus = "default:cactus",
steel = "default:steel_ingot",
bronze = "default:bronze_ingot",
diamond = "default:diamond",
gold = "default:gold_ingot",
mithril = "moreores:mithril_ingot",
crystal = "ethereal:crystal_ingot",
}
ARMOR_FIRE_PROTECT = minetest.get_modpath("ethereal") ~= nil
ARMOR_FIRE_NODES = {
{"default:lava_source", 5, 8},
{"default:lava_flowing", 5, 8},
{"fire:basic_flame", 3, 4},
{"fire:permanent_flame", 3, 4},
{"ethereal:crystal_spike", 2, 1},
{"ethereal:fire_flower", 2, 1},
{"default:torch", 1, 1},
{"default:torch_ceiling", 1, 1},
{"default:torch_wall", 1, 1},
}
local modpath = minetest.get_modpath(ARMOR_MOD_NAME)
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local worldpath = minetest.get_worldpath()
dofile(modpath.."/api.lua")
-- Legacy Config Support
local input = io.open(modpath.."/armor.conf", "r")
if input then
dofile(modpath.."/armor.conf")
@ -46,8 +19,40 @@ if input then
input = nil
end
dofile(minetest.get_modpath(ARMOR_MOD_NAME).."/api.lua")
dofile(minetest.get_modpath(ARMOR_MOD_NAME).."/armor.lua")
for name, _ in pairs(armor.config) do
local global = "ARMOR_"..name:upper()
if minetest.global_exists(global) then
armor.config[name] = _G[global]
end
end
if minetest.global_exists("ARMOR_MATERIALS") then
armor.materials = table.copy(ARMOR_MATERIALS)
end
if minetest.global_exists("ARMOR_FIRE_NODES") then
armor.fire_nodes = table.copy(ARMOR_FIRE_NODES)
end
for name, config in pairs(armor.config) do
local setting = minetest.setting_get("armor_"..name)
if type(config) == "number" then
setting = tonumber(setting)
elseif type(config) == "boolean" then
setting = minetest.setting_getbool("armor_"..name)
end
if setting then
armor.config[name] = setting
end
end
for material, _ in pairs(armor.materials) do
local key = "material_"..material
if armor.config[key] == false then
armor.materials[material] = nil
end
end
dofile(modpath.."/armor.lua")
-- Mod Compatibility
@ -60,7 +65,7 @@ local armor_formpage = "image[2.5,0;2,4;armor_preview]"..
"label[5,1.5;Heal: armor_heal]"..
"list[current_player;main;0,4.7;8,1;]"..
"list[current_player;main;0,5.85;8,3;8]"
if ARMOR_FIRE_PROTECT then
if armor.config.fire_protect then
armor_formpage = armor_formpage.."label[5,2;Fire: armor_fire]"
end
if minetest.global_exists("technic") then
@ -91,7 +96,7 @@ elseif minetest.get_modpath("unified_inventory") and not unified_inventory.sfinv
"label[5.0,"..(fy + 0.5)..";Heal: "..armor.def[name].heal.."]"..
"listring[current_player;main]"..
"listring[detached:"..name.."_armor;armor]"
if ARMOR_FIRE_PROTECT then
if armor.config.fire_protect then
formspec = formspec.."label[5.0,"..(fy + 1.0)..
";Fire: "..armor.def[name].fire.."]"
end
@ -132,10 +137,10 @@ for _, mod in pairs(skin_mods) do
end
end
if not minetest.get_modpath("moreores") then
ARMOR_MATERIALS.mithril = nil
armor.materials.mithril = nil
end
if not minetest.get_modpath("ethereal") then
ARMOR_MATERIALS.crystal = nil
armor.materials.crystal = nil
end
-- Armor Player Model
@ -269,8 +274,8 @@ minetest.register_on_joinplayer(function(player)
end
end
end
for i=1, ARMOR_INIT_TIMES do
minetest.after(ARMOR_INIT_DELAY * i, function(player)
for i=1, armor.config.init_times do
minetest.after(armor.config.init_delay * i, function(player)
armor:set_player_armor(player)
if not armor.inv_mod then
armor:update_inventory(player)
@ -279,7 +284,7 @@ minetest.register_on_joinplayer(function(player)
end
end)
if ARMOR_DROP == true or ARMOR_DESTROY == true then
if armor.config.drop == true or armor.config.destroy == true then
minetest.register_on_dieplayer(function(player)
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
if not name then
@ -303,8 +308,8 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
else
armor:update_inventory(player)
end
if ARMOR_DESTROY == false then
minetest.after(ARMOR_BONES_DELAY, function()
if armor.config.destroy == false then
minetest.after(armor.config.bones_delay, function()
local meta = nil
local maxp = vector.add(pos, 8)
local minp = vector.subtract(pos, 8)
@ -375,9 +380,9 @@ end, true)
-- Fire Protection and water breating, added by TenPlus1
if ARMOR_FIRE_PROTECT == true then
if armor.config.fire_protect == true then
-- override hot nodes so they do not hurt player anywhere but mod
for _, row in pairs(ARMOR_FIRE_NODES) do
for _, row in pairs(armor.fire_nodes) do
if minetest.registered_nodes[row[1]] then
minetest.override_item(row[1], {damage_per_second = 0})
end
@ -388,7 +393,7 @@ end
minetest.register_globalstep(function(dtime)
armor.timer = armor.timer + dtime
if armor.timer < ARMOR_UPDATE_TIME then
if armor.timer < armor.config.update_time then
return
end
for _,player in pairs(minetest.get_connected_players()) do
@ -402,18 +407,18 @@ minetest.register_globalstep(function(dtime)
end
end
-- fire protection
if ARMOR_FIRE_PROTECT == true
if armor.config.fire_protect == true
and name and pos and hp then
pos.y = pos.y + 1.4 -- head level
local node_head = minetest.get_node(pos).name
pos.y = pos.y - 1.2 -- feet level
local node_feet = minetest.get_node(pos).name
-- is player inside a hot node?
for _, row in pairs(ARMOR_FIRE_NODES) do
for _, row in pairs(armor.fire_nodes) do
-- check fire protection, if not enough then get hurt
if row[1] == node_head or row[1] == node_feet then
if hp > 0 and armor.def[name].fire < row[2] then
hp = hp - row[3] * ARMOR_UPDATE_TIME
hp = hp - row[3] * armor.config.update_time
player:set_hp(hp)
break
end

View File

@ -13,7 +13,7 @@ minetest.register_tool("shields:shield_admin", {
wear = 0,
})
if ARMOR_MATERIALS.wood then
if armor.materials.wood then
minetest.register_tool("shields:shield_wood", {
description = "Wooden Shield",
inventory_image = "shields_inv_shield_wood.png",
@ -36,7 +36,7 @@ if ARMOR_MATERIALS.wood then
})
end
if ARMOR_MATERIALS.cactus then
if armor.materials.cactus then
minetest.register_tool("shields:shield_cactus", {
description = "Cactus Shield",
inventory_image = "shields_inv_shield_cactus.png",
@ -59,7 +59,7 @@ if ARMOR_MATERIALS.cactus then
})
end
if ARMOR_MATERIALS.steel then
if armor.materials.steel then
minetest.register_tool("shields:shield_steel", {
description = "Steel Shield",
inventory_image = "shields_inv_shield_steel.png",
@ -68,7 +68,7 @@ if ARMOR_MATERIALS.steel then
})
end
if ARMOR_MATERIALS.bronze then
if armor.materials.bronze then
minetest.register_tool("shields:shield_bronze", {
description = "Bronze Shield",
inventory_image = "shields_inv_shield_bronze.png",
@ -77,7 +77,7 @@ if ARMOR_MATERIALS.bronze then
})
end
if ARMOR_MATERIALS.diamond then
if armor.materials.diamond then
minetest.register_tool("shields:shield_diamond", {
description = "Diamond Shield",
inventory_image = "shields_inv_shield_diamond.png",
@ -86,7 +86,7 @@ if ARMOR_MATERIALS.diamond then
})
end
if ARMOR_MATERIALS.gold then
if armor.materials.gold then
minetest.register_tool("shields:shield_gold", {
description = "Gold Shield",
inventory_image = "shields_inv_shield_gold.png",
@ -95,7 +95,7 @@ if ARMOR_MATERIALS.gold then
})
end
if ARMOR_MATERIALS.mithril then
if armor.materials.mithril then
minetest.register_tool("shields:shield_mithril", {
description = "Mithril Shield",
inventory_image = "shields_inv_shield_mithril.png",
@ -104,7 +104,7 @@ if ARMOR_MATERIALS.mithril then
})
end
if ARMOR_MATERIALS.crystal then
if armor.materials.crystal then
minetest.register_tool("shields:shield_crystal", {
description = "Crystal Shield",
inventory_image = "shields_inv_shield_crystal.png",
@ -113,7 +113,7 @@ if ARMOR_MATERIALS.crystal then
})
end
for k, v in pairs(ARMOR_MATERIALS) do
for k, v in pairs(armor.materials) do
minetest.register_craft({
output = "shields:shield_"..k,
recipe = {