An update to pre-release of v1.0

This commit is contained in:
Apollo 2022-05-19 13:59:09 -04:00
parent 233bd4ba17
commit 236355ed5c
6 changed files with 130 additions and 27 deletions

View File

@ -1,2 +1,24 @@
# rebreather
Adds a item which checks if the player is low on air if so provides air at the cost of durability, A Minetest Mod
# Rebreather
Adds a item which checks if the player is low on air if so provides air at the cost of durability.
## In the mod
* Starting set of 3 rebreathers. (Steel, Gold, and Diamond, this can be disabled if desired)
* Simple Api for adding custom rebreathers. (Just pick an item name, inventory image, and how fast it wears down (bigger means less uses), don't forget to make a recipe to craft it)
* Rebrethers won't break, and they can be regenerated while in air. (See below for more information)
## How they work
Simply craft a rebreather, then keep it in your inventory.
While in your inventory they can:
* Provide air when you hit 25% or less of your max breath. (They provide 1 less than your max breath, so mods that increase air capacity means this mod will make use of that increased air capacity)
* When not needed they will regenerate any durability they've lost when they were being used. (While at a slower rate it still works)
> Due to a bio mechanical discovery the Rebreather mod provides in simple terms mechanical gills. (While being used however the filtration system gets overloaded and eventually can't provide air, but when not needed the filtration system can perform the needed self cleaning process thus after some time it can then provide air again)
Built-in to the mod are 3 different rebreathers each a upgrade from the last. (This can be disabled if you just wanted the mod as an api, or limit the number of players able to obtain rebreathers)
> A note, they will consume the first rebreather then when that one fails it can use the next. (And while not needed both will regenerate via the self cleaning process)

68
api.lua
View File

@ -22,8 +22,15 @@ rebreather.check_player = function (name)
for idx, stack in pairs(inv:get_list("main")) do
for _, i in ipairs(rebreather.items) do
if i == stack:get_name() then
found = true
id = idx
local stack_def = stack:get_definition()
-- Don't destroy rebreathers (this will find what the durability/wear is left, if we can take another use)
if stack:get_wear()+(stack_def.groups.damage_per_use) < 65535 then
found = true
id = idx
break
end
end
if found then
break
end
end
@ -42,16 +49,16 @@ rebreather.air_player = function (name)
local player = minetest.get_player_by_name(name)
if player ~= nil then
local inv = player:get_inventory()
local rebreather_in_hand = nil
local rebreather_in_inv = nil
local at = nil
local rc = rebreather.check_player(name)
rebreather_in_hand = rc.success
rebreather_in_inv = rc.success
at = rc.value
--minetest.log("action", "[rebreather] '"..name.."' "..tostring(rebreather_in_hand).." "..tostring(at).."")
if rebreather_in_hand then
-- Obtain current item in hand, Obtain current air levels, Obtain max air levels (via Object properites)
local hand = inv:get_stack("main", at)
local def = hand:get_definition()
--minetest.log("action", "[rebreather] '"..name.."' "..tostring(rebreather_in_inv).." "..tostring(at).."")
if rebreather_in_inv then
-- Obtain item in inv, Obtain current air levels, Obtain max air levels (via Object properites)
local rebr = inv:get_stack("main", at)
local def = rebr:get_definition()
local air = player:get_breath()
local props = player:get_properties()
local max_air = props.breath_max
@ -62,20 +69,41 @@ rebreather.air_player = function (name)
minetest.log("action", "[rebreather] '"..name.."' Has "..perc.."% Air ("..air.."/"..max_air..")")
end
if perc <= 25 then
-- Update air, Damage item, Update item in hand
player:set_breath(max_air-1) -- Don't update to max so we quit hiding the breath bubbles.
hand:add_wear(def.groups.damage_per_use or 1000)
-- Update air, Damage item, Update item in inventory
player:set_breath(max_air-1) -- Don't update to max so we quit hiding the breath bubbles. (Which also triggered a regenerate)
rebr:add_wear(def.groups.damage_per_use or 5000)
if rebreather.debug then
minetest.log("action", "[rebreather] '"..name.."' Used '"..hand:get_name().."' durability at "..hand:get_wear())
minetest.log("action", "[rebreather] '"..name.."' Used '"..rebr:get_name().."' durability at "..rebr:get_wear())
else
minetest.log("action", "[rebreather] '"..name.."' Used '"..rebr:get_name().."'")
end
inv:set_stack("main", at, hand)
inv:set_stack("main", at, rebr)
elseif perc == 100 then
-- Regenerate if the air is full
local meta = hand:get_meta()
hand:add_wear(-(def.groups.damage_per_use/8) or -125)
inv:set_stack("main", at, hand)
if rebreather.debug then
minetest.log("action", "[rebreather] '"..name.."' Regenerates '"..hand:get_name().."' durability at "..hand:get_wear())
-- Regenerate if the air is full (Regenerate all of them not just the one we were using)
local num_repaired = 0
for i, _ in pairs(inv:get_lists()) do
if rebreather.debug_regeneration then
minetest.log("action", "[rebreather] i="..tostring(i))
end
for id, stack in pairs(inv:get_list(i)) do
if rebreather.debug_regeneration then
minetest.log("action", "[rebreather] i="..tostring(i).." id="..tostring(id).." stack="..minetest.serialize(stack:to_table()))
end
for _, r in ipairs(rebreather.items) do
if stack:get_name() == r and stack:get_wear() ~= 0 then
if rebreather.debug_regeneration then
minetest.log("action", "[rebreather] Repaired! i="..tostring(i).." id="..tostring(id).." stack="..minetest.serialize(stack:to_table()).." Repaired!")
end
local stack_def = stack:get_definition()
stack:add_wear(-(stack_def.groups.damage_per_use/8) or -625)
inv:set_stack(i, id, stack)
num_repaired = num_repaired + 1
end
end
end
end
if num_repaired ~= 0 then
minetest.log("action", "[rebreather] '"..name.."' Regenerates "..tostring(num_repaired).." rebreathers")
end
end
end

View File

@ -1,20 +1,23 @@
rebreather.add_rebreather("rebreather", "rebreather_rebreather.png", 3000)
rebreather.add_rebreather("diamond_rebreather", "rebreather_rebreather.png^[colorize:#00ddff77", 1500)
rebreather.add_rebreather("steel_rebreather", "rebreather_rebreather.png", 5000)
rebreather.add_rebreather("gold_rebreather", "rebreather_rebreather.png^[colorize:#dddd0088", 3000)
rebreather.add_rebreather("diamond_rebreather", "rebreather_rebreather.png^[colorize:#00ddff99", 2000)
local empty = ""
local iron = "default:steel_ingot"
local wool = "group:wool" -- Use groups!
local diamond = "default:diamond"
local gold = "default:gold_ingot"
if minetest.get_modpath("mcl_core") then
iron = "mcl_core:iron_ingot"
--wool = "mcl_wool:white"
diamond = "mcl_core:diamond"
gold = "mcl_core:gold_ingot"
end
minetest.register_craft({
output = "rebreather:rebreather",
output = "rebreather:steel_rebreather",
recipe = {
{wool, iron, wool},
{iron, empty, iron},
@ -22,11 +25,20 @@ minetest.register_craft({
}
})
minetest.register_craft({
output = "rebreather:gold_rebreather",
recipe = {
{wool, gold, wool},
{gold, "rebreather:steel_rebreather", gold},
{empty, gold, empty},
}
})
minetest.register_craft({
output = "rebreather:diamond_rebreather",
recipe = {
{wool, diamond, wool},
{diamond, "rebreather:rebreather", diamond},
{diamond, "rebreather:gold_rebreather", diamond},
{empty, diamond, empty}
}
})

View File

@ -4,6 +4,8 @@ rebreather = {}
rebreather.version = "1.0"
rebreather.debug = false
rebreather.debug_regeneration = false
rebreather.enable_builtin = true
rebreather.modpath = minetest.get_modpath("rebreather")
if minetest.get_modpath("default") then
@ -26,7 +28,10 @@ end
rebreather.items = {}
dofile(rebreather.modpath..DIR_DELIM.."api.lua")
dofile(rebreather.modpath..DIR_DELIM.."base_item.lua") -- A generic basic rebreather
dofile(rebreather.modpath..DIR_DELIM.."settings.lua")
if rebreather.enable_builtin == true then
dofile(rebreather.modpath..DIR_DELIM.."base_item.lua") -- Builtin rebreathers
end
local interval = 0.0 -- fire off once every second
minetest.register_globalstep(function (delta)

24
settings.lua Normal file
View File

@ -0,0 +1,24 @@
rebreather.debug = minetest.settings:get_bool("rebreather.debug")
if rebreather.debug == nil then
rebreather.debug = false
minetest.settings:set_bool("rebreather.debug", false)
end
rebreather.debug_regeneration = minetest.settings:get_bool("rebreather.debug_regeneration")
if rebreather.debug_regeneration == nil then
rebreather.debug_regeneration = false
minetest.settings:set_bool("rebreather.debug_regeneration", false)
end
rebreather.enable_builtin = minetest.settings:get_bool("rebreather.enable_builtin")
if rebreather.enable_builtin == nil then
rebreather.enable_builtin = true
minetest.settings:set_bool("rebreather.enable_builtin", true)
end
rebreather.enable_builtin_crafting = minetest.settings:get_bool("rebreather.enable_builtin_crafting")
if rebreather.enable_builtin_crafting == nil then
rebreather.enable_builtin_crafting = true
minetest.settings:set_bool("rebreather.enable_builtin_crafting", true)
end

12
settingtyps.txt Normal file
View File

@ -0,0 +1,12 @@
# Outputs extra debug information to minetest's logfile
rebreather.debug (Debug to Logs) bool false
# Outputs excess debug information specifically about the rebreather regeneration to minetest's logfile
rebreather.debug_regeneration (Debug regeneration section to Logs) bool false
# Are there the 3 pre-built rebreathers? (If false the mod becomes an API only)
rebreather.enable_builtin (Enable Builtin Rebreathers) bool true
# Can the 3 pre-built rebreathers be crafted. (If false then they can only be obtained by give or shops)
rebreather.enable_builtin_crafting (Enable the Builtin Rebreathers Crafting) bool true