Commit 1b56c7a5 authored by Brett O'Donnell's avatar Brett O'Donnell
Browse files

added armor

parent 0fc48713
...@@ -8,6 +8,8 @@ Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com> ...@@ -8,6 +8,8 @@ Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-infinite_chest Source Code: https://github.com/cornernote/minetest-infinite_chest
License: GPLv3 License: GPLv3
Textures by: Jordan Snelling (Jordach)
Texture License: GPLv3
---------------------------------- ----------------------------------
......
...@@ -18,28 +18,32 @@ bags = {} ...@@ -18,28 +18,32 @@ bags = {}
-- get_formspec -- get_formspec
bags.get_formspec = function(player,page) bags.get_formspec = function(player,page)
local formspec = "size[8,8.5]" local formspec = "size[8,8.5]"
.."button[4,0;2,0.5;main;Craft]" .."list[current_player;main;0,3.5;8,4;]"
.."button[6,0;2,0.5;bags;Bags]" .."button[0,7.8;2,0.5;main;Main]"
.."list[current_player;main;0,4.5;8,4;]" .."button[2,7.8;2,0.5;bags;Bags]"
-- bags inventory page -- creative button
if minetest.setting_getbool("creative_mode") then
formspec = formspec .. "button[6,7.8;2,0.5;creative;Creative]"
end
-- bags
if page=="bags" then if page=="bags" then
return formspec return formspec
--.."label[0,0;Bags]" .."button[0,2;2,0.5;bag1;Bag 1]"
.."button[0,3;2,0.5;bag1;Bag 1]" .."list[detached:"..player:get_player_name().."_bags;bag1;0.5,1;1,1;]"
.."list[detached:"..player:get_player_name().."_bags;bag1;0.5,2;1,1;]"
.."button[2,3;2,0.5;bag2;Bag 2]" .."button[2,2;2,0.5;bag2;Bag 2]"
.."list[detached:"..player:get_player_name().."_bags;bag2;2.5,2;1,1;]" .."list[detached:"..player:get_player_name().."_bags;bag2;2.5,1;1,1;]"
.."button[4,3;2,0.5;bag3;Bag 3]" .."button[4,2;2,0.5;bag3;Bag 3]"
.."list[detached:"..player:get_player_name().."_bags;bag3;4.5,2;1,1;]" .."list[detached:"..player:get_player_name().."_bags;bag3;4.5,1;1,1;]"
.."button[6,3;2,0.5;bag4;Bag 4]" .."button[6,2;2,0.5;bag4;Bag 4]"
.."list[detached:"..player:get_player_name().."_bags;bag4;6.5,2;1,1;]" .."list[detached:"..player:get_player_name().."_bags;bag4;6.5,1;1,1;]"
end end
-- bag invenory page -- bag
for i=1,4 do for i=1,4 do
if page=="bag"..i then if page=="bag"..i then
local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image
...@@ -49,19 +53,42 @@ bags.get_formspec = function(player,page) ...@@ -49,19 +53,42 @@ bags.get_formspec = function(player,page)
end end
end end
-- default invenory page -- creative
if page=="creative" and minetest.setting_getbool("creative_mode") then
return "size[13,7.5]"
.."list[current_player;main;5,3.5;8,4;]"
.."list[current_player;craft;8,0;3,3;]"
.."list[current_player;craftpreview;12,1;1,1;]"
.."list[detached:creative;main;0.3,0.5;4,6;0]"
.."button[0.3,6.5;1.6,1;creative_prev;<<]"
.."button[2.7,6.5;1.6,1;creative_next;>>]"
end
-- default (craft/armor)
return formspec return formspec
--.."label[0,0;Player Inventory]" .."list[detached:"..player:get_player_name().."_armor;armor_helmet;0,0;1,1;]"
.."list[current_player;craft;3,1;3,3;]" .."list[detached:"..player:get_player_name().."_armor;armor_chest;0,1;1,1;]"
.."list[current_player;craftpreview;7,2;1,1;]" .."list[detached:"..player:get_player_name().."_armor;armor_boots;0,2;1,1;]"
.."image[1,1.5;1,2;player.png]" .."list[detached:"..player:get_player_name().."_armor;armor_shield;2,1;1,1;]"
.."image[1,0.5;1,2;player.png]"
.."list[current_player;craft;4,0;3,3;]"
.."list[current_player;craftpreview;7,1;1,1;]"
end end
-- on_player_receive_fields -- on_player_receive_fields
bags.on_player_receive_fields = function(player, formname, fields) bags.on_player_receive_fields = function(player, formname, fields)
if minetest.setting_getbool("creative_mode") then return end if fields.creative or fields.creative_prev or fields.creative_next then
if fields.creative then
player:set_inventory_formspec(bags.get_formspec(player,"creative"))
end
return
end
if fields.armor then
player:set_inventory_formspec(bags.get_formspec(player,"armor"))
return
end
if fields.bags then if fields.bags then
player:set_inventory_formspec(bags.get_formspec(player,"bags")) player:set_inventory_formspec(bags.get_formspec(player,"bags"))
return return
...@@ -81,9 +108,12 @@ end ...@@ -81,9 +108,12 @@ end
-- on_joinplayer -- on_joinplayer
bags.on_joinplayer = function(player) bags.on_joinplayer = function(player)
if minetest.setting_getbool("creative_mode") then return end
local pinv = player:get_inventory() -- player inventory
local inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{ local player_inv = player:get_inventory()
-- bags inventory
local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack) player:get_inventory():set_stack(listname, index, stack)
player:get_inventory():set_size(listname.."contents", bags.get_bagslots(stack)) player:get_inventory():set_size(listname.."contents", bags.get_bagslots(stack))
...@@ -111,10 +141,41 @@ bags.on_joinplayer = function(player) ...@@ -111,10 +141,41 @@ bags.on_joinplayer = function(player)
}) })
for i=1,4 do for i=1,4 do
local bag = "bag"..i local bag = "bag"..i
inv:set_size(bag, 1) player_inv:set_size(bag, 1)
inv:set_stack(bag,1,pinv:get_stack(bag,1)) bags_inv:set_size(bag, 1)
pinv:set_size(bag, 1) bags_inv:set_stack(bag,1,player_inv:get_stack(bag,1))
end end
-- armor 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)
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil)
end,
allow_put = function(inv, listname, index, stack, player)
if inv:is_empty(listname) and bags.is_armor(stack,listname) then
return 1
else
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
return 1
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
-- set formspec
player:set_inventory_formspec(bags.get_formspec(player)) player:set_inventory_formspec(bags.get_formspec(player))
end end
...@@ -124,4 +185,11 @@ bags.get_bagslots = function(stack) ...@@ -124,4 +185,11 @@ bags.get_bagslots = function(stack)
if stack then if stack then
return stack:get_definition().groups.bagslots return stack:get_definition().groups.bagslots
end end
end end
\ No newline at end of file
-- is_armor
bags.is_armor = function(stack,armor_type)
if stack then
return stack:get_definition().groups[armor_type]
end
end
creative
\ No newline at end of file
...@@ -22,7 +22,7 @@ minetest.register_on_joinplayer(function(player) ...@@ -22,7 +22,7 @@ minetest.register_on_joinplayer(function(player)
bags.on_joinplayer(player) bags.on_joinplayer(player)
end) end)
-- register craftitems -- register bag craftitems
minetest.register_craftitem("bags:small", { minetest.register_craftitem("bags:small", {
description = "Small Bag", description = "Small Bag",
inventory_image = "bags_small.png", inventory_image = "bags_small.png",
...@@ -39,12 +39,12 @@ minetest.register_craftitem("bags:large", { ...@@ -39,12 +39,12 @@ minetest.register_craftitem("bags:large", {
groups = {bagslots=24}, groups = {bagslots=24},
}) })
-- register crafts -- register bag crafts
minetest.register_craft({ minetest.register_craft({
output = "bags:small", output = "bags:small",
recipe = { recipe = {
{"", "default:stick", ""}, {"", "default:stick", ""},
{"default:wood", "default:stick", "default:wood"}, {"default:wood", "default:wood", "default:wood"},
{"default:wood", "default:wood", "default:wood"}, {"default:wood", "default:wood", "default:wood"},
}, },
}) })
...@@ -63,4 +63,62 @@ minetest.register_craft({ ...@@ -63,4 +63,62 @@ minetest.register_craft({
{"bags:medium", "bags:medium", "bags:medium"}, {"bags:medium", "bags:medium", "bags:medium"},
{"bags:medium", "bags:medium", "bags:medium"}, {"bags:medium", "bags:medium", "bags:medium"},
}, },
}) })
\ No newline at end of file
-- register armor
for material,name in pairs({wood="Wooden",iron="Iron",mese="Mese"}) do
-- craftitems
minetest.register_craftitem("bags:armor_helmet_"..material, {
description = name.." Helmet",
inventory_image = "armor_helmet_"..material..".png",
groups = {armor_helmet=1},
})
minetest.register_craftitem("bags:armor_chest_"..material, {
description = name.." Chestplate",
inventory_image = "armor_chest_"..material..".png",
groups = {armor_chest=1},
})
minetest.register_craftitem("bags:armor_boots_"..material, {
description = name.." Boots",
inventory_image = "armor_boots_"..material..".png",
groups = {armor_boots=1},
})
minetest.register_craftitem("bags:armor_shield_"..material, {
description = name.." Shield",
inventory_image = "armor_shield_"..material..".png",
groups = {armor_shield=1},
})
-- crafts
minetest.register_craft({
output = "bags:armor_helmet_"..material,
recipe = {
{"default:"..material, "default:"..material, "default:"..material},
{"default:"..material, "", "default:"..material},
{"default:"..material, "", "default:"..material},
},
})
minetest.register_craft({
output = "bags:armor_chest_"..material,
recipe = {
{"default:"..material, "default:"..material, "default:"..material},
{"default:"..material, "default:"..material, "default:"..material},
{"", "default:"..material, ""},
},
})
minetest.register_craft({
output = "bags:armor_boots_"..material,
recipe = {
{"default:"..material, "", "default:"..material},
{"default:"..material, "", "default:"..material},
{"default:"..material, "", "default:"..material},
},
})
minetest.register_craft({
output = "bags:armor_shield_"..material,
recipe = {
{"default:"..material, "default:"..material, "default:"..material},
{"default:"..material, "", "default:"..material},
{"default:"..material, "default:"..material, "default:"..material},
},
})
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment