Skip to content

Commit 7488f48

Browse files
kilbithparamat
authored andcommittedJan 5, 2016
Minor polishing of creative
1 parent b0ec8f1 commit 7488f48

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
 

‎mods/creative/init.lua

+10-8
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ function creative_inventory.update(player_name, filter)
5151

5252
for name, def in pairs(minetest.registered_items) do
5353
if not (def.groups.not_in_creative_inventory == 1) and
54-
def.description and def.description ~= "" then
55-
if (filter and def.name:find(filter, 1, true)) or not filter then
56-
creative_list[#creative_list+1] = name
57-
end
54+
def.description and def.description ~= "" and
55+
(not filter or def.name:find(filter, 1, true)) then
56+
creative_list[#creative_list+1] = name
5857
end
5958
end
6059

@@ -136,10 +135,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
136135
local current_page = 0
137136
local player_name = player:get_player_name()
138137
local formspec = player:get_inventory_formspec()
139-
local start_i = formspec:match("list%[detached:creative_" .. player_name .. ";main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
138+
local start_i = formspec:match("list%[detached:creative_" .. player_name .. ";.*;(%d+)%]")
139+
local inv_size = creative_inventory[player_name].size
140140
start_i = tonumber(start_i) or 0
141141

142-
if fields.creative_prev or start_i >= creative_inventory[player_name].size then
142+
if fields.creative_prev or start_i >= inv_size then
143143
start_i = start_i - 4*6
144144
elseif fields.creative_next or start_i < 0 then
145145
start_i = start_i + 4*6
@@ -157,9 +157,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
157157
creative_inventory.set_creative_formspec(player, 0, 1)
158158
end)
159159
end
160-
161-
if start_i < 0 or start_i >= creative_inventory[player_name].size then
160+
161+
if start_i >= inv_size then
162162
start_i = 0
163+
elseif start_i < 0 then
164+
start_i = inv_size - (inv_size % (6*4))
163165
end
164166

165167
creative_inventory.set_creative_formspec(player, start_i, start_i / (6*4) + 1)

0 commit comments

Comments
 (0)
Please sign in to comment.