Added trolley, new formspec, shift+click functionality

This commit is contained in:
TenPlus1 2015-11-28 11:43:09 +00:00
commit 156a0d2df4
8 changed files with 264 additions and 0 deletions

32
LICENSE Normal file
View File

@ -0,0 +1,32 @@
Copyright (c) 2013, Brett O'Donnell http://cornernote.github.io
All rights reserved.
_____ _____ _____ _____ _____ _____
| |___| __ | | |___| __ | | |___|_ _|___
| --| . | -| | | | -_| -| | | | . | | | | -_|
|_____|___|__|__|_|___|___|__|__|_|___|___| |_| |___|
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the organization nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

38
README.md Normal file
View File

@ -0,0 +1,38 @@
# Bags for Minetest
Allows players to craft and attach bags to their inventory to increase player item storage capacity.
## Features
- Bags are available in inventory.
- Multiple sized bags.
- Bags store items permanently with the player
## Resources
- **[Documentation](http://cornernote.github.io/minetest-bags)**
- **[GitHub Project](https://github.com/cornernote/minetest-bags)**
- **[Minetest Forum](http://minetest.net/forum/viewtopic.php?id=3081)**
## Support
- Does this README need improvement? Go ahead and [suggest a change](https://github.com/cornernote/minetest-bags/edit/master/README.md).
- Found a bug, or need help using this project? Check the [open issues](https://github.com/cornernote/minetest-bags/issues) or [create an issue](https://github.com/cornernote/minetest-bags/issues/new).
## About
This module is open source, so it's distributed freely. If you find it useful then I ask not for your wealth, but simply to spare your time to consider the world we share by watching [Earthlings](http://earthlings.com/), a multi-award winning film available to watch online for free. A must-see for anyone who wishes to make the world a better place.
## Credits
- Tonyka - created the amazing bag textures
## License
[BSD-3-Clause](https://raw.github.com/cornernote/minetest-bags/master/LICENSE), Copyright © 2013-2014 [Brett O'Donnell](http://cornernote.github.io/)

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
inventory_plus

192
init.lua Normal file
View File

@ -0,0 +1,192 @@
--[[
Bags for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-bags
License: BSD-3-Clause https://raw.github.com/cornernote/minetest-bags/master/LICENSE
Edited by TenPlus1
]]--
local get_formspec = function(player, page)
if page == "bags" then
return "size[8,7.5]"
..default.gui_bg..default.gui_bg_img..default.gui_slots
.."list[current_player;main;0,3.5;8,4;]"
.."button[0,1;2,0.5;main;Back]"
.."button[2.5,1;1.3,0.5;bag1;Bag 1]"
.."button[2.5,2.2;1.3,0.5;bag2;Bag 2]"
.."button[5.2,1;1.3,0.5;bag3;Bag 3]"
.."button[5.2,2.2;1.3,0.5;bag4;Bag 4]"
.."list[detached:"..player:get_player_name().."_bags;bag1;3.8,.8;1,1;]"
.."list[detached:"..player:get_player_name().."_bags;bag2;3.8,2;1,1;]"
.."list[detached:"..player:get_player_name().."_bags;bag3;6.5,.8;1,1;]"
.."list[detached:"..player:get_player_name().."_bags;bag4;6.5,2;1,1;]"
end
for i = 1, 4 do
if page == "bag" .. i then
local image = player:get_inventory():get_stack("bag"
.. i, 1):get_definition().inventory_image
--[[
return "size[8,9.5]"
..default.gui_bg..default.gui_bg_img..default.gui_slots
.."list[current_player;main;0,5.5;8,4;]"
.."button[6,0.2;2,0.5;main;Main]"
.."button[4,0.2;2,0.5;bags;Bags]"
.."image[0,0;1,1;" .. image .. "]"
.."list[current_player;bag" .. i .. "contents;0,1;8,4;]"
--]]
return "size[8,9]"
..default.gui_bg..default.gui_bg_img..default.gui_slots
.."list[current_player;bag" .. i .. "contents;0,0;8,4;]"
.."button[0,4.2.2;2,0.5;main;Main]"
.."button[6,4.2.2;2,0.5;bags;Bags]"
.."image[3.5,4;1,1;" .. image .. "]"
.."list[current_player;main;0,5;8,4;]"
.. "listring[current_player;main]"
.. "listring[current_player;bag" .. i .. "contents]"
end
end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.bags then
inventory_plus.set_inventory_formspec(player, get_formspec(player, "bags"))
return
end
for i = 1, 4 do
local page = "bag" .. i
if fields[page] then
if player:get_inventory():get_stack(page, 1):get_definition().groups.bagslots == nil then
page = "bags"
end
inventory_plus.set_inventory_formspec(player, get_formspec(player, page))
return
end
end
end)
minetest.register_on_joinplayer(function(player)
inventory_plus.register_button(player,"bags","Bags")
local player_inv = player:get_inventory()
local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack)
player:get_inventory():set_size(listname.."contents", stack:get_definition().groups.bagslots)
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 stack:get_definition().groups.bagslots then
return 1
else
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname .. "contents") == true then
return stack:get_count()
else
return 0
end
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0
end,
})
for i = 1, 4 do
local bag = "bag" .. i
player_inv:set_size(bag, 1)
bags_inv:set_size(bag, 1)
bags_inv:set_stack(bag, 1, player_inv:get_stack(bag, 1))
end
end)
-- register bags items
minetest.register_craftitem("bags:small", {
description = "Small Bag",
inventory_image = "bags_small.png",
groups = {bagslots = 8},
})
minetest.register_craftitem("bags:medium", {
description = "Medium Bag",
inventory_image = "bags_medium.png",
groups = {bagslots = 16},
})
minetest.register_craftitem("bags:large", {
description = "Large Bag",
inventory_image = "bags_large.png",
groups = {bagslots = 24},
})
minetest.register_tool("bags:trolley", {
description = "Trolley",
inventory_image = "bags_trolley.png",
groups = {bagslots = 32},
})
-- register bag crafts
minetest.register_craft({
output = "bags:small",
recipe = {
{"", "default:stick", ""},
{"mobs:leather", "mobs:leather", "mobs:leather"},
{"mobs:leather", "mobs:leather", "mobs:leather"},
},
})
minetest.register_craft({
output = "bags:medium",
recipe = {
{"", "default:stick", ""},
{"bags:small", "bags:small", "bags:small"},
},
})
minetest.register_craft({
output = "bags:large",
recipe = {
{"", "default:stick", ""},
{"bags:medium", "bags:medium", "bags:medium"},
},
})
minetest.register_craft({
output = "bags:trolley",
recipe = {
{"", "default:stick", ""},
{"bags:large", "bags:large", "bags:large"},
},
})
print ("[MOD] Bags loaded")

BIN
textures/bags_large.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

BIN
textures/bags_medium.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

BIN
textures/bags_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

BIN
textures/bags_trolley.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B