initial commit
98
README.txt
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
----------------------------------
|
||||||
|
Armor for Minetest
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
120
api.lua
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
--[[
|
||||||
|
|
||||||
|
Armor for Minetest
|
||||||
|
|
||||||
|
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||||
|
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
|
||||||
|
|
1
depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
inventory_plus
|
80
init.lua
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
--[[
|
||||||
|
|
||||||
|
Armor for Minetest
|
||||||
|
|
||||||
|
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||||
|
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
|
BIN
textures/armor_mese_boots.png
Normal file
After Width: | Height: | Size: 250 B |
BIN
textures/armor_mese_chest.png
Normal file
After Width: | Height: | Size: 319 B |
BIN
textures/armor_mese_helmet.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
textures/armor_mese_shield.png
Normal file
After Width: | Height: | Size: 329 B |
BIN
textures/armor_steel_boots.png
Normal file
After Width: | Height: | Size: 250 B |
BIN
textures/armor_steel_chest.png
Normal file
After Width: | Height: | Size: 336 B |
BIN
textures/armor_steel_helmet.png
Normal file
After Width: | Height: | Size: 352 B |
BIN
textures/armor_steel_shield.png
Normal file
After Width: | Height: | Size: 412 B |
BIN
textures/armor_wood_boots.png
Normal file
After Width: | Height: | Size: 245 B |
BIN
textures/armor_wood_chest.png
Normal file
After Width: | Height: | Size: 344 B |
BIN
textures/armor_wood_helmet.png
Normal file
After Width: | Height: | Size: 356 B |
BIN
textures/armor_wood_shield.png
Normal file
After Width: | Height: | Size: 315 B |