-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add clear button
- Loading branch information
Showing
6 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
-- Clear items in the craft inventory | ||
|
||
|
||
-- Backup to inject code | ||
unified_inventory_plus.craft_clear = unified_inventory.pages["craft"].get_formspec | ||
|
||
local function onload() | ||
unified_inventory.pages["craft"] = { | ||
get_formspec = function(player, perplayer_formspec) | ||
local formspecy = perplayer_formspec.formspec_y + 1 | ||
local formspec = unified_inventory_plus.craft_clear(player, perplayer_formspec).formspec | ||
formspec = formspec.."image_button[1.25,"..(formspecy)..";0.75,0.75;pattern_clear.png;craft_clear;]" | ||
return {formspec=formspec} | ||
end, | ||
} | ||
end | ||
|
||
onload() | ||
|
||
|
||
-- Rotate items in the craft inventory | ||
local function craft_clear(player, formname, fields) | ||
local player_inv = player:get_inventory() | ||
local craft_list = player_inv:get_list("craft") | ||
local remaining_craft_list = craft_list | ||
|
||
for k,v in pairs(craft_list) do | ||
--minetest.chat_send_all(v:get_name().." "..v:get_count()) | ||
if(v:get_count() > 0) then | ||
local nb_left = room_left_for_item(player_inv:get_list("main"), v) | ||
if(nb_left >= v:get_count()) then | ||
place_item_in_stacks(player, "main", v:get_name(), v:get_count()) | ||
remaining_craft_list[k]:clear() | ||
else | ||
place_item_in_stacks(player, "main", v:get_name(), nb_left) | ||
remaining_craft_list[k]:set_count(v:get_count() - nb_left) | ||
end | ||
end | ||
end | ||
|
||
player_inv:set_list("craft", remaining_craft_list) | ||
end | ||
|
||
|
||
|
||
|
||
minetest.register_on_player_receive_fields(function(player, formname, fields) | ||
--if not formname:match("craft") then return end | ||
for k, v in pairs(fields) do | ||
if k:match("craft_clear") then | ||
craft_clear(player, formname, fields) | ||
end | ||
end | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.