diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..93957ee --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Sounds are under various licenses, see the license.txt file in the /sounds directory for details. + +License for Code and Textures +----------------------------- + +Copyright (C) 2017 FaceDeer + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..331d858 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..723a376 --- /dev/null +++ b/init.lua @@ -0,0 +1,150 @@ +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + +local print_settingtypes = false +local CONFIG_FILE_PREFIX = "airtanks_" +local config = {} + +local function setting(stype, name, default, description) + local value + if stype == "bool" then + value = minetest.setting_getbool(CONFIG_FILE_PREFIX..name) + elseif stype == "string" then + value = minetest.setting_get(CONFIG_FILE_PREFIX..name) + elseif stype == "int" or stype == "float" then + value = tonumber(minetest.setting_get(CONFIG_FILE_PREFIX..name)) + end + if value == nil then + value = default + end + config[name] = value + + if print_settingtypes then + minetest.debug(CONFIG_FILE_PREFIX..name.." ("..description..") "..stype.." "..tostring(default)) + 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 recharge_airtank = function(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 + if itemstack:get_name() == full_item then + itemstack:set_wear(0) + else + local inv = user:get_inventory() + local leftover = inv:add_item("main", full_item) + if leftover:get_count() == 0 then + itemstack:set_count(itemstack:get_count()-1) + end + end + minetest.sound_play("airtanks_compressor", {pos = pointed_thing.under, gain = 0.5}) + end + return itemstack +end + +local use_airtank = function(itemstack, user, pointed_thing, uses, full_item, empty_item) + itemstack = recharge_airtank(itemstack, user, pointed_thing, full_item) -- first check if we're clicking on a compressor + + local breath = user:get_breath() + if breath > 9 then return itemstack end + breath = math.min(10, breath+5) + user:set_breath(breath) + minetest.sound_play("airtanks_hiss", {pos = user:getpos(), gain = 0.5}) + + if not minetest.setting_getbool("creative_mode") then + local wdef = itemstack:get_definition() + itemstack:add_wear(65535/(uses-1)) + if itemstack:get_count() == 0 then + if wdef.sound and wdef.sound.breaks then + minetest.sound_play(wdef.sound.breaks, + {pos = user:getpos(), gain = 0.5}) + end + local inv = user:get_inventory() + itemstack = inv:add_item("main", empty_item) + end + end + return itemstack +end + +local function register_air_tank(name, desc, color, uses, material) + minetest.register_craftitem("airtanks:empty_"..name.."_tank", { + description = S("Empty @1", desc), + inventory_image = "airtanks_airtank.png^[multiply:"..color.."^airtanks_empty.png", + wield_image = "airtanks_airtank.png^[multiply:"..color.."^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, + groups = {not_repaired_by_anvil = 1}, + inventory_image = "airtanks_airtank.png^[multiply:"..color, + wield_image = "airtanks_airtank.png^[multiply:"..color, + stack_max = 1, + + on_place = function(itemstack, user, pointed_thing) + return use_airtank(itemstack, user, pointed_thing, uses, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank") + end, + + on_use = function(itemstack, user, pointed_thing) + return use_airtank(itemstack, user, pointed_thing, uses, "airtanks:"..name.."_tank", "airtanks:empty_"..name.."_tank") + end, + }) + + minetest.register_craft({ + recipe = { + {"", material, ""}, + {material, "", material}, + {"", material, ""}, + }, + output = "airtanks:empty_"..name.."_tank" + }) + +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") + +minetest.register_node("airtanks:compressor", { + description = S("Air Compressor"), + groups = {oddly_breakable_by_hand = 1, airtanks_compressor = 1}, + sounds = default.node_sound_metal_defaults(), + tiles = { + "airtanks_compressor_bottom.png^[transformR90", + "airtanks_compressor_bottom.png^[transformR90", + "airtanks_compressor.png" + }, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + node_box = { + type = "fixed", + fixed = { + {-0.25, -0.4375, -0.5, 0.25, 0.0625, 0.5}, + {-0.3125, -0.5, -0.375, 0.3125, 0.125, 0.375}, + {-0.125, 0.125, -0.25, 0.125, 0.4375, 0.25}, + } + } +}) + +minetest.register_craft({ + recipe = { + {"", "default:steel_ingot", ""}, + {"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"}, + {"group:wood", "default:steel_ingot", "group:wood"}, + }, + output = "airtanks:compressor" +}) \ No newline at end of file diff --git a/intllib.lua b/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..67331ff --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,38 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-03-26 01:50-0600\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:54 +msgid "Empty @1" +msgstr "" + +#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:95 +msgid "Steel Air Tank" +msgstr "" + +#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:96 +msgid "Copper Air Tank" +msgstr "" + +#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:97 +msgid "Bronze Air Tank" +msgstr "" + +#: C:\Users\Bryan\Downloads\minetest-0.4.15-win64\mods\airtanks\init.lua:100 +msgid "Air Compressor" +msgstr "" diff --git a/locale/update.bat b/locale/update.bat new file mode 100644 index 0000000..e87d44c --- /dev/null +++ b/locale/update.bat @@ -0,0 +1,6 @@ +@echo off +setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION +cd .. +set LIST= +for /r %%X in (*.lua) do set LIST=!LIST! %%X +..\intllib\tools\xgettext.bat %LIST% \ No newline at end of file diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..79891b2 --- /dev/null +++ b/mod.conf @@ -0,0 +1 @@ +name = airtanks \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..ccfcbf9 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,3 @@ +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 \ No newline at end of file diff --git a/sounds/airtanks_compressor.ogg b/sounds/airtanks_compressor.ogg new file mode 100644 index 0000000..807949b Binary files /dev/null and b/sounds/airtanks_compressor.ogg differ diff --git a/sounds/airtanks_hiss.ogg b/sounds/airtanks_hiss.ogg new file mode 100644 index 0000000..4512f2f Binary files /dev/null and b/sounds/airtanks_hiss.ogg differ diff --git a/sounds/license.txt b/sounds/license.txt new file mode 100644 index 0000000..af0c419 --- /dev/null +++ b/sounds/license.txt @@ -0,0 +1,2 @@ +airtanks_hiss - from https://www.freesound.org/people/josepharaoh99/sounds/367125/ by josepharaoh99 under the public domain via CC 0 +airtanks_comressor - from https://www.freesound.org/people/Cell31_Sound_Productions/sounds/376927/ by Cell31_Sound_Productions under CC BY 3.0 \ No newline at end of file diff --git a/textures/airtanks_airtank.png b/textures/airtanks_airtank.png new file mode 100644 index 0000000..2a0a9de Binary files /dev/null and b/textures/airtanks_airtank.png differ diff --git a/textures/airtanks_compressor.png b/textures/airtanks_compressor.png new file mode 100644 index 0000000..c38c094 Binary files /dev/null and b/textures/airtanks_compressor.png differ diff --git a/textures/airtanks_compressor_bottom.png b/textures/airtanks_compressor_bottom.png new file mode 100644 index 0000000..3c67857 Binary files /dev/null and b/textures/airtanks_compressor_bottom.png differ diff --git a/textures/airtanks_empty.png b/textures/airtanks_empty.png new file mode 100644 index 0000000..667305d Binary files /dev/null and b/textures/airtanks_empty.png differ