3 local drop_action = InventoryAction("drop")
5 local strip_move_act = InventoryAction("move")
6 strip_move_act:to("current_player", "craft", 1)
7 local strip_craft_act = InventoryAction("craft")
8 strip_craft_act:craft("current_player")
9 local strip_move_back_act = InventoryAction("move")
10 strip_move_back_act:from("current_player", "craftresult", 1)
12 core.register_globalstep(function(dtime)
13 local player = core.localplayer
14 if not player then return end
15 local item = player:get_wielded_item()
16 local itemdef = core.get_item_def(item:get_name())
17 local wieldindex = player:get_wield_index()
19 if core.settings:get_bool("autorefill") and itemdef then
20 local space = item:get_free_space()
21 local i = core.find_item(item:get_name(), wieldindex + 1)
22 if i and space > 0 then
23 local move_act = InventoryAction("move")
24 move_act:to("current_player", "main", wieldindex)
25 move_act:from("current_player", "main", i)
26 move_act:set_count(space)
31 if core.settings:get_bool("strip") then
32 if itemdef and itemdef.groups.tree and player:get_control().RMB then
33 strip_move_act:from("current_player", "main", wieldindex)
34 strip_move_back_act:to("current_player", "main", wieldindex)
35 strip_move_act:apply()
36 strip_craft_act:apply()
37 strip_move_back_act:apply()
41 if core.settings:get_bool("autoeject") then
42 local list = (core.settings:get("eject_items") or ""):split(",")
43 local inventory = core.get_inventory("current_player")
44 for index, stack in pairs(inventory.main) do
45 if table.indexof(list, stack:get_name()) ~= -1 then
46 drop_action:from("current_player", "main", index)
52 if core.settings:get_bool("next_item") then
53 elapsed_time = elapsed_time + dtime
54 if elapsed_time < tick_time then return end
55 if item:get_count() == 0 then
56 player:set_wield_index(wieldindex + 1)
62 core.register_list_command("eject", "Configure AutoEject", "eject_items")
66 local function check_tool(stack, node_groups, old_best_time)
67 local toolcaps = stack:get_tool_capabilities()
68 if not toolcaps then return end
69 local best_time = old_best_time
70 for group, groupdef in pairs(toolcaps.groupcaps) do
71 local level = node_groups[group]
73 local this_time = groupdef.times[level]
74 if this_time < best_time then
79 return best_time < old_best_time, best_time
82 core.register_on_punchnode(function(pos, node)
83 if not minetest.settings:get_bool("autotool") then return end
84 local player = minetest.localplayer
85 local inventory = minetest.get_inventory("current_player")
86 local node_groups = minetest.get_node_def(node.name).groups
87 local new_index = player:get_wield_index()
88 local is_better, best_time = false, math.huge
89 is_better, best_time = check_tool(player:get_wielded_item(), node_groups, best_time)
90 is_better, best_time = check_tool(inventory.hand[1], node_groups, best_time)
91 for index, stack in pairs(inventory.main) do
92 is_better, best_time = check_tool(stack, node_groups, best_time)
97 player:set_wield_index(new_index)
102 function get_itemslot_bg(x, y, w, h)
104 for i = 0, w - 1, 1 do
105 for j = 0, h - 1, 1 do
106 out = out .."image["..x+i..","..y+j..";1,1;mcl_formspec_itemslot.png]"
112 local enderchest_formspec = "size[9,8.75]"..
113 "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", "Ender Chest")).."]"..
114 "list[current_player;enderchest;0,0.5;9,3;]"..
115 get_itemslot_bg(0,0.5,9,3)..
116 "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", "Inventory")).."]"..
117 "list[current_player;main;0,4.5;9,3;9]"..
118 get_itemslot_bg(0,4.5,9,3)..
119 "list[current_player;main;0,7.74;9,1;]"..
120 get_itemslot_bg(0,7.74,9,1)..
121 "listring[current_player;enderchest]"..
122 "listring[current_player;main]"
124 function core.open_enderchest()
125 core.show_formspec("__builtin__:enderchest", enderchest_formspec)
130 local hand_formspec = "size[9,8.75]"..
131 "label[0,0;"..minetest.formspec_escape(minetest.colorize("#313131", "Hand")).."]"..
132 "list[current_player;hand;0,0.5;1,1;]"..
133 get_itemslot_bg(0,0.5,1,1)..
134 "label[0,4.0;"..minetest.formspec_escape(minetest.colorize("#313131", "Inventory")).."]"..
135 "list[current_player;main;0,4.5;9,3;9]"..
136 get_itemslot_bg(0,4.5,9,3)..
137 "list[current_player;main;0,7.74;9,1;]"..
138 get_itemslot_bg(0,7.74,9,1)..
139 "listring[current_player;hand]"..
140 "listring[current_player;main]"
142 function core.open_handslot()
143 minetest.show_formspec("__builtin__:hand", hand_formspec)