commit fd741a8496d2f49b8f8b51c33da6c616764def55 Author: Brett O'Donnell Date: Mon Sep 17 19:01:06 2012 +0930 initial commit diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..1798217 --- /dev/null +++ b/README.txt @@ -0,0 +1,98 @@ +---------------------------------- +Armor for Minetest +---------------------------------- + + +Copyright (c) 2012 cornernote, Brett O'Donnell + +Source Code: https://github.com/cornernote/minetest-armor +License: GPLv3 + +Textures by: Jordan Snelling (Jordach) +Texture License: GPLv3 + + +---------------------------------- +Description +---------------------------------- + + +Allows players to craft and attach armor to their inventory to increase player strength. + + + +---------------------------------- +Crafts +---------------------------------- + +M = Material: Wood, Steel, Mese + +Helmet: +MMM +M-M +M-M + +Chestplate: +MMM +MMM +-M- + +Boots: +M-M +M-M +M-M + +Shield: +MMM +M-M +MMM + + + +---------------------------------- +Modders Guide +---------------------------------- + + +To turn your craftitem into armor simply add one of the following to the groups in the node definition. +armor_helmet=X +armor_chest=X +armor_boots=X +armor_shield=X + +X is from 1 to 4, where 1 is the highest grade armor (mese) + +EG: +minetest.register_tool("your_mod:your_armor", { + description = "Your Armor", + groups = {armor_helmet=2}, +}) + + + +---------------------------------- +License +---------------------------------- + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 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 General Public License for more details. + +You should have received a copy of the GNU 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. + + + +---------------------------------- +Credits +---------------------------------- + +Thank you to the minetest community who has shared their code and knowledge with me. + diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..f44fd42 --- /dev/null +++ b/api.lua @@ -0,0 +1,120 @@ +--[[ + +Armor for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +Source Code: https://github.com/cornernote/minetest-particles +License: GPLv3 + +API + +]]-- + + + +-- expose api +armor = {} + +-- get_armor_level +armor.get_armor_level = function(stack,armor_type) + if stack then + return stack:get_definition().groups[armor_type] + end +end + +-- set_armor_groups +armor.set_armor_groups = function(player) + local level + local armor_groups = {level=4,fleshy=4,snappy=4,choppy=4} + player_inv = player:get_inventory() + + -- helmet + level = armor.get_armor_level(player_inv:get_stack("armor_helmet", 1),"armor_helmet") + if level~=nil then + armor_groups.level = level + end + -- chest + level = armor.get_armor_level(player_inv:get_stack("armor_chest", 1),"armor_chest") + if level~=nil then + armor_groups.fleshy = level + end + -- boots + level = armor.get_armor_level(player_inv:get_stack("armor_boots", 1),"armor_boots") + if level~=nil then + armor_groups.snappy = level + end + -- shield + level = armor.get_armor_level(player_inv:get_stack("armor_shield", 1),"armor_shield") + if level~=nil then + armor_groups.choppy = level + end + + player:set_armor_groups(armor_groups) + print(dump(armor_groups)) +end + +-- register armor +armor.register_armor = function(mod_name,name,label,material,level) + + -- tools + minetest.register_tool(mod_name..":"..name.."helmet", { + description = label.." Helmet", + inventory_image = mod_name.."_"..name.."_helmet.png", + groups = {armor_helmet=level}, + wear = 0, + }) + minetest.register_tool(mod_name..":"..name.."_chest", { + description = label.." Chestplate", + inventory_image = mod_name.."_"..name.."_chest.png", + groups = {armor_chest=level}, + wear = 0, + }) + minetest.register_tool(mod_name..":"..name.."_boots", { + description = label.." Boots", + inventory_image = mod_name.."_"..name.."_boots.png", + groups = {armor_boots=level}, + wear = 0, + }) + minetest.register_tool(mod_name..":"..name.."shield", { + description = label.." Shield", + inventory_image = mod_name.."_"..name.."_shield.png", + groups = {armor_shield=level}, + wear = 0, + }) + + -- crafts + minetest.register_craft({ + output = mod_name..":"..name.."_helmet_", + recipe = { + {material, material, material}, + {material, "", material}, + {material, "", material}, + }, + }) + minetest.register_craft({ + output = mod_name..":"..name.."_chest_", + recipe = { + {material, material, material}, + {material, material, material}, + {"", material, ""}, + }, + }) + minetest.register_craft({ + output = mod_name..":"..name.."_boots_", + recipe = { + {material, "", material}, + {material, "", material}, + {material, "", material}, + }, + }) + minetest.register_craft({ + output = mod_name..":"..name.."_shield_", + recipe = { + {material, material, material}, + {material, "", material}, + {material, material, material}, + }, + }) + +end + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..3c8fd00 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +inventory_plus \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..8b05408 --- /dev/null +++ b/init.lua @@ -0,0 +1,80 @@ +--[[ + +Armor for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +Source Code: https://github.com/cornernote/minetest-particles +License: GPLv3 + +]]-- + +-- load api +dofile(minetest.get_modpath("armor").."/api.lua") + +-- add inventory_plus page +inventory_plus.pages["armor"] = "Armor" + +-- get_formspec +local get_formspec = function(player,page) + return "size[8,7.5]" + .."button[0,0;2,0.5;main;Back]" + .."list[current_player;main;0,3.5;8,4;]" + .."list[detached:"..player:get_player_name().."_armor;armor_helmet;3,0;1,1;]" + .."list[detached:"..player:get_player_name().."_armor;armor_chest;3,1;1,1;]" + .."list[detached:"..player:get_player_name().."_armor;armor_boots;3,2;1,1;]" + .."list[detached:"..player:get_player_name().."_armor;armor_shield;5,1;1,1;]" + .."image[4,0.5;1,2;player.png]" +end + +-- register_on_player_receive_fields +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.armor then + inventory_plus.set_inventory_formspec(player, get_formspec(player,"armor")) + return + end +end) + +-- register_on_joinplayer +minetest.register_on_joinplayer(function(player) + local player_inv = player:get_inventory() + local armor_inv = minetest.create_detached_inventory(player:get_player_name().."_armor",{ + on_put = function(inv, listname, index, stack, player) + player:get_inventory():set_stack(listname, index, stack) + armor.set_armor_groups(player) + end, + on_take = function(inv, listname, index, stack, player) + player:get_inventory():set_stack(listname, index, nil) + armor.set_armor_groups(player) + end, + allow_put = function(inv, listname, index, stack, player) + if inv:is_empty(listname) and armor.get_armor_level(stack,listname) then + return 1 + else + return 0 + end + end, + allow_take = function(inv, listname, index, stack, player) + return stack:get_count() + end, + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + return 0 + end, + }) + for _,v in ipairs({"boots","chest","helmet","shield"}) do + local armor = "armor_"..v + player_inv:set_size(armor, 1) + armor_inv:set_size(armor, 1) + armor_inv:set_stack(armor,1,player_inv:get_stack(armor,1)) + end + armor.set_armor_groups(player) +end) + +-- register armors +local armors = { + {name="wood",label="Wooden",material="default:wood",level=3}, + {name="steel",label="Steel",material="default:steel_ingot",level=2}, + {name="mese",label="Mese",material="default:mese",level=1}, +} +for _,params in pairs(armors) do + armor.register_armor("armor",params.name,params.label,params.material,params.level) +end diff --git a/textures/armor_mese_boots.png b/textures/armor_mese_boots.png new file mode 100644 index 0000000..0a55bdd Binary files /dev/null and b/textures/armor_mese_boots.png differ diff --git a/textures/armor_mese_chest.png b/textures/armor_mese_chest.png new file mode 100644 index 0000000..f959f60 Binary files /dev/null and b/textures/armor_mese_chest.png differ diff --git a/textures/armor_mese_helmet.png b/textures/armor_mese_helmet.png new file mode 100644 index 0000000..98cae18 Binary files /dev/null and b/textures/armor_mese_helmet.png differ diff --git a/textures/armor_mese_shield.png b/textures/armor_mese_shield.png new file mode 100644 index 0000000..2b4e647 Binary files /dev/null and b/textures/armor_mese_shield.png differ diff --git a/textures/armor_steel_boots.png b/textures/armor_steel_boots.png new file mode 100644 index 0000000..4cc7f31 Binary files /dev/null and b/textures/armor_steel_boots.png differ diff --git a/textures/armor_steel_chest.png b/textures/armor_steel_chest.png new file mode 100644 index 0000000..cd40e27 Binary files /dev/null and b/textures/armor_steel_chest.png differ diff --git a/textures/armor_steel_helmet.png b/textures/armor_steel_helmet.png new file mode 100644 index 0000000..229a887 Binary files /dev/null and b/textures/armor_steel_helmet.png differ diff --git a/textures/armor_steel_shield.png b/textures/armor_steel_shield.png new file mode 100644 index 0000000..8fc3827 Binary files /dev/null and b/textures/armor_steel_shield.png differ diff --git a/textures/armor_wood_boots.png b/textures/armor_wood_boots.png new file mode 100644 index 0000000..9ad2832 Binary files /dev/null and b/textures/armor_wood_boots.png differ diff --git a/textures/armor_wood_chest.png b/textures/armor_wood_chest.png new file mode 100644 index 0000000..1c9fc35 Binary files /dev/null and b/textures/armor_wood_chest.png differ diff --git a/textures/armor_wood_helmet.png b/textures/armor_wood_helmet.png new file mode 100644 index 0000000..655513a Binary files /dev/null and b/textures/armor_wood_helmet.png differ diff --git a/textures/armor_wood_shield.png b/textures/armor_wood_shield.png new file mode 100644 index 0000000..bee0992 Binary files /dev/null and b/textures/armor_wood_shield.png differ