Skip to content

Commit

Permalink
Airtanks and breathing tube in armor slots (#8)
Browse files Browse the repository at this point in the history
Integrates MineClone/MineClonia so that those items can be used in the armor slot.
  • Loading branch information
nonfreegithub authored Oct 11, 2023
1 parent 443c635 commit 70d9f58
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
58 changes: 51 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -87,6 +89,9 @@ 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},}

Expand Down Expand Up @@ -144,11 +149,19 @@ local function register_air_tank(name, desc, color, uses, material)
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)
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)
end,
Expand Down Expand Up @@ -190,11 +203,19 @@ local function register_air_tank_2(name, desc, color, uses, material)
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)
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)
end,
Expand Down Expand Up @@ -243,11 +264,19 @@ local function register_air_tank_3(name, desc, color, uses, material)
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)
if has_mcl_armor then
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)
end,
Expand Down Expand Up @@ -356,7 +385,7 @@ local test_can_put = function(pos, listname, index, itemstack)
return 1
end
end
return 0
return 0
end
if listname == "fuel" then
local fuel, afterfuel = minetest.get_craft_result({method="fuel",width=1,items={itemstack:get_name()}})
Expand Down Expand Up @@ -593,6 +622,13 @@ minetest.register_craftitem("airtanks:breathing_tube", {
_doc_items_usagehelp = tube_help,
inventory_image = "airtanks_breathing_tube.png",
wield_image = "airtanks_breathing_tube.png",

_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({
Expand All @@ -606,9 +642,13 @@ minetest.register_craft({

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
Expand All @@ -617,12 +657,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)
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
Expand Down
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = airtanks
description = Provides pressurized air tanks for extended underwater excursions
depends =
optional_depends = doc, default, mcl_formspec, mcl_sounds, mcl_core, mcl_copper
optional_depends = doc, default, mcl_formspec, mcl_sounds, mcl_core, mcl_copper, mcl_armor
Binary file added textures/airtanks_chestplate_tank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/airtanks_chestplate_tank_three.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/airtanks_chestplate_tank_two.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/airtanks_helmet_tube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added textures/airtanks_helmet_tube_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70d9f58

Please sign in to comment.