Page 1 of 1

[question] sfinv modding questions

PostPosted: Fri May 24, 2019 02:59
by Extex
OK so I'm making a mod with a new sfinv inventory page, with two item slots; and I only want items with a specific group to be allowed in these slots.
How would I do this?
Code: Select all
sfinv.register_page("rings:ring_page", {
   title = "Rings",
   get = function(self, player, context)
      return sfinv.make_formspec(player, context,
            "list[current_player;ring_slots;1.75,0.5;1,2;]",
          true)
   end,
})

And I only want items with the group "ring" to be allowed in the slots

Re: [question] sfinv modding questions

PostPosted: Sat May 25, 2019 06:42
by Krock
Extex wrote: I only want items with a specific group to be allowed in these slots.

And I only want items with the group "ring" to be allowed in the slots

First is possible, latter done by the rule given for the first request.

Since Minetest 5.0.0 you can use the callback minetest.register_allow_player_inventory_action to prevent items to be placed in player inventory slots.
Sample code: (untested, use "Quote" function to keep tabulators)
Code: Select all
mminetest.register_allow_player_inventory_action(function(player, action, inv, info)
   if action == "take" then
      return -- Not interesting
   end
   local list = info.to_list or info.listname
   if list ~= "ring_slots" then
      return -- Wrong affected list
   end
   return 0 -- May not put the item into this slot
end)

Re: [question] sfinv modding questions

PostPosted: Sat May 25, 2019 18:18
by Extex
OK I have no idea how that function works.
So I just copy pasted, and for some reason both of the slots are just gone

And the content of the slots was shifted to my crafting

I removed it and it still happens
I just get this error

2019-05-25 12:44:47: WARNING[Main]: GUIFormSpecMenu::drawList(): The inventory list "ring_slots" @ "current_player" doesn't exist

Re: [question] sfinv modding questions

PostPosted: Tue May 28, 2019 02:30
by Extex
Oh nvm I figured out what was wrong.
I needed to do it like this
Code: Select all

minetest.register_on_joinplayer(function(player)                                 
    local inv = player:get_inventory()                                           
    inv:set_size("rings", 2)                                             
end)
sfinv.register_page("rings:ring_page", {
   title = "Rings",
   get = function(self, player, context)
       local formspec = ""..
                "list[current_player;rings;1.75,0.5;1,2;]"..
            ""..
            "image[0,4.7;1,1;gui_hb_bg.png]"..
            "image[1,4.7;1,1;gui_hb_bg.png]"..
            "image[2,4.7;1,1;gui_hb_bg.png]"..
            "image[3,4.7;1,1;gui_hb_bg.png]"..
            "image[4,4.7;1,1;gui_hb_bg.png]"..
            "image[5,4.7;1,1;gui_hb_bg.png]"..
            "image[6,4.7;1,1;gui_hb_bg.png]"..
            "image[7,4.7;1,1;gui_hb_bg.png]"
        return sfinv.make_formspec(player, context, formspec, true)
   end
})


But still can't figure out how to limit it to only items with "ring" group