Compare commits

...

10 commits

Author SHA1 Message Date
a47d4c9040 Change recipes 2025-06-15 18:49:49 +02:00
15f64201b6 Keep only steel tanks 2025-06-15 18:16:20 +02:00
Github is a non-free platform owned by Microsoft. Reasonable alternatives exist, such as Gitea, Sourcehut. We need a federated, mastodon-like forge based on ForgeFed. See: https://forgefed.org
f88520a24d
Fix duplicate in Mineclonia on_place (#11)
An itemstack must be returned to not duplicate the item.
2025-03-25 21:58:33 +01:00
Cpyte-Engine-Developer
2825e97bfd
Add Russian translation (#9) 2024-03-03 09:39:13 +01:00
Github is a non-free platform owned by Microsoft. Reasonable alternatives exist, such as Gitea, Sourcehut. We need a federated, mastodon-like forge based on ForgeFed. See: https://forgefed.org
70d9f58f6b
Airtanks and breathing tube in armor slots (#8)
Integrates MineClone/MineClonia so that those items can be used in the armor slot.
2023-10-11 20:04:20 +02:00
FaceDeer
443c635c00
initial compatibility work (#7) 2022-09-17 18:17:08 -06:00
FaceDeer
6f02c5ee64 empty airtanks were working with the breathing tube 2022-09-06 23:54:18 -06:00
FaceDeer
b686694979 pack the two and three tank art together more 2021-03-13 17:17:24 -07:00
FaceDeer
2bf396e5bf fancy compressor with formspec and fuel requirement (optional) 2021-03-13 02:19:11 -07:00
FaceDeer
1e85d0c309 bugfix - double and triple tanks were returning empty singles when used up 2021-03-11 22:46:11 -07:00
20 changed files with 473 additions and 146 deletions

View file

@ -2,8 +2,14 @@ A simple mod for extending one's underwater excursion time.
Air tanks are crafted from copper, steel, or bronze ingots and are wielded like tools. A compressor is crafted from steel, mese shard, and wood.
Place a compressor in world and click on it with an empty air tank to fill it. Compressors can also recharge partly-used tanks.
Place a compressor in world and click on it with an empty air tank to fill it. Compressors can also recharge partly-used tanks. Compressors require fuel, unless that configuration option has been disabled.
When running low on breath use a filled air tank to recharge your breath bar. One use will replenish 5 steps of breath (out of 10). By default a steel air tank will hold 30 uses, a bronze one holds 20, and a copper one holds 10 - these settings can be changed in the mod's section under Advanced Settings. Once a tank runs out of uses it turns into an empty tank, which can be recharged again with a compressor.
To automatically draw air from air tanks, craft a breathing tube and put it in your quick-use inventory row. When your breath bar drops below 5 steps it will automatically attempt to use an air tank from your quick-use inventory row to replenish it.
To automatically draw air from air tanks, craft a breathing tube and put it in your quick-use inventory row. When your breath bar drops below 5 steps it will automatically attempt to use an air tank from your quick-use inventory row to replenish it.
## Dependencies
This mod will work with either the default minetest_game (and most other games derived from it), or it will work with MineClone2 or MineClone5. Bronze ingots aren't available in Mineclone and so bronze tanks are not an option when running in that environment.
Although these games are listed as optional dependencies this mod will throw an assert if one of the two are not installed.

View file

@ -1,2 +0,0 @@
default
doc?

View file

@ -1 +0,0 @@
Provides pressurized air tanks for extended underwater excursions

528
init.lua
View file

@ -4,6 +4,8 @@ local print_settingtypes = false
local CONFIG_FILE_PREFIX = "airtanks_"
local config = {}
local has_mcl_armor = minetest.get_modpath("mcl_armor")
local function setting(stype, name, default, description)
local value
if stype == "bool" then
@ -25,72 +27,70 @@ end
-- Single tanks
setting("int", "steel_uses", 20, "Number of uses for a steel air tank")
setting("int", "copper_uses", 10, "Number of uses for a copper air tank")
setting("int", "bronze_uses", config.steel_uses + config.copper_uses, "Number of uses for a bronze air tank")
-- Double tanks
setting("bool", "enable_double", true, "Enable double tanks")
setting("int", "steel_2_uses", config.steel_uses * 2, "Number of uses for a pair of steel air tanks")
setting("int", "copper_2_uses", config.copper_uses * 2, "Number of uses for a pair of copper air tanks")
setting("int", "bronze_2_uses", config.bronze_uses * 2, "Number of uses for a pair of bronze air tanks")
-- Triple tanks
setting("bool", "enable_triple", true, "Enable triple tanks")
setting("int", "steel_3_uses", config.steel_uses * 3, "Number of uses for three steel air tanks")
setting("int", "copper_3_uses", config.copper_uses * 3, "Number of uses for threee copper air tanks")
setting("int", "bronze_3_uses", config.bronze_uses * 3, "Number of uses for three bronze air tanks")
setting("bool", "wear_in_creative", true, "Air tanks wear out in creative mode")
setting("bool", "compressor_needs_fuel", true, "Compressor needs fuel")
-- these may come from default or from mineclone mods
local steel_ingot
local mese_crystal_fragment
local get_itemslot_bg = function(x, y, w, h) return "" end
local get_hotbar_bg = function(x, y) return "" end
local sounds
if minetest.get_modpath("default") then
steel_ingot = "technic:stainless_steel_ingot"
mese_crystal_fragment = "default:mese_crystal_fragment"
get_hotbar_bg = default.get_hotbar_bg
sounds = default.node_sound_metal_defaults()
elseif minetest.get_modpath("mcl_core") then
steel_ingot = "mcl_core:iron_ingot"
mese_crystal_fragment = "mesecons:wire_00000000_off"
else
assert(false, "This mod requires either Mineclone or the default Minetest Game to be installed.")
end
if minetest.get_modpath("mcl_formspec") then
get_itemslot_bg = mcl_formspec.get_itemslot_bg
end
if minetest.get_modpath("mcl_sounds") then
sounds = mcl_sounds.node_sound_metal_defaults()
end
local compressor_desc = S("A machine for filling air tanks with compressed air.")
local compressor_help = S("Place this machine somewhere that it has access to air (one of its adjacent nodes needs to have air in it). When you click on it with an empty or partly-empty compressed air tank the tank will be refilled.")
local compressor_help
if config.compressor_needs_fuel then
compressor_help = S("This machine requires fuel to operate. Place something that can burn in the fuel slot, and then place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.")
else
compressor_help = S("Place place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.")
end
local tube_desc = S("A breathing tube to allow automatic hands-free use of air tanks.")
local tube_help = S("If this item is present in your quick-use inventory then whenever your breath bar goes below 5 it will automatically make use of any air tanks that are present in your quick-use inventory to replenish your breath supply. Note that it will not use air tanks that are present elsewhere in your inventory, only ones in your quick-use bar.")
if has_mcl_armor then
tube_help = S("If this item is present in your head armor slot then whenever your breath bar goes below 5 it will automatically make use of any air tanks that are present in your chestplate armor slot to replenish your breath supply. Note that it will not use air tanks that are present elsewhere in your inventory, only ones in your chestplate armor slot.")
end
local cardinal_dirs = {{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=0,y=0,z=1},{x=0,y=0,z=-1},}
local function recharge_airtank(itemstack, user, pointed_thing, full_item)
if pointed_thing.type ~= "node" then return itemstack end
local node = minetest.get_node(pointed_thing.under)
if minetest.get_item_group(node.name, "airtanks_compressor") > 0 then
local has_air = false
for _, dir in pairs(cardinal_dirs) do
if minetest.get_node(vector.add(pointed_thing.under, dir)).name == "air" then
has_air = true
break
end
end
if not has_air then
minetest.sound_play("airtanks_compressor_fail", {pos = pointed_thing.under, gain = 0.5})
return itemstack
end
if itemstack:get_name() == full_item then
itemstack:set_wear(0)
else
local inv = user:get_inventory()
if itemstack:get_count() == 1 then
itemstack = ItemStack(full_item) -- replace with new stack containing one full tank
else
local leftover = inv:add_item("main", full_item)
if leftover:get_count() == 0 then
itemstack:take_item(1)
end
end
end
minetest.sound_play("airtanks_compressor", {pos = pointed_thing.under, gain = 0.5})
end
return itemstack
-- For compressor code use later on
local max_uses = math.max(config.steel_uses)
if config.enable_triple then
max_uses = max_uses * 3
elseif config.enable_double then
max_uses = max_uses * 2
end
local function use_airtank(itemstack, user, pointed_thing, full_item)
if pointed_thing then
itemstack = recharge_airtank(itemstack, user, pointed_thing, full_item) -- first check if we're clicking on a compressor
end
local function use_airtank(itemstack, user)
local breath = user:get_breath()
if breath > 9 then return itemstack end
breath = math.min(10, breath+5)
@ -99,14 +99,14 @@ local function use_airtank(itemstack, user, pointed_thing, full_item)
if (not minetest.settings:get_bool("creative_mode")) or config.wear_in_creative then
local wdef = itemstack:get_definition()
itemstack:add_wear(65535/(wdef._airtank_uses-1))
itemstack:add_wear(65535/(wdef._airtanks_uses-1))
if itemstack:get_count() == 0 then
if wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks,
{pos = user:get_pos(), gain = 0.5})
end
local inv = user:get_inventory()
itemstack = inv:add_item("main", wdef._airtank_empty)
itemstack = inv:add_item("main", wdef._airtanks_empty)
end
end
return itemstack
@ -114,90 +114,96 @@ end
-- This will only work for single use tanks... we need to add separate functions for the others
local function register_air_tank(name, desc, color, uses, material)
if not material then return end
minetest.register_craftitem("airtanks:empty_"..name.."_tank", {
description = S("Empty @1", desc),
groups = {airtank = 1},
_doc_items_longdesc = S("A compressed air tank, currently empty."),
_doc_items_usagehelp = S("This tank can be recharged with compressed air by using it on a compressor block. When fully charged this tank has @1 uses before it becomes empty.", uses),
_airtanks_uses = uses,
_airtanks_full = "airtanks:"..name.."_tank",
inventory_image = "airtanks_airtank.png^[colorize:"..color.."^[mask:airtanks_airtank.png^airtanks_empty.png",
wield_image = "airtanks_airtank.png^[colorize:"..color.."^[mask:airtanks_airtank.png^airtanks_empty.png",
stack_max = 99,
on_place = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank")
end,
on_use = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank")
end,
})
minetest.register_tool("airtanks:"..name.."_tank", {
description = desc,
_doc_items_longdesc = S("A tank containing compressed air."),
_doc_items_usagehelp = S("If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged this tank has @1 uses before it becomes empty.", uses),
_airtank_uses = uses,
_airtank_empty = "airtanks:empty_"..name.."_tank",
groups = {not_repaired_by_anvil = 1, airtank = 1},
_airtanks_uses = uses,
_airtanks_empty = "airtanks:empty_"..name.."_tank",
groups = {not_repaired_by_anvil = 1, airtank = 2},
inventory_image = "airtanks_airtank.png^[colorize:"..color.."^[mask:airtanks_airtank.png",
wield_image = "airtanks_airtank.png^[colorize:"..color.."^[mask:airtanks_airtank.png",
stack_max = 1,
_mcl_armor_element = "torso",
_mcl_armor_texture = "airtanks_chestplate_tank.png",
on_place = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
if has_mcl_armor then
return mcl_armor.equip_on_use(itemstack, user, pointed_thing)
else
return use_airtank(itemstack, user)
end
end,
on_secondary_use = has_mcl_armor and mcl_armor.equip_on_use,
on_use = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
return use_airtank(itemstack, user)
end,
})
minetest.register_craft({
recipe = {
{"", material, ""},
{material, "airtanks:compressor", material},
{material, "technic:rubber", material},
{material, "default:mese_crystal_fragment", material},
{"", material, ""},
},
output = "airtanks:empty_"..name.."_tank",
replacements = {{"airtanks:compressor", "airtanks:compressor"}},
})
end
local function register_air_tank_2(name, desc, color, uses)
local function register_air_tank_2(name, desc, color, uses, material)
if not material then return end
minetest.register_craftitem("airtanks:empty_"..name.."_tank_2", {
description = S("Empty @1", desc),
groups = {airtank = 1},
_doc_items_longdesc = S("A pair of compressed air tanks, currently empty."),
_doc_items_usagehelp = S("This tank can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.", uses),
_airtanks_uses = uses,
_airtanks_full = "airtanks:"..name.."_tank_2",
inventory_image = "airtanks_airtank_two.png^[colorize:"..color.."^[mask:airtanks_airtank_two.png^airtanks_empty.png",
wield_image = "airtanks_airtank_two.png^[colorize:"..color.."^[mask:airtanks_airtank_two.png^airtanks_empty.png",
stack_max = 99,
on_place = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_2")
end,
on_use = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_2")
end,
})
minetest.register_tool("airtanks:"..name.."_tank_2", {
description = desc,
_doc_items_longdesc = S("A pair of tanks containing compressed air."),
_doc_items_usagehelp = S("If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged these tanks have @1 uses before it becomes empty.", uses),
_airtank_uses = uses,
_airtank_empty = "airtanks:empty_"..name.."_tank",
groups = {not_repaired_by_anvil = 1, airtank = 1},
_airtanks_uses = uses,
_airtanks_empty = "airtanks:empty_"..name.."_tank_2",
groups = {not_repaired_by_anvil = 1, airtank = 2},
inventory_image = "airtanks_airtank_two.png^[colorize:"..color.."^[mask:airtanks_airtank_two.png",
wield_image = "airtanks_airtank_two.png^[colorize:"..color.."^[mask:airtanks_airtank_two.png",
stack_max = 1,
_mcl_armor_element = "torso",
_mcl_armor_texture = "airtanks_chestplate_tank_two.png",
on_place = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_2", "airtanks:empty_"..name.."_tank_2")
if has_mcl_armor then
return mcl_armor.equip_on_use(itemstack, user, pointed_thing)
else
return use_airtank(itemstack, user)
end
end,
on_secondary_use = has_mcl_armor and mcl_armor.equip_on_use,
on_use = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_2", "airtanks:empty_"..name.."_tank_2")
return use_airtank(itemstack, user)
end,
})
@ -205,6 +211,7 @@ local function register_air_tank_2(name, desc, color, uses)
minetest.register_craft({
recipe = {
-- Use 2 singles to make a double
{"technic:rubber", "pipeworks:pipe_1_empty"},
{"airtanks:empty_"..name.."_tank", "airtanks:empty_"..name.."_tank"},
},
output = "airtanks:empty_"..name.."_tank_2",
@ -213,6 +220,7 @@ local function register_air_tank_2(name, desc, color, uses)
minetest.register_craft({
recipe = {
-- Use 2 singles to make a double
{"technic:rubber", "pipeworks:pipe_1_empty"},
{"airtanks:"..name.."_tank", "airtanks:"..name.."_tank"},
},
output = "airtanks:"..name.."_tank_2",
@ -220,48 +228,54 @@ local function register_air_tank_2(name, desc, color, uses)
end
local function register_air_tank_3(name, desc, color, uses)
local function register_air_tank_3(name, desc, color, uses, material)
if not material then return end
minetest.register_craftitem("airtanks:empty_"..name.."_tank_3", {
description = S("Empty @1", desc),
groups = {airtank = 1},
_doc_items_longdesc = S("A set of three compressed air tanks, currently empty."),
_doc_items_usagehelp = S("These tanks can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.", uses),
_airtanks_uses = uses,
_airtanks_full = "airtanks:"..name.."_tank_3",
inventory_image = "airtanks_airtank_three.png^[colorize:"..color.."^[mask:airtanks_airtank_three.png^airtanks_empty.png",
wield_image = "airtanks_airtank_three.png^[colorize:"..color.."^[mask:airtanks_airtank_three.png^airtanks_empty.png",
stack_max = 99,
on_place = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_3")
end,
on_use = function(itemstack, user, pointed_thing)
return recharge_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_3")
end,
})
minetest.register_tool("airtanks:"..name.."_tank_3", {
description = desc,
_doc_items_longdesc = S("A set of three tanks containing compressed air."),
_doc_items_usagehelp = S("If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged these tanks have @1 uses before it becomes empty.", uses),
_airtank_uses = uses,
_airtank_empty = "airtanks:empty_"..name.."_tank",
groups = {not_repaired_by_anvil = 1, airtank = 1},
_airtanks_uses = uses,
_airtanks_empty = "airtanks:empty_"..name.."_tank_3",
groups = {not_repaired_by_anvil = 1, airtank = 2},
inventory_image = "airtanks_airtank_three.png^[colorize:"..color.."^[mask:airtanks_airtank_three.png",
wield_image = "airtanks_airtank_three.png^[colorize:"..color.."^[mask:airtanks_airtank_three.png",
stack_max = 1,
_mcl_armor_element = "torso",
_mcl_armor_texture = "airtanks_chestplate_tank_three.png",
on_place = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_3", "airtanks:empty_"..name.."_tank_3")
if has_mcl_armor then
return mcl_armor.equip_on_use(itemstack, user, pointed_thing)
else
return use_airtank(itemstack, user)
end
end,
on_secondary_use = has_mcl_armor and mcl_armor.equip_on_use,
on_use = function(itemstack, user, pointed_thing)
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank_3", "airtanks:empty_"..name.."_tank_3")
return use_airtank(itemstack, user)
end,
})
-- Allow empty tanks
minetest.register_craft({
recipe = {
-- Use 3 singles to make a triple
{"", "pipeworks:pipe_1_empty", ""},
{"technic:rubber", "pipeworks:pipe_1_empty", "technic:rubber"},
{"airtanks:empty_"..name.."_tank", "airtanks:empty_"..name.."_tank", "airtanks:empty_"..name.."_tank"},
},
output = "airtanks:empty_"..name.."_tank_3",
@ -269,7 +283,8 @@ local function register_air_tank_3(name, desc, color, uses)
minetest.register_craft({
recipe = {
-- Use 1 single and 1 double to make a triple
{"airtanks:empty_"..name.."_tank", "airtanks:empty_"..name.."_tank_2", ""},
{"technic:rubber", "pipeworks:pipe_1_empty"},
{"airtanks:empty_"..name.."_tank", "airtanks:empty_"..name.."_tank_2"},
},
output = "airtanks:empty_"..name.."_tank_3",
})
@ -277,6 +292,8 @@ local function register_air_tank_3(name, desc, color, uses)
minetest.register_craft({
recipe = {
-- Use 3 singles to make a triple
{"", "pipeworks:pipe_1_empty", ""},
{"technic:rubber", "pipeworks:pipe_1_empty", "technic:rubber"},
{"airtanks:"..name.."_tank", "airtanks:"..name.."_tank", "airtanks:"..name.."_tank"},
},
output = "airtanks:"..name.."_tank_3",
@ -284,50 +301,244 @@ local function register_air_tank_3(name, desc, color, uses)
minetest.register_craft({
recipe = {
-- Use 1 single and 1 double to make a triple
{"airtanks:"..name.."_tank", "airtanks:"..name.."_tank_2", ""},
{"technic:rubber", "pipeworks:pipe_1_empty"},
{"airtanks:"..name.."_tank", "airtanks:"..name.."_tank_2"},
},
output = "airtanks:"..name.."_tank_3",
})
end
register_air_tank("steel", S("Steel Air Tank"), "#d6d6d6", config.steel_uses, "default:steel_ingot")
register_air_tank("copper", S("Copper Air Tank"), "#cd8e54", config.copper_uses, "default:copper_ingot")
register_air_tank("bronze", S("Bronze Air Tank"), "#c87010", config.bronze_uses, "default:bronze_ingot")
register_air_tank("steel", S("Steel Air Tank"), "#d6d6d6", config.steel_uses, steel_ingot)
if config.enable_double then
register_air_tank_2("steel", S("Double Steel Air Tanks"), "#d6d6d6", config.steel_2_uses)
register_air_tank_2("copper", S("Double Copper Air Tanks"), "#cd8e54", config.copper_2_uses)
register_air_tank_2("bronze", S("Double Bronze Air Tanks"), "#c87010", config.bronze_2_uses)
register_air_tank_2("steel", S("Double Steel Air Tanks"), "#d6d6d6", config.steel_2_uses, steel_ingot)
end
if config.enable_triple then
register_air_tank_3("steel", S("Triple Steel Air Tanks"), "#d6d6d6", config.steel_3_uses)
register_air_tank_3("copper", S("Triple Copper Air Tanks"), "#cd8e54", config.copper_3_uses)
register_air_tank_3("bronze", S("Triple Bronze Air Tanks"), "#c87010", config.bronze_3_uses)
register_air_tank_3("steel", S("Triple Steel Air Tanks"), "#d6d6d6", config.steel_3_uses, steel_ingot)
end
---------------------------------------------------------------------------------------------------------
-- Compressor
local sounds
if default.node_sound_metal_defaults then -- 0.4.14 doesn't have metal sounds
sounds = default.node_sound_metal_defaults()
local tank_inv_size = 4*4
local get_compressor_formspec
if config.compressor_needs_fuel then
get_compressor_formspec = function(remaining_time)
local formspec =
"size[8,9]" ..
"label[1,1.5;" .. S("Fuel") .. "]" ..
get_itemslot_bg(1,2,1,1) ..
"list[context;fuel;1,2;1,1;]" ..
"label[4.5,0;" .. S("Tanks") .. "]" ..
"label[2,2;" .. S("Pressure:\n@1", remaining_time) .. "]" ..
get_itemslot_bg(3,0.5,4,4) ..
"list[context;tanks;3,0.5;4,4;]" ..
get_itemslot_bg(0,4.85,8,1) ..
"list[current_player;main;0,4.85;8,1;]" ..
get_itemslot_bg(0,6.08,8,3) ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[context;tanks]" ..
"listring[current_player;main]" ..
get_hotbar_bg(0,4.85)
return formspec
end
else
sounds = default.node_sound_stone_defaults()
get_compressor_formspec = function()
local formspec =
"size[8,9]" ..
"label[3.5,0;" .. S("Tanks") .. "]" ..
get_itemslot_bg(2,0.5,4,4) ..
"list[context;tanks;2,0.5;4,4;]" ..
get_itemslot_bg(0,4.85,8,1) ..
"list[current_player;main;0,4.85;8,1;]" ..
get_itemslot_bg(0,6.08,8,3) ..
"list[current_player;main;0,6.08;8,3;8]" ..
"listring[context;tanks]" ..
"listring[current_player;main]" ..
get_hotbar_bg(0,4.85)
return formspec
end
end
-- ensures only valid items can be placed into compressor inventories
local test_can_put = function(pos, listname, index, itemstack)
if listname == "tanks" then
if minetest.get_item_group(itemstack:get_name(), "airtank") > 0 then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:get_stack(listname, index):get_count() == 0 then
return 1
end
end
return 0
end
if listname == "fuel" then
local fuel, afterfuel = minetest.get_craft_result({method="fuel",width=1,items={itemstack:get_name()}})
if fuel.time ~= 0 then
return itemstack:get_count()
end
return 0
end
return itemstack:get_count()
end
-- whenever an inventory action is performed, makes sure there's a timer running
local ensure_timer = function(pos)
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(1)
end
end
-- Locates the target tank to fill
local find_most_fillable = function(inv)
local most_fillable_index = 0
local most_fillable_capacity = 0
local most_fillable_needs = max_uses + 1
local most_fillable_stack
local most_fillable_def
for i = 1, tank_inv_size do
local tank = inv:get_stack("tanks", i)
local count = tank:get_count() -- for sanity-checking purposes
if count > 1 then
minetest.log("error", "[airtanks] Compressor at " .. minetest.pos_to_string(pos)
.. " had a tank stack with more than one tank in it. Currently not something that's"
.. " handled gracefully.")
return false
elseif count == 1 then
local tank_def = tank:get_definition()
local tank_capacity = tank_def._airtanks_uses
local tank_needs
if tank_def._airtanks_full then
tank_needs = tank_capacity -- this is an empty tank
else
tank_needs = tank_capacity * (tank:get_wear() / 65535)
end
if tank_needs > 0 then -- ignore tanks that are already full
if tank_capacity > most_fillable_capacity then -- fill biggest tanks first
most_fillable_needs = max_uses + 1
most_fillable_capacity = tank_capacity
end
if tank_needs < most_fillable_needs then-- fill tanks closest to being full first
most_fillable_needs = tank_needs
end
if most_fillable_capacity == tank_capacity and most_fillable_needs == tank_needs then
most_fillable_index = i
most_fillable_stack = tank
most_fillable_def = tank_def
end
end
end
end
return most_fillable_index, most_fillable_stack, most_fillable_def
end
local compressor_timestep_with_fuel = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local fuel_time = meta:get_float("fuel_time")
if (fuel_time < 1 and inv:is_empty("fuel")) or inv:is_empty("tanks") then
return false
end
local most_fillable_index, most_fillable_stack, most_fillable_def = find_most_fillable(inv)
if most_fillable_index == 0 then
return false
end
-- we now have a tank to fill. Do we have enough fuel?
if fuel_time < 1 then
local fuel_item = inv:get_stack("fuel", 1) -- there should be something here or we would have exited early above
fuel_item:set_count(1)
local fuel_item = inv:remove_item("fuel", fuel_item)
local burn = minetest.get_craft_result({method="fuel",width=1,items={fuel_item:get_name()}})
fuel_time = fuel_time + burn.time
end
if fuel_time < 1 then
-- this fuel source is producing less than 1 second of burn time. Weird, but maybe so.
-- don't refill yet, just update the fuel burned and try again.
-- this is an edge case so I'm not too worried about efficiency here
meta:set_float("fuel_time", fuel_time)
return true
end
fuel_time = fuel_time - 1
local wear_per_use = 65535/most_fillable_def._airtanks_uses
if most_fillable_def._airtanks_full then
-- we're starting with a completely empty tank, turn it into a full tank and add wear.
most_fillable_stack = ItemStack(most_fillable_def._airtanks_full)
most_fillable_stack:set_wear(65535 - wear_per_use)
else
most_fillable_stack:set_wear(math.max(most_fillable_stack:get_wear() - wear_per_use, 0))
end
inv:set_stack("tanks", most_fillable_index, most_fillable_stack)
meta:set_float("fuel_time", fuel_time)
return true
end
local compressor_timestep_without_fuel = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("tanks") then
return false
end
local most_fillable_index, most_fillable_stack, most_fillable_def = find_most_fillable(inv)
if most_fillable_index == 0 then
return false
end
local wear_per_use = 65535/most_fillable_def._airtanks_uses
if most_fillable_def._airtanks_full then
-- we're starting with a completely empty tank, turn it into a full tank and add wear.
most_fillable_stack = ItemStack(most_fillable_def._airtanks_full)
most_fillable_stack:set_wear(65535 - wear_per_use)
else
most_fillable_stack:set_wear(math.max(most_fillable_stack:get_wear() - wear_per_use, 0))
end
inv:set_stack("tanks", most_fillable_index, most_fillable_stack)
return true
end
local compressor_timestep
if config.compressor_needs_fuel then
compressor_timestep = compressor_timestep_with_fuel
else
compressor_timestep = compressor_timestep_without_fuel
end
local compressor_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
inv:set_size("tanks", tank_inv_size)
meta:set_float("fuel_time", 0)
meta:set_string("formspec", get_compressor_formspec(0))
end
minetest.register_node("airtanks:compressor", {
description = S("Air Compressor"),
_doc_items_longdesc = compressor_desc,
_doc_items_usagehelp = compressor_help,
groups = {oddly_breakable_by_hand = 1, airtanks_compressor = 1},
groups = {oddly_breakable_by_hand = 1, airtanks_compressor = 1, handy = 1},
sounds = sounds,
tiles = {
"airtanks_compressor_bottom.png^[transformR90",
"airtanks_compressor_bottom.png^[transformR90",
"airtanks_compressor.png"
},
use_texture_alpha = "clip",
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
@ -338,14 +549,54 @@ minetest.register_node("airtanks:compressor", {
{-0.3125, -0.5, -0.375, 0.3125, 0.125, 0.375},
{-0.125, 0.125, -0.25, 0.125, 0.4375, 0.25},
}
}
},
on_construct = compressor_construct,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("fuel") and inv:is_empty("tanks")
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return test_can_put(pos, to_list, to_index, stack)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
return test_can_put(pos, listname, index, stack)
end,
on_metadata_inventory_move = ensure_timer,
on_metadata_inventory_put = ensure_timer,
on_metadata_inventory_take = ensure_timer,
on_timer = function(pos, elapsed)
local meta = minetest.get_meta(pos)
local last_return = true
while elapsed > 0 and last_return == true do
last_return = compressor_timestep(pos)
elapsed = elapsed - 1
end
if last_return == true then
minetest.sound_play("airtanks_compressor", {pos = pos, gain = 0.5})
minetest.get_node_timer(pos):start(1)
meta:set_string("last_state", "success")
elseif meta:get("last_state") == "success" then
minetest.sound_play("airtanks_compressor_fail", {pos = pos, gain = 0.5})
meta:set_string("last_state", "fail")
end
meta:set_string("formspec", get_compressor_formspec(math.floor(meta:get_float("fuel_time"))))
end
})
minetest.register_craft({
recipe = {
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
{"group:wood", "default:steel_ingot", "group:wood"},
{"technic:rubber", mese_crystal_fragment, "technic:rubber"},
{steel_ingot, "technic:machine_casing", steel_ingot},
{"basic_materials:gear_steel", steel_ingot, "mesecons_pistons:piston_normal_off"},
},
output = "airtanks:compressor"
})
@ -359,23 +610,33 @@ minetest.register_craftitem("airtanks:breathing_tube", {
_doc_items_usagehelp = tube_help,
inventory_image = "airtanks_breathing_tube.png",
wield_image = "airtanks_breathing_tube.png",
stack_max = 99,
_mcl_armor_element = "head",
_mcl_armor_texture = "airtanks_helmet_tube.png",
_mcl_armor_preview = "airtanks_helmet_tube_preview.png",
on_place = has_mcl_armor and mcl_armor.equip_on_use,
on_secondary_use = has_mcl_armor and mcl_armor.equip_on_use,
})
minetest.register_craft({
recipe = {
{"", "group:stick", ""},
{"", "group:stick", ""},
{"group:wood", "group:stick", ""},
{"", "pipeworks:pipe_1_empty", ""},
{"", "pipeworks:pipe_1_empty", ""},
{"technic:rubber", "", ""},
},
output = "airtanks:breathing_tube"
})
local function tool_active(player, item)
local inv = player:get_inventory()
local inv_list = "main"
local hotbar = player:hud_get_hotbar_itemcount()
if has_mcl_armor then
inv_list = "armor"
end
for i=1, hotbar do
if inv:get_stack("main", i):get_name() == item then
if inv:get_stack(inv_list, i):get_name() == item then
return true
end
end
@ -384,12 +645,16 @@ end
local function use_any_airtank(player)
local inv = player:get_inventory()
local inv_list = "main"
local hotbar = player:hud_get_hotbar_itemcount()
if has_mcl_armor then
inv_list = "armor"
end
for i=1, hotbar do
local itemstack = inv:get_stack("main", i)
if minetest.get_item_group(itemstack:get_name(), "airtank") > 0 then
local itemstack = inv:get_stack(inv_list, i)
if minetest.get_item_group(itemstack:get_name(), "airtank") > 1 then
itemstack = use_airtank(itemstack, player)
inv:set_stack("main", i, itemstack)
inv:set_stack(inv_list, i, itemstack)
return true
end
end
@ -397,8 +662,7 @@ local function use_any_airtank(player)
end
local function player_event_handler(player, eventname)
assert(player:is_player())
if eventname == "breath_changed" and player:get_breath() < 5 and tool_active(player, "airtanks:breathing_tube") then
if player:is_player() and eventname == "breath_changed" and player:get_breath() < 5 and tool_active(player, "airtanks:breathing_tube") then
if not use_any_airtank(player) then
minetest.sound_play("airtanks_gasp", {pos = player:get_pos(), gain = 0.5})
end
@ -409,3 +673,15 @@ end
minetest.register_playerevent(player_event_handler)
-----------------------------------------------------------------------------------------
-- Update old compressors
minetest.register_lbm({
label = "Upgrade airtanks compressors",
name = "airtanks:upgrade_compressors",
nodenames = {"airtanks:compressor"},
run_at_every_load = false,
action = function(pos, node)
compressor_construct(pos)
end,
})

View file

@ -20,15 +20,10 @@ A tank containing compressed air.=
Air Compressor=
#item name, a snorkel mouthpiece for breathing underwater
Breathing Tube=
#compressed air tank made of bronze
Bronze Air Tank=
#compressed air tank made of copper
Copper Air Tank=
Double Bronze Air Tanks=
Double Copper Air Tanks=
Double Steel Air Tanks=
#for indicating that a particular type of air tank is empty
Empty @1=
Fuel=
#documentation text
If this item is present in your quick-use inventory then whenever your breath bar goes below 5 it will automatically make use of any air tanks that are present in your quick-use inventory to replenish your breath supply. Note that it will not use air tanks that are present elsewhere in your inventory, only ones in your quick-use bar.=
@ -38,19 +33,20 @@ If you're underwater and you're running out of breath, wield this item and use i
#documentation text
If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged this tank has @1 uses before it becomes empty.=
#documentation text
Place this machine somewhere that it has access to air (one of its adjacent nodes needs to have air in it). When you click on it with an empty or partly-empty compressed air tank the tank will be refilled.=
Place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.=
Pressure:@n@1=
#compressed air tank made of steel
Steel Air Tank=
Tanks=
These tanks can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.=
This machine requires fuel to operate. Place something that can burn in the fuel slot, and then place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.=
This tank can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.=
#documentation text
This tank can be recharged with compressed air by using it on a compressor block. When fully charged this tank has @1 uses before it becomes empty.=
Triple Bronze Air Tanks=
Triple Copper Air Tanks=
Triple Steel Air Tanks=

53
locale/translate.ru.tr Normal file
View file

@ -0,0 +1,53 @@
# textdomain: airtanks
### init.lua ###
#documentation text
A breathing tube to allow automatic hands-free use of air tanks.=Дыхательная трубка позволяет автоматически использовать воздушный баллон без рук.
#documentation text
A compressed air tank, currently empty.=Пустой баллон сжатого воздуха.
#documentation text
A machine for filling air tanks with compressed air.=Устройство для заполнения баллонов сжатым воздухом.
A pair of compressed air tanks, currently empty.=Пара пустых баллонов сжатого воздуха.
A pair of tanks containing compressed air.=Пара заполненных баллонов сжатого воздуха.
A set of three compressed air tanks, currently empty.=Набор из 3-ех пустых баллонов сжатого воздуха.
A set of three tanks containing compressed air.=Набор из 3-ех заполненных баллонов сжатого воздуха
#documentation text
A tank containing compressed air.=Баллон содержащий сжатый воздух.
#node name, compresses air to fill pressurized gas tanks
Air Compressor=Воздушный компрессор
#item name, a snorkel mouthpiece for breathing underwater
Breathing Tube=Дыхательная трубка
#compressed air tank made of bronze
Double Steel Air Tanks=Двойной стальной воздушный баллон
#for indicating that a particular type of air tank is empty
Empty @1=Пустой @1
Fuel=Топливо
#documentation text
If this item is present in your quick-use inventory then whenever your breath bar goes below 5 it will automatically make use of any air tanks that are present in your quick-use inventory to replenish your breath supply. Note that it will not use air tanks that are present elsewhere in your inventory, only ones in your quick-use bar.=Если этот предмет находится в ячейке быстрого доступа, то когда останется меньше 5 пузырьков воздуха игрок автоматически испоьзует воздушный баллон находящийся в слоте быстрого доступа который заполнит запасы воздуха. Запомните, что автоматически будут использоваться только баллоны находящиеся в слотах быстрого доступа.
If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged these tanks have @1 uses before it becomes empty.=Если вы находитесь под водой и вы задыхаетесь, наденьте этот предмет и используйте его для восстановления 5 пузырьков. Полностью заполненные баллоны могут быть использованы @1 раз.
#documentation text
If you're underwater and you're running out of breath, wield this item and use it to replenish 5 bubbles on your breath bar. When fully charged this tank has @1 uses before it becomes empty.=Если вы находитесь под водой и вы задыхаетесь, наденьте этот предмет и используйте его для восстановления 5 пузырьков. Полностью заполненные баллон может быть использован @1 раз.
Place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.=Разместите пустые баллоны в инвентаре справа. Компресор автоматически заполнит их воздухом.
Pressure:@n@1=Давление:@n@1
#compressed air tank made of steel
Steel Air Tank=Стальной воздушный баллон
Tanks=Баллоны
These tanks can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.=Эти баллоны могут быть заполнены сжатым воздухом с помощью компрессора. Полностью запоненные баллоны могут быть использованы @1 раз.
This machine requires fuel to operate. Place something that can burn in the fuel slot, and then place empty tanks in the inventory to the right. The compressor will start filling the largest capacity tanks first.=Это устройство требует топливо дл работы. Поместите что-то в слот с топливом, а потом положите пустые баллоны в инвентарь справа. Компрессор заполнит сперва баллоны с самм большим объемом.
This tank can be recharged with compressed air by using it on a compressor block. When fully charged these tanks have @1 uses before it becomes empty.=Этот баллон может быть заполнен сжатым воздухом с помощью компрессора. Полностью заполненный баллон может быть использован @1 раз.
#documentation text
This tank can be recharged with compressed air by using it on a compressor block. When fully charged this tank has @1 uses before it becomes empty.=Этот баллон может быть заполнен с помощью компрессора. Полностью заполненный баллон может быть использован @1 раз.
Triple Steel Air Tanks=Тройной стальной баллон

View file

@ -1,4 +1,4 @@
name = airtanks
description = Provides pressurized air tanks for extended underwater excursions
depends = default
optional_depends = doc
depends = technic, basic_materials, mesecons_pistons, pipeworks
optional_depends = doc, default, mcl_formspec, mcl_sounds, mcl_core, mcl_copper, mcl_armor

View file

@ -1,6 +1,5 @@
airtanks_steel_uses (Number of uses for a steel air tank) int 30 2 1000
airtanks_copper_uses (Number of uses for a copper air tank) int 10 2 1000
airtanks_bronze_uses (Number of uses for a bronze air tank) int 20 2 1000
airtanks_wear_in_creative (Air tanks wear out in creative mode) bool true
airtanks_enable_double (Enable double tanks) bool true
airtanks_enable_triple (Enable triple tanks) bool true
airtanks_enable_triple (Enable triple tanks) bool true
airtanks_compressor_needs_fuel (Compressor requires fuel) bool true

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 333 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 B

After

Width:  |  Height:  |  Size: 669 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 424 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 B

After

Width:  |  Height:  |  Size: 398 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 850 B

After

Width:  |  Height:  |  Size: 843 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 629 B

After

Width:  |  Height:  |  Size: 627 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 137 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 B