[Mod] Sfinv Unified Inventory [0.1][unified_inventory]

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

[Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

Image

Image

Adds unified inventory features to sfinv.

This mod implements a fake unified inventory API and passes usage through to sfinv

Download: https://github.com/rubenwardy/sfinv_uni ... master.zip
GitHub: https://github.com/rubenwardy/sfinv_unified_inventory
Depends: sfinv (is in Minetest Game 0.4.15) and sfinv_buttons
Supports: creative and sethome (from Minetest Game)
License: LGPL 2 or later

Some code was reused from the original Unified Inventory - (C) 2012-2014 Maciej Kasatkin (RealBadAngel), LGPLv2+

TODO: bags, craft guide, refill slot
Last edited by rubenwardy on Sat Dec 31, 2016 01:00, edited 3 times in total.
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader


User avatar
mahmutelmas06
Member
Posts: 367
Joined: Mon Mar 02, 2015 13:10
GitHub: mahmutelmas06
IRC: mahmutelmas06
In-game: masum

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by mahmutelmas06 » Post

It doesnt add buttons. I still see More tab even i added sfinv_buttons_use_icon_bar = true to config.
My Mods:

Beverage

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

You need to apply the pr I posted in the forum topic
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

hajo
Member
Posts: 606
Joined: Thu Oct 13, 2016 10:45
Location: DE
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by hajo » Post

rubenwardy wrote:TODO: bags, craft guide, refill slot
How about Journalist/Note-taker: appends an entry to your travel-log (book-with-text),
i.e. date and coordinates.

User avatar
cd2
Member
Posts: 562
Joined: Mon Jun 01, 2015 06:30
GitHub: cdqwertz
In-game: cd cd2
Location: Linux
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by cd2 » Post

+1

User avatar
Warrior_4_Christ
Member
Posts: 30
Joined: Thu Oct 27, 2016 18:16
GitHub: Warrior-4-Christ
In-game: Warrior_4_Christ
Location: Palm Bay, FL U.S.
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Warrior_4_Christ » Post

TODO: bags, craft guide, refill slot
How long do you think it would take for craft guide to be added? I run a server with lots of mods and people need the craft guide to fully experience the game. :)
For God so loved the world that He gave his only begotten Son, that whosoever believeth in Him should not perish, but have everlasting life. -- John 3:16 KJV
____
| [] []|
| _>/

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by ShadMOrdre » Post

rubenwardy,

after figuring out which forum post you were actually talking about regarding the PR, i manually edited the init.lua from sfinv_buttons, to include the code on your git. not all of us are users of git source code management, and general non IT users, probably not at all.

I get an error regarding a missing end to an if statement at line 52. there follows an elseif, and so I'm not sure if I should add the end before the else if, or try to trace the lua to find which actual if is missing its related end.

Any help?


Thanks,

Shad MOrdre

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by TumeniNodes » Post

Ummm, how the heck did I not see this until now? 0_o
Downloading with sfinv buttons to try out.
A Wonderful World

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

I think I'm going to deprecate this, and instead write mods for sfinv to add UI features. Adding a compatibility layer is just asking for trouble, I feel
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
ExeterDad
Member
Posts: 1717
Joined: Sun Jun 01, 2014 20:00
In-game: ExeterDad
Location: New Hampshire U.S.A

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by ExeterDad » Post

Deprecate or depreciate? It's still got value to me. I like the look of the buttons on the side, and the extra width of the formspec because of it. Our mods and extra code is so intertwined that pulling that layer out of the server will be like pulling teeth. I'm likely to keep it as long as I can.

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by TumeniNodes » Post

rubenwardy wrote:I think I'm going to deprecate this, and instead write mods for sfinv to add UI features. Adding a compatibility layer is just asking for trouble, I feel
you're a poopie head. just merge Wuzzy's buttons, and write this setup as one mod and then add mods to add addtl UI features. :P
I'm tired... headin to bed (I just wanted to call you a poopie head, the rest was sporadic rambling) ; )
A Wonderful World

User avatar
apienk
Member
Posts: 26
Joined: Tue Mar 10, 2015 15:38
GitHub: apienk
In-game: apienk

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by apienk » Post

Hi, I read your tutorial for sfinv and it states that I can use is_in_nav to limit tab display per privilege. I am unclear however how to use it. Is it a property of sfinv page? If so, this should work but it does not:

Code: Select all

sfinv.register_page("mymod:mytab", {
	title = "mytabname",
	get = function(self, player, context)
		return sfinv.make_formspec(player, context,
                "label[0.1,0.1;Hello world!]", true)
	end,
	is_in_nav = function(self, player, context)
		local privs = player:get_privs()
		return privs.server
	end,
})
The error is: attempt to call method 'get_privs' (a nil value).

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

apienk wrote:Hi, I read your tutorial for sfinv and it states that I can use is_in_nav to limit tab display per privilege. I am unclear however how to use it. Is it a property of sfinv page? If so, this should work but it does not:

Code: Select all

sfinv.register_page("mymod:mytab", {
	title = "mytabname",
	get = function(self, player, context)
		return sfinv.make_formspec(player, context,
                "label[0.1,0.1;Hello world!]", true)
	end,
	is_in_nav = function(self, player, context)
		local privs = player:get_privs()
		return privs.server
	end,
})
The error is: attempt to call method 'get_privs' (a nil value).
use minetest.check_player_privs(player, { server = true})

Code: Select all

sfinv.register_page("mymod:mytab", {
	title = "mytabname",
	get = function(self, player, context)
		return sfinv.make_formspec(player, context,
                "label[0.1,0.1;Hello world!]", true)
	end,
	is_in_nav = function(self, player, context)
		return minetest.check_player_privs(player, { server = true})
	end,
})
also, make sure to check the privs again in on_receive_fields
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
apienk
Member
Posts: 26
Joined: Tue Mar 10, 2015 15:38
GitHub: apienk
In-game: apienk

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by apienk » Post

Thanks, it worked.

User avatar
Fixer
Member
Posts: 904
Joined: Sun Jul 31, 2011 11:23
IRC: Fixer
In-game: Fixer
Location: Ukraine

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Fixer » Post

I dislike layout of buttons on right side, does not feels aesthetic enough.

User avatar
Extex
Member
Posts: 244
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Extex » Post

How would I register a sfinv page that contains two slots

That's it, just two slots
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Miniontoby » Post

I have an code but it doesn't work

It is the sfinv.register_page row that doesn't work

Code: Select all

sfinv = minetest.get_modpath("sfinv")

if minetest.get_modpath("sfinv") then 
	sfinv.register_page("myadmin:myadmin", {
		title = "admin",
		get = function(self, player, context)
			local players = {}
			context.myadmin_players = players
	
			-- Using an array to build a formspec is considerably faster
			local formspec = {
				"textlist[0.1,0.1;7.8,3;playerlist;"
			}

			-- Add all players to the text list, and to the players list
			local is_first = true
			for _ , player in pairs(minetest.get_connected_players()) do
				local player_name = player:get_player_name()
				players[#players + 1] = player_name
				if not is_first then
					formspec[#formspec + 1] = ","
				end
				formspec[#formspec + 1] =
						minetest.formspec_escape(player_name)
				is_first = false
			end
			formspec[#formspec + 1] = "]"

			-- Add buttons
			formspec[#formspec + 1] = "button[0.1,3.3;2,1;kick;Kick]"
			formspec[#formspec + 1] = "button[2.1,3.3;2,1;ban;Kick + Ban]"

			-- Wrap the formspec in sfinv's layout
			-- (ie: adds the tabs and background)
			return sfinv.make_formspec(player, context,
					table.concat(formspec, ""), false)
		end,
		on_player_receive_fields = function(self, player, context, fields)
			-- text list event,  check event type and set index if selection changed
			if fields.playerlist then
				local event = minetest.explode_textlist_event(fields.playerlist)
				if event.type == "CHG" then
					context.myadmin_selected_idx = event.index
				end

			-- Kick button was pressed
			elseif fields.kick then
				local player_name =
					context.myadmin_players[context.myadmin_selected_idx]
				if player_name then
					minetest.chat_send_player(player:get_player_name(),
						"Kicked " .. player_name)
					minetest.kick_player(player_name)
				end
	
			-- Ban button was pressed
			elseif fields.ban then
				local player_name =
					context.myadmin_players[context.myadmin_selected_idx]
				if player_name then
					minetest.chat_send_player(player:get_player_name(),
							"Banned " .. player_name)
					minetest.ban_player(player_name)
					minetest.kick_player(player_name, "Banned")
				end
			end
		end,
		is_in_nav = function(self, player, context)
			local privs = minetest.get_player_privs(player:get_player_name())
			local function on_grant_revoke(grantee, granter, priv)
				if priv ~= "kick" and priv ~= "ban" then
					return
				end

				local player = minetest.get_player_by_name(grantee)
				if not player then
					return
				end

				local context = sfinv.get_or_create_context(player)
				if context.page ~= "myadmin:myadmin" then
					return
				end

				sfinv.set_player_inventory_formspec(player, context)
			end

			minetest.register_on_priv_grant(on_grant_revoke)
			minetest.register_on_priv_revoke(on_grant_revoke)
			return privs.kick or privs.ban
		end,
		on_enter = function(self, player, context)
		
		end,
		on_leave = function(self, player, context)
			
		end,
	})
end
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

User avatar
Lone_Wolf
Member
Posts: 2576
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: LandarVargan
In-game: LandarVargan

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Lone_Wolf » Post

Miniontoby wrote:I have an code but it doesn't work

It is the sfinv.register_page row that doesn't work

Code: Select all

sfinv = minetest.get_modpath("sfinv")

if minetest.get_modpath("sfinv") then 
	sfinv.register_page("myadmin:myadmin", {
		title = "admin",
		get = function(self, player, context)
			local players = {}
			context.myadmin_players = players
	
			-- Using an array to build a formspec is considerably faster
			local formspec = {
				"textlist[0.1,0.1;7.8,3;playerlist;"
			}

			-- Add all players to the text list, and to the players list
			local is_first = true
			for _ , player in pairs(minetest.get_connected_players()) do
				local player_name = player:get_player_name()
				players[#players + 1] = player_name
				if not is_first then
					formspec[#formspec + 1] = ","
				end
				formspec[#formspec + 1] =
						minetest.formspec_escape(player_name)
				is_first = false
			end
			formspec[#formspec + 1] = "]"

			-- Add buttons
			formspec[#formspec + 1] = "button[0.1,3.3;2,1;kick;Kick]"
			formspec[#formspec + 1] = "button[2.1,3.3;2,1;ban;Kick + Ban]"

			-- Wrap the formspec in sfinv's layout
			-- (ie: adds the tabs and background)
			return sfinv.make_formspec(player, context,
					table.concat(formspec, ""), false)
		end,
		on_player_receive_fields = function(self, player, context, fields)
			-- text list event,  check event type and set index if selection changed
			if fields.playerlist then
				local event = minetest.explode_textlist_event(fields.playerlist)
				if event.type == "CHG" then
					context.myadmin_selected_idx = event.index
				end

			-- Kick button was pressed
			elseif fields.kick then
				local player_name =
					context.myadmin_players[context.myadmin_selected_idx]
				if player_name then
					minetest.chat_send_player(player:get_player_name(),
						"Kicked " .. player_name)
					minetest.kick_player(player_name)
				end
	
			-- Ban button was pressed
			elseif fields.ban then
				local player_name =
					context.myadmin_players[context.myadmin_selected_idx]
				if player_name then
					minetest.chat_send_player(player:get_player_name(),
							"Banned " .. player_name)
					minetest.ban_player(player_name)
					minetest.kick_player(player_name, "Banned")
				end
			end
		end,
		is_in_nav = function(self, player, context)
			local privs = minetest.get_player_privs(player:get_player_name())
			local function on_grant_revoke(grantee, granter, priv)
				if priv ~= "kick" and priv ~= "ban" then
					return
				end

				local player = minetest.get_player_by_name(grantee)
				if not player then
					return
				end

				local context = sfinv.get_or_create_context(player)
				if context.page ~= "myadmin:myadmin" then
					return
				end

				sfinv.set_player_inventory_formspec(player, context)
			end

			minetest.register_on_priv_grant(on_grant_revoke)
			minetest.register_on_priv_revoke(on_grant_revoke)
			return privs.kick or privs.ban
		end,
		on_enter = function(self, player, context)
		
		end,
		on_leave = function(self, player, context)
			
		end,
	})
end
Just delete that first line and it should work
My ContentDB -|- Working on CaptureTheFlag -|- Minetest Forums Dark Theme!! (You need it)

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Miniontoby » Post

Then minetest doesn't know what sfinv is
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by rubenwardy » Post

Miniontoby wrote:Then minetest doesn't know what sfinv is
You need to depend on sfinv in mod.conf (or depends.txt)

sfinv is a table, but you're replacing it with a string
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Miniontoby » Post

Thanks rubenwardy
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

u34

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by u34 » Post

any chance to add support for bags, craft guide, refill slot
how can i get it to work under minetest?

thx for info.

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] Sfinv Unified Inventory [0.1][unified_inventory]

by Miniontoby » Post

cHyper wrote:
Tue Jan 19, 2021 13:33
any chance to add support for bags, craft guide, refill slot
how can i get it to work under minetest?

thx for info.
Hi cHyper, use the Unified Inventory. Its already in that mod, but here at sfinv not.

Or use: Inventorybags
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests