mirror of
https://github.com/minetest-mods/airtanks.git
synced 2024-07-04 21:15:12 +02:00
add breathing tube
This commit is contained in:
parent
ca5de11915
commit
756833b855
93
init.lua
93
init.lua
@ -25,6 +25,10 @@ local function setting(stype, name, default, description)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
setting("int", "steel_uses", 30, "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)/2, "Number of uses for a bronze air tank")
|
||||||
|
|
||||||
local full_tank_desc = S("A tank containing compressed air.")
|
local full_tank_desc = S("A tank containing compressed air.")
|
||||||
local full_tank_help = 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 %i uses before it becomes empty.")
|
local full_tank_help = 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 %i uses before it becomes empty.")
|
||||||
|
|
||||||
@ -34,13 +38,12 @@ local empty_tank_help = S("This tank can be recharged with compressed air by usi
|
|||||||
local compressor_desc = S("A machine for filling air tanks with compressed air.")
|
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 = 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.")
|
||||||
|
|
||||||
setting("int", "steel_uses", 30, "Number of uses for a steel air tank")
|
local tube_desc = S("A breathing tube to allow automatic hands-free use of air tanks.")
|
||||||
setting("int", "copper_uses", 10, "Number of uses for a copper air tank")
|
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.")
|
||||||
setting("int", "bronze_uses", (config.steel_uses + config.copper_uses)/2, "Number of uses for a bronze air tank")
|
|
||||||
|
|
||||||
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 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 recharge_airtank = function(itemstack, user, pointed_thing, full_item)
|
local function recharge_airtank(itemstack, user, pointed_thing, full_item)
|
||||||
if pointed_thing.type ~= "node" then return itemstack end
|
if pointed_thing.type ~= "node" then return itemstack end
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
if minetest.get_item_group(node.name, "airtanks_compressor") > 0 then
|
if minetest.get_item_group(node.name, "airtanks_compressor") > 0 then
|
||||||
@ -71,8 +74,10 @@ local recharge_airtank = function(itemstack, user, pointed_thing, full_item)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
local use_airtank = function(itemstack, user, pointed_thing, uses, full_item, empty_item)
|
local function use_airtank(itemstack, user, pointed_thing, full_item)
|
||||||
itemstack = recharge_airtank(itemstack, user, pointed_thing, full_item) -- first check if we're clicking on a compressor
|
if pointed_thing then
|
||||||
|
itemstack = recharge_airtank(itemstack, user, pointed_thing, full_item) -- first check if we're clicking on a compressor
|
||||||
|
end
|
||||||
|
|
||||||
local breath = user:get_breath()
|
local breath = user:get_breath()
|
||||||
if breath > 9 then return itemstack end
|
if breath > 9 then return itemstack end
|
||||||
@ -82,14 +87,14 @@ local use_airtank = function(itemstack, user, pointed_thing, uses, full_item, em
|
|||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
local wdef = itemstack:get_definition()
|
local wdef = itemstack:get_definition()
|
||||||
itemstack:add_wear(65535/(uses-1))
|
itemstack:add_wear(65535/(wdef._airtank_uses-1))
|
||||||
if itemstack:get_count() == 0 then
|
if itemstack:get_count() == 0 then
|
||||||
if wdef.sound and wdef.sound.breaks then
|
if wdef.sound and wdef.sound.breaks then
|
||||||
minetest.sound_play(wdef.sound.breaks,
|
minetest.sound_play(wdef.sound.breaks,
|
||||||
{pos = user:getpos(), gain = 0.5})
|
{pos = user:getpos(), gain = 0.5})
|
||||||
end
|
end
|
||||||
local inv = user:get_inventory()
|
local inv = user:get_inventory()
|
||||||
itemstack = inv:add_item("main", empty_item)
|
itemstack = inv:add_item("main", wdef._airtank_empty)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
@ -117,17 +122,19 @@ local function register_air_tank(name, desc, color, uses, material)
|
|||||||
description = desc,
|
description = desc,
|
||||||
_doc_items_longdesc = full_tank_desc,
|
_doc_items_longdesc = full_tank_desc,
|
||||||
_doc_items_usagehelp = string.format(full_tank_help, uses),
|
_doc_items_usagehelp = string.format(full_tank_help, uses),
|
||||||
groups = {not_repaired_by_anvil = 1},
|
_airtank_uses = uses,
|
||||||
|
_airtank_empty = "airtanks:empty_"..name.."_tank",
|
||||||
|
groups = {not_repaired_by_anvil = 1, airtank = 1},
|
||||||
inventory_image = "airtanks_airtank.png^[multiply:"..color,
|
inventory_image = "airtanks_airtank.png^[multiply:"..color,
|
||||||
wield_image = "airtanks_airtank.png^[multiply:"..color,
|
wield_image = "airtanks_airtank.png^[multiply:"..color,
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
|
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
return use_airtank(itemstack, user, pointed_thing, uses, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
|
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return use_airtank(itemstack, user, pointed_thing, uses, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
|
return use_airtank(itemstack, user, pointed_thing, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -146,6 +153,9 @@ register_air_tank("steel", S("Steel Air Tank"), "#d6d6d6", config.steel_uses, "d
|
|||||||
register_air_tank("copper", S("Copper Air Tank"), "#cd8e54", config.copper_uses, "default:copper_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("bronze", S("Bronze Air Tank"), "#c87010", config.bronze_uses, "default:bronze_ingot")
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------------------------
|
||||||
|
-- Compressor
|
||||||
|
|
||||||
local sounds
|
local sounds
|
||||||
if default.node_sound_metal_defaults then -- 0.4.14 doesn't have metal sounds
|
if default.node_sound_metal_defaults then -- 0.4.14 doesn't have metal sounds
|
||||||
sounds = default.node_sound_metal_defaults()
|
sounds = default.node_sound_metal_defaults()
|
||||||
@ -184,4 +194,63 @@ minetest.register_craft({
|
|||||||
{"group:wood", "default:steel_ingot", "group:wood"},
|
{"group:wood", "default:steel_ingot", "group:wood"},
|
||||||
},
|
},
|
||||||
output = "airtanks:compressor"
|
output = "airtanks:compressor"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------------------------------------
|
||||||
|
-- breathing tube
|
||||||
|
|
||||||
|
minetest.register_craftitem("airtanks:breathing_tube", {
|
||||||
|
description = S("Breathing Tube"),
|
||||||
|
_doc_items_longdesc = tube_desc,
|
||||||
|
_doc_items_usagehelp = tube_help,
|
||||||
|
inventory_image = "airtanks_breathing_tube.png",
|
||||||
|
wield_image = "airtanks_breathing_tube.png",
|
||||||
|
stack_max = 99,
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
recipe = {
|
||||||
|
{"", "group:stick", ""},
|
||||||
|
{"", "group:stick", ""},
|
||||||
|
{"group:wood", "group:stick", ""},
|
||||||
|
},
|
||||||
|
output = "airtanks:breathing_tube"
|
||||||
|
})
|
||||||
|
|
||||||
|
local function tool_active(player, item)
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
local hotbar = player:hud_get_hotbar_itemcount()
|
||||||
|
for i=1, hotbar do
|
||||||
|
if inv:get_stack("main", i):get_name() == item then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function use_any_airtank(player)
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
local hotbar = player:hud_get_hotbar_itemcount()
|
||||||
|
for i=1, hotbar do
|
||||||
|
local itemstack = inv:get_stack("main", i)
|
||||||
|
if minetest.get_item_group(itemstack:get_name(), "airtank") > 0 then
|
||||||
|
itemstack = use_airtank(itemstack, player)
|
||||||
|
inv:set_stack("main", i, itemstack)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
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 not use_any_airtank(player) then
|
||||||
|
minetest.sound_play("airtanks_gasp", {pos = player:getpos(), gain = 0.5})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_playerevent(player_event_handler)
|
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2017-03-26 10:53-0600\n"
|
"POT-Creation-Date: 2017-03-27 14:50-0600\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -17,11 +17,11 @@ msgstr ""
|
|||||||
"Content-Type: text/plain; charset=CHARSET\n"
|
"Content-Type: text/plain; charset=CHARSET\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:28
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:32
|
||||||
msgid "A tank containing compressed air."
|
msgid "A tank containing compressed air."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:29
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:33
|
||||||
#, lua-format
|
#, lua-format
|
||||||
msgid ""
|
msgid ""
|
||||||
"If you're underwater and you're running out of breath, wield this item and "
|
"If you're underwater and you're running out of breath, wield this item and "
|
||||||
@ -29,44 +29,61 @@ msgid ""
|
|||||||
"tank has %i uses before it becomes empty."
|
"tank has %i uses before it becomes empty."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:31
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:35
|
||||||
msgid "A compressed air tank, currently empty."
|
msgid "A compressed air tank, currently empty."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:32
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:36
|
||||||
#, lua-format
|
#, lua-format
|
||||||
msgid ""
|
msgid ""
|
||||||
"This tank can be recharged with compressed air by using it on a compressor "
|
"This tank can be recharged with compressed air by using it on a compressor "
|
||||||
"block. When fully charged this tank has %i uses before it becomes empty."
|
"block. When fully charged this tank has %i uses before it becomes empty."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:34
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:38
|
||||||
msgid "A machine for filling air tanks with compressed air."
|
msgid "A machine for filling air tanks with compressed air."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:35
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:39
|
||||||
msgid ""
|
msgid ""
|
||||||
"Place this machine somewhere that it has access to air (one of its adjacent "
|
"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-"
|
"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."
|
"empty compressed air tank the tank will be refilled."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:100
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:41
|
||||||
|
msgid "A breathing tube to allow automatic hands-free use of air tanks."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:42
|
||||||
|
msgid ""
|
||||||
|
"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."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:105
|
||||||
msgid "Empty @1"
|
msgid "Empty @1"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:145
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:152
|
||||||
msgid "Steel Air Tank"
|
msgid "Steel Air Tank"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:146
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:153
|
||||||
msgid "Copper Air Tank"
|
msgid "Copper Air Tank"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:147
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:154
|
||||||
msgid "Bronze Air Tank"
|
msgid "Bronze Air Tank"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:157
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:167
|
||||||
msgid "Air Compressor"
|
msgid "Air Compressor"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:203
|
||||||
|
msgid "Breathing Tube"
|
||||||
|
msgstr ""
|
||||||
|
BIN
sounds/airtanks_gasp.ogg
Normal file
BIN
sounds/airtanks_gasp.ogg
Normal file
Binary file not shown.
BIN
textures/airtanks_breathing_tube.png
Normal file
BIN
textures/airtanks_breathing_tube.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 496 B |
Loading…
Reference in New Issue
Block a user