From 1b61611ce3b0756d9b33c9298b4b0ad3984fa0b6 Mon Sep 17 00:00:00 2001 From: octacian Date: Wed, 8 Feb 2017 22:08:29 -0800 Subject: [PATCH] Initial commit --- LICENSE | 16 +++++++++++ README.md | 0 api.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ init.lua | 14 +++++++++ 4 files changed, 115 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 api.lua create mode 100644 init.lua diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0b3ce07 --- /dev/null +++ b/LICENSE @@ -0,0 +1,16 @@ +MIT License +Copyright (c) 2017 Elijah Duffy +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..0b9edbb --- /dev/null +++ b/api.lua @@ -0,0 +1,85 @@ +-- microexpansion/api.lua +local BASENAME = "microexpansion" + +-- [local function] register recipe +local function register_recipe(output, recipe) + local function isint(n) + return n==math.floor(n) + end + + local function getAmount() + if isint(recipe[2][1]) then + local q = recipe[2][1] + recipe[2][1] = nil + return q + else return 1 end + end + + local function register(amount, recipe) + minetest.register_craft({ + output = output.." "..amount, + recipe = recipe, + }) + end + + local function single() + register(getAmount(), recipe[2]) + end + + local function multiple() + for i, item in ipairs(recipe) do + if i == 0 then return end + register(getAmount(), recipe[i]) + end + end + + -- check type + if recipe[1] == "single" then single() + elseif recipe[1] == "multiple" then multiple() + else return microexpansion.log("invalid recipe for definition "..output..". "..dump(recipe[2])) end +end + +-- [function] register item +function microexpansion.register_item(itemstring, def) + -- usedfor + if def.usedfor then + def.description = def.description .. "\nfor " .. def.usedfor + end + + -- register craftitem + minetest.register_craftitem(BASENAME..":"..itemstring, { + description = def.description, + inventory_image = BASENAME.."_"..def.inventory_image..".png", + }) + + -- if recipe, register recipe + if def.recipe then + register_recipe(BASENAME..":"..itemstring, def.recipe) + end +end + +-- [function] register cell +function microexpansion.register_cell(itemstring, def) + if not def.inventory_image then + def.inventory_image = itemstring + end + + -- register craftitem + minetest.register_craftitem(BASENAME..":"..itemstring, { + description = def.description, + inventory_image = BASENAME.."_"..def.inventory_image..".png", + microexpansion = { + drive = { + capacity = def.capacity or 5000, + }, + }, + }) + + -- if recipe, register recipe + if def.recipe then + -- if recipe, register recipe + if def.recipe then + register_recipe(BASENAME..":"..itemstring, def.recipe) + end + end +end diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a824e1e --- /dev/null +++ b/init.lua @@ -0,0 +1,14 @@ +-- microexpansion/init.lua +microexpansion = {} +microexpansion.modpath = minetest.get_modpath("microexpansion") -- modpath +local modpath = microexpansion.modpath -- modpath pointer + +-- logger +function microexpansion.log(content, log_type) + if not content then return false end + if log_type == nil then log_type = "action" end + minetest.log(log_type, "[MicroExpansion] "..content) +end + +-- Load API +dofile(modpath.."/api.lua")