how to change chest inventory size?

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

how to change chest inventory size?

by durtective6 » Tue Oct 29, 2013 17:22

another question! So im making a mod but would like to know how to increase a chests capacity but cant get it to work by changing inv:set_size("main", 8*4) to inv:set_size("main", 9*4), can anyone help?
many thanks
also using this code im about to show i cant get a different texture on each face of the chest

minetest.register_node("techno:technocrate", {
drawtype = "glasslike",
description = "technocrate",
tiles = {"techno_technocrate_top.png", "techno_technocrate_top.png", "techno_technocrate_side.png",
"techno_technocrate_side.png", "techno_technocrate_side.png", "techno_technocrate_front.png"},
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
groups = {choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",default.chest_formspec)
meta:set_string("infotext", "technocrate")
local inv = meta:get_inventory()
inv:set_size("main", 9*4)
end,
Last edited by durtective6 on Tue Oct 29, 2013 17:39, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Oct 29, 2013 17:45

The default chest has a string set to default.chest_formspec and that is where you make your change. Change the line
"list[current_name;main;0,0;8,4;]".. to "list[current_name;main;0,0;9,4;]".. in order to get the size to be 9 by 4 inventory slots, but remember, you may have to change the line "size[8,9]".. to "size[9,9]".. in order to have a large enough form to fit the new size of inventory on.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
default.chest_formspec =
    "size[8,9]"..
    "list[current_name;main;0,0;8,4;]"..
    "list[current_player;main;0,5;8,4;]"


EDIT: You edited your message as I was typing my reply. From the code you added, you placed the inv:set_size line in the wrong place. If you are creating a new chest and not modifying the default chest, you will need to change the formspec entirely, not try to add an inv:set_size line somewhere in the definition of the chest's construction. Look more closely at how the default chest is defined and it will become more clear to you. As for getting the different textures on the different sides, you are using a glasslike drawtype and sunlight propagates which I am not sure how those will affect textures. There may be something else going on but I am not sure. One thing you may try is to copy the default chest code and make small changes until it is what you want. Test the changes after each change as that will give you some idea what is happening when you make a change.
Last edited by LionsDen on Tue Oct 29, 2013 17:54, edited 1 time in total.
 

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

by durtective6 » Tue Oct 29, 2013 18:13

k thanks for the help ill play with the drawtypes and paramatypes a bit

EDIT:i changed the code to the code you stated above but with no success dunno if im doing anything wrong, would i need to change locked spec and this line "list[current_player;main;0,5;8,4;]"?
Last edited by durtective6 on Tue Oct 29, 2013 18:26, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Tue Oct 29, 2013 23:12

durtective6 wrote:k thanks for the help ill play with the drawtypes and paramatypes a bit

EDIT:i changed the code to the code you stated above but with no success dunno if im doing anything wrong, would i need to change locked spec and this line "list[current_player;main;0,5;8,4;]"?



If you are still using the code that you added to your first post, it wont work because you need to change the formspec, not the inv:set_size. If I get a chance, I will take a look and see what I can do and what it affects.
 

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

by durtective6 » Tue Oct 29, 2013 23:26

default.chest_formspec =
"size[9,9]"..
"list[current_name;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]"

k thanks i changed it to this as suggested if that helps
thanks a lot for the help.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Oct 30, 2013 04:51

durtective6 wrote:default.chest_formspec =
"size[9,9]"..
"list[current_name;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]"

k thanks i changed it to this as suggested if that helps
thanks a lot for the help.


You forgot to change "list[current_name;main;0,0;8,4;]".. to "list[current_name;main;0,0;9,4;]".. and also if you do it this way only, you may likely change the default chest's inventory size as well. By the way, I was wrong about the inv:set_size as that just sets the metadata's inventory size, not the formspec. The inv:set_size needs to be the same size as the "list[current_name;main;0,0;9,4;]".. otherwise, weird things may happen. It's been a while since I played a little with chest code. I am definitely not an expert at formspecs or chests. Let me know if your changes worked at all or not.

There are many other mods that have their own chests in them if you want more examples. The technic mod has some and there are some other mods that have chest in their name. Looking at those and the nodes.lua in the builtin from minetest_game will likely help you to do what you are looking for.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Oct 30, 2013 05:43

Here is a sample chest mod that I made that increases the inventory size to 9x4 inventory slots. Hope that this helps you out some. I basically just copied the default chest from minetest_game and made some changes. Maybe it will give you some ideas on what you are trying to do. I did test it myself and it worked fine for me.
Attachments
chest0.zip
(9.95 KiB) Downloaded 54 times
Last edited by LionsDen on Wed Oct 30, 2013 05:43, edited 1 time in total.
 

User avatar
durtective6
Member
 
Posts: 167
Joined: Sun Aug 12, 2012 14:19
In-game: derplez

by durtective6 » Wed Oct 30, 2013 10:21

thanks a lot for the help, its helped me lots. also i found out that putting the drawtype to glass overwrites the facedir so it displays the same texture on all sides
Last edited by durtective6 on Wed Oct 30, 2013 10:24, edited 1 time in total.
 

User avatar
LionsDen
Member
 
Posts: 525
Joined: Thu Jun 06, 2013 03:19

by LionsDen » Wed Oct 30, 2013 16:21

Your welcome. Have fun modding. :)
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 13 guests

cron