Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory_plus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
inventory_plus
Commits
bc147fc2
Commit
bc147fc2
authored
9 years ago
by
Brett O'Donnell
Browse files
Options
Downloads
Plain Diff
Merge pull request #8 from tenplus1/patch-1
Tidied and Tweaked :)
parents
8c05ccaf
07fb379f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_plus/init.lua
+98
-53
98 additions, 53 deletions
inventory_plus/init.lua
with
98 additions
and
53 deletions
inventory_plus/init.lua
+
98
−
53
View file @
bc147fc2
...
...
@@ -6,8 +6,9 @@ Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-inventory_plus
License: BSD-3-Clause https://raw.github.com/cornernote/minetest-inventory_plus/master/LICENSE
]]
--
Edited by TenPlus1 (23rd March 2016)
]]
--
-- expose api
inventory_plus
=
{}
...
...
@@ -19,17 +20,27 @@ inventory_plus.buttons = {}
inventory_plus
.
default
=
minetest
.
setting_get
(
"inventory_default"
)
or
"craft"
-- register_button
inventory_plus
.
register_button
=
function
(
player
,
name
,
label
)
inventory_plus
.
register_button
=
function
(
player
,
name
,
label
)
local
player_name
=
player
:
get_player_name
()
if
inventory_plus
.
buttons
[
player_name
]
==
nil
then
inventory_plus
.
buttons
[
player_name
]
=
{}
end
inventory_plus
.
buttons
[
player_name
][
name
]
=
label
end
-- set_inventory_formspec
inventory_plus
.
set_inventory_formspec
=
function
(
player
,
formspec
)
inventory_plus
.
set_inventory_formspec
=
function
(
player
,
formspec
)
-- error checking
if
not
formspec
then
return
end
if
minetest
.
setting_getbool
(
"creative_mode"
)
then
-- if creative mode is on then wait a bit
minetest
.
after
(
0
.
01
,
function
()
player
:
set_inventory_formspec
(
formspec
)
...
...
@@ -39,53 +50,74 @@ inventory_plus.set_inventory_formspec = function(player,formspec)
end
end
-- create detached inventory for trashcan
local
trashInv
=
minetest
.
create_detached_inventory
(
"trash"
,
{
on_put
=
function
(
inv
,
toList
,
toIndex
,
stack
,
player
)
inv
:
set_stack
(
toList
,
toIndex
,
ItemStack
(
nil
))
end
})
trashInv
:
set_size
(
"main"
,
1
)
-- get_formspec
inventory_plus
.
get_formspec
=
function
(
player
,
page
)
--if not player then
-- return
--end
inventory_plus
.
get_formspec
=
function
(
player
,
page
)
if
not
player
then
return
end
-- default inventory page
local
formspec
=
"size[8,7.5]"
-- player inventory
formspec
=
formspec
..
"list[current_player;main;0,3.5;8,4;]"
..
default
.
gui_bg
..
default
.
gui_bg_img
..
default
.
gui_slots
..
"list[current_player;main;0,3.5;8,4;]"
-- craft page
if
page
==
"craft"
then
formspec
=
formspec
..
"button[0,0;2,0.5;main;Back]"
..
"list[current_player;craftpreview;7,1;1,1;]"
if
minetest
.
setting_getbool
(
"inventory_craft_small"
)
then
formspec
=
formspec
..
"list[current_player;craft;3,0;2,2;]"
..
"listring[current_name;craft]"
..
"listring[current_player;main]"
--player:get_inventory():set_width("craft", 2)
--player:get_inventory():set_size("craft", 2*2)
else
formspec
=
formspec
..
"list[current_player;craft;3,0;3,3;]"
..
"listring[current_name;craft]"
..
"listring[current_player;main]"
--player:get_inventory():set_width("craft", 3)
--player:get_inventory():set_size("craft", 3*3)
if
page
==
"craft"
then
local
inv
=
player
:
get_inventory
()
or
nil
if
not
inv
then
print
(
"NO INVENTORY FOUND"
)
return
end
formspec
=
formspec
..
"button[0,1;2,0.5;main;Back]"
..
"list[current_player;craftpreview;7,1;1,1;]"
..
"list[current_player;craft;3,0;3,3;]"
..
"listring[current_name;craft]"
..
"listring[current_player;main]"
-- trash icon
..
"list[detached:trash;main;1,2;1,1;]"
..
"image[1.1,2.1;0.8,0.8;creative_trash_icon.png]"
end
-- creative page
if
page
==
"creative"
then
if
page
==
"creative"
then
return
player
:
get_inventory_formspec
()
..
"button[5
,0;2
,0.
5
;main;Back]"
..
"button[5
.4,4.2;2.65
,0.
3
;main;Back]"
end
-- main page
if
page
==
"main"
then
if
page
==
"main"
then
-- buttons
local
x
,
y
=
0
,
0
for
k
,
v
in
pairs
(
inventory_plus
.
buttons
[
player
:
get_player_name
()])
do
formspec
=
formspec
..
"button["
..
x
..
","
..
y
..
";2,0.5;"
..
k
..
";"
..
v
..
"]"
x
=
x
+
2
local
x
,
y
=
0
,
1
for
k
,
v
in
pairs
(
inventory_plus
.
buttons
[
player
:
get_player_name
()])
do
formspec
=
formspec
..
"button["
..
x
..
","
..
y
..
";2,0.5;"
..
k
..
";"
..
v
..
"]"
x
=
x
+
2
if
x
==
8
then
x
=
0
y
=
y
+
1
x
=
0
y
=
y
+
1
end
end
end
...
...
@@ -95,39 +127,52 @@ end
-- register_on_joinplayer
minetest
.
register_on_joinplayer
(
function
(
player
)
if
minetest
.
setting_getbool
(
"inventory_craft_small"
)
then
player
:
get_inventory
():
set_width
(
"craft"
,
2
)
player
:
get_inventory
():
set_size
(
"craft"
,
2
*
2
)
else
player
:
get_inventory
():
set_width
(
"craft"
,
3
)
player
:
get_inventory
():
set_size
(
"craft"
,
3
*
3
)
end
inventory_plus
.
register_button
(
player
,
"craft"
,
"Craft"
)
inventory_plus
.
register_button
(
player
,
"craft"
,
"Craft"
)
if
minetest
.
setting_getbool
(
"creative_mode"
)
then
inventory_plus
.
register_button
(
player
,
"creative_prev"
,
"Creative"
)
inventory_plus
.
register_button
(
player
,
"creative_prev"
,
"Creative"
)
end
minetest
.
after
(
1
,
function
()
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
inventory_plus
.
default
))
minetest
.
after
(
1
,
function
()
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
inventory_plus
.
default
))
end
)
end
)
-- register_on_player_receive_fields
minetest
.
register_on_player_receive_fields
(
function
(
player
,
formname
,
fields
)
-- main
if
fields
.
main
then
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"main"
))
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"main"
))
return
end
-- craft
if
fields
.
craft
then
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"craft"
))
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"craft"
))
return
end
-- creative
if
fields
.
creative_prev
or
fields
.
creative_next
then
minetest
.
after
(
0
.
1
,
function
()
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"creative"
))
if
fields
.
creative_prev
or
fields
.
creative_next
then
minetest
.
after
(
0
.
1
,
function
()
inventory_plus
.
set_inventory_formspec
(
player
,
inventory_plus
.
get_formspec
(
player
,
"creative"
))
end
)
return
end
end
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment