TL;DR
LuaControl.move_crafting would permit to reorder crafting queue without quirksLuaControl.begin_crafting and LuaControl.cancel_crafting can cause unwanted side effects when reordering and need some hacks to prevent them which cause other unwanted side effects.
What ?
LuaControl.move_crafting(from_index, to_index, merge, count) → uintreorder given count of the recipe at given crafting queue index to the given index position.
If specified, does a merge of the moved recipe stack in the target recipe stack if they correspond to the same recipe. otherwise the new stack is placed before
Child crafts are automatically moved with actual craft to keep consistency.
Child crafts can't be moved alone.
Parameters
- from_index :: uint: The recipe stack index to reorder.
- to_index :: uint: The target index in crafting queue to reorder to.
- merge :: boolean (optional): Does it merge. Default to false
- count :: uint (optional): The count to move. Count greater than recipe stack size would be ignored. By default move the whole recipe stack.
The count that was actually moved.
Examples ?
Code: Select all
player.move_crafting(#player.crafting_queue, 1) -- move last recipe stack to front
player.move_crafting(2, 1, false) -- move second stack to front, without merge
player.move_crafting(2, 1, true) -- move second stack to front, with merge if possible
player.move_crafting(1, 1, false, 1) -- split the first recipe stack with one recipe placed before the others
Why ?
LuaControl.begin_crafting need items in inventory, LuaControl.cancel_crafting put items in inventory or dump them on ground,When reordering those side effect need a hack to prevent dymping on ground, so usually LuaControl.character_inventory_slots_bonus is modified
When modifying LuaControl.character_inventory_slots_bonus, inventory is "reset" and so each Gui using it is rerendered, which effectively reset scrollbars and selectors
LuaControl.move_crafting wouldn't do inventory manipulation and so would never need such hack.
Another solution would be to consider that dump to ground is done after scripts and that inventory can temporary overfill which would don't need the LuaControl.character_inventory_slots_bonus hack
Another solution would be to not trigger a rerendering if LuaControl.character_inventory_slots_bonus has kept his original value