Page 1 of 1

how to change chest inventory size?

PostPosted: Tue Oct 29, 2013 17:22
by durtective6
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,

PostPosted: Tue Oct 29, 2013 17:45
by LionsDen
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.

PostPosted: Tue Oct 29, 2013 18:13
by durtective6
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;]"?

PostPosted: Tue Oct 29, 2013 23:12
by LionsDen
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.

PostPosted: Tue Oct 29, 2013 23:26
by durtective6
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.

PostPosted: Wed Oct 30, 2013 04:51
by LionsDen
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.

PostPosted: Wed Oct 30, 2013 05:43
by LionsDen
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.

PostPosted: Wed Oct 30, 2013 10:21
by durtective6
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

PostPosted: Wed Oct 30, 2013 16:21
by LionsDen
Your welcome. Have fun modding. :)