From 156a0d2df43abc37c58abd7e6eef650f2bd38075 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sat, 28 Nov 2015 11:43:09 +0000 Subject: [PATCH] Added trolley, new formspec, shift+click functionality --- LICENSE | 32 +++++++ README.md | 38 ++++++++ depends.txt | 2 + init.lua | 192 ++++++++++++++++++++++++++++++++++++++ textures/bags_large.png | Bin 0 -> 255 bytes textures/bags_medium.png | Bin 0 -> 248 bytes textures/bags_small.png | Bin 0 -> 250 bytes textures/bags_trolley.png | Bin 0 -> 199 bytes 8 files changed, 264 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/bags_large.png create mode 100644 textures/bags_medium.png create mode 100644 textures/bags_small.png create mode 100644 textures/bags_trolley.png diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ef9ddd5 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea783f3 --- /dev/null +++ b/README.md @@ -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/) diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..65e2314 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +default +inventory_plus \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..5a9c279 --- /dev/null +++ b/init.lua @@ -0,0 +1,192 @@ +--[[ + +Bags for Minetest + +Copyright (c) 2012 cornernote, Brett O'Donnell +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") \ No newline at end of file diff --git a/textures/bags_large.png b/textures/bags_large.png new file mode 100644 index 0000000000000000000000000000000000000000..823d24cc8c0ccc2c4bf24997c7a5f3d07be3a432 GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!aez;VYq#A3MkWRcUOqWKejPDU zO$9|eIayB?m1rHEQY));NBb6M$9^}r$k33bfq{GC;_52PpFZx00%~V03GxeOaCmkj z4alkTba4!kxE$IWDdeok!Q#m4t?=ltzqDiU)a!M=)_n|~EH)ia^v`#+f0C?JQj<@# zNc xoA{O6IFvOz#a?icSHsFO=RCbu3%BEYn)D5%SZA_i8G*dW;OXk;vd$@?2>^qHQH}rr literal 0 HcmV?d00001 diff --git a/textures/bags_medium.png b/textures/bags_medium.png new file mode 100644 index 0000000000000000000000000000000000000000..ccdb2359d5389fef528b074bc7eb7e86abbb5498 GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!aez;VYq#A3Ieq~xQBiw&*#HgA zWCMdDORHL2hXy;_VmJ3zXUBdwx2Zlpivt5ThKJV{71cM^adWy|0%~V03GxeOaCmkj z4ah0>ba4!kxE$Ia&3D*0TQhCx;JLN!q|&#)0+DJn+&3=s zxbMBBv!<=!+nJ7KpCrmAY*0KV^g;E)w2r#DZOg3kTjo!{+Ge}cCB@-tny~)FxFoUU sr%P`6f6++T@U@~ literal 0 HcmV?d00001 diff --git a/textures/bags_small.png b/textures/bags_small.png new file mode 100644 index 0000000000000000000000000000000000000000..34812f173563e15c589d62d10711b11b828aa89f GIT binary patch literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!aez;VYq#A36;TlbMI}2etx$8b zTt}w_H@6xOuNHsbqR`NZp`mjV;(Jq5muF^dsIK1C-F;%&vh_<@fVvqNOM?7@862M7 zNCR?8JzX3_BrfOnU*tQgz~Mai+`&^C|NdW(dtcJcudK2}UAJ+{zExlQs%=DdJ>qSD zT6|iiT(oaTM%+)GBa0>Dnr0uo@9?KFp)HD~|MHSIYL_4MC0+ftwoi14=Q{?g21(!D uMhOh&zj$Ajs0cJ@x!ga^qNOyyf4O}66_#s<`n$70&hd2hb6Mw<&;$TmA6-iT literal 0 HcmV?d00001 diff --git a/textures/bags_trolley.png b/textures/bags_trolley.png new file mode 100644 index 0000000000000000000000000000000000000000..a729181bf7c9226dc95669d35d4044d19eff8e38 GIT binary patch literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPGa4)6(a%>XhO8I%MBEfp1-9PFoi zd9Mo(E6vS0kdUzV)Ye-d*^(f?Uq$DI*9D4f7*xcL{ z&R)BCPk})w)4R8Tg>%D>wpP<77AIvVTb@Rqu;~*zR2&yLbaZ!1do&!p>Uu#^<-mbg p8X7ESy^b4VCNNGtsKGIfkzrOFZ}rV=4|Sj|44$rjF6*2UngATrJqrK; literal 0 HcmV?d00001