Crafting Tools


Adds hotkeys to craft items from your cursor, quickbar or nearby ghost items NEW: craft nearby upgrade requests if not in inventory FIX: craft merged chests

Utilities
6 months ago
1.1
1.83K

b Crash when crafting in editor mode or when crafting ghosts with excessive reach range

1 year, 10 months ago
(updated 1 year, 10 months ago)

This thread covers two specific bugs, but since I decided to go in into the code and create a small patch for use with editor/cheat mode, figured it might be better to have a single topic.

Reproduction steps:

  1. Start a new scenario using the Map Editor.

  2. Add basic inserter into quickbar.

  3. Try to craft a single inserter through quickbar shortcut (Alt + 1).

  4. Start a new game.

  5. Place an inserter ghost onto surface.

  6. Enable cheat mode via console (/cheat).

  7. Grant player large reach distance bonus via console: /c game.player.character.character_reach_distance_bonus=10000000.

  8. Press Shift +G to start crafting nearby ghosts (no ghosts need to be placed).

Expected results:

  • In step (3), the inserter crafting fails due to insufficient ingredients.
  • In step (8), the inserter crafting fails due to insufficient ingredients.

Actual results:

  • In step (3), the game crashes with the following stack trace:
craft 1 inserter
  71.719 Error MainLoop.cpp:1284: Exception at tick 292: The mod Crafting Tools (2.0.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Kux-CraftingTools::shortcut-1-craft-1 (ID 184)
No manual crafter.
stack traceback:
    [C]: in function 'get_craftable_count'
    __Kux-CraftingTools__/features/CraftingHotkeys/control.lua:12: in function 'craft'
    __Kux-CraftingTools__/features/CraftingHotkeys/control.lua:101: in function <__Kux-CraftingTools__/features/CraftingHotkeys/control.lua:96>
  • In step (8), the game crashes with the following stack trace:
  51.509 Error MainLoop.cpp:1284: Exception at tick 1723: The mod Crafting Tools (2.0.2) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Kux-CraftingTools::CraftNearbyGhostItems (ID 175)
position: -10000000.429688 is out of range
stack traceback:
    [C]: in function 'find_entities_filtered'
    ...aftingTools__/features/CraftNearbyGhostItems/control.lua:33: in function 'autoCraft'
    ...aftingTools__/features/CraftNearbyGhostItems/control.lua:145: in function <...aftingTools__/features/CraftNearbyGhostItems/control.lua:143>

Additional details:

  • Originally, the errors were produced while using the mod in conjunction with the Creative Mod and Editor Extensions.
  • Crashes related to crafting from cursor/quickbar seem to be specific when running in editor mode.
  • The No manual crafter. error message listed above is thrown by the player.get_craftable_count() invocation in editor mode it seems.
  • I will attach a patch in the first comment that both fixes the crashes, and changes slightly the crafting beahviour in editor/cheat mode (and limits scanning if reach distance is too high for nearby ghost crafting).
1 year, 10 months ago

The following patch takes care of the following:

  • Fixes crashing when crafting from cursor/quickbar in editor mode.
  • Fixes crashing when crafting with excessive reach distance.
  • Gives the player items in editor/cheat mode instead of crafting them. This is a feature improvement.
  • Limits the scanning for ghosts when crafting nearby ghost items in order to avoid game lock-ups in case of excessive reach distance.
diff --git a/features/CraftNearbyGhostItems/control.lua b/features/CraftNearbyGhostItems/control.lua
index 6815f63..869de90 100644
--- a/features/CraftNearbyGhostItems/control.lua
+++ b/features/CraftNearbyGhostItems/control.lua
@@ -23,6 +23,15 @@ local function autoCraft(player)
    info.player_position = player.position

    local reach = player.character.reach_distance
+
+   -- Limit reach distance to some sane value. Useful in cases
+   -- where mods extend reach distance (like creative/cheat mods)
+   -- beyond a value that can be safely used for bounding box
+   -- when searching for entities. Additional plus is that if
+   -- values are too high, the game will freeze up while the
+   -- search function is running.
+   reach = reach > 1000 and 1000
+
    if info.next >= #info.ghosts then
        local aabb = {
            left_top = {player.position.x - reach, player.position.y - reach},
@@ -51,7 +60,10 @@ local function autoCraft(player)

                    local recipe = game.recipe_prototypes[stack.name]
                    local item = stack.name
-                   if player.force.recipes[item] ~= nil and
+
+                   if player.controller_type == defines.controllers.editor or player.cheat_mode then
+                       player.insert({name=item, count=1})
+                   elseif player.force.recipes[item] ~= nil and
                        ((player.get_craftable_count(item) > 0 and
                            player.force.recipes[item].enabled == true)) then
                        if recipe ~= nil and recipe.allow_as_intermediate then
@@ -143,4 +155,4 @@ end)
 script.on_event("CraftNearbyGhostItems", function (e)
    local player = game.players[e.player_index]
    autoCraft(player)
-end)
\ No newline at end of file
+end)
diff --git a/features/CraftingHotkeys/control.lua b/features/CraftingHotkeys/control.lua
index 79ca185..d457889 100644
--- a/features/CraftingHotkeys/control.lua
+++ b/features/CraftingHotkeys/control.lua
@@ -1,5 +1,22 @@
 local craft = function(player, item, count)
-   print("craft "..count.." "..item.name)
+    print("craft "..count.." "..item.name)
+
+    -- Give items to player without crafting if in editor or cheat
+    -- mode. Fixes issue with player.get_craftable_count() function
+    -- causing crashes when in editor mode as well.
+    if player.controller_type == defines.controllers.editor or player.cheat_mode  then
+
+        -- Grant one stack of items instead of filling-up the
+        -- inventory in editor/cheat mode.
+        if count == 0 then
+            count = item.stack_size
+        end
+
+        player.insert({name=item.name, count=count})
+
+        return
+    end
+
     local found = false
     local len = 0
     local recipes = {}
1 year, 10 months ago

By the way, may I suggest to set-up some kind of git repository on some forge for hosting the code? It would help a bit both with creating pull requests, and also make it easier to get the hands on code and see the logic behind commits :)

1 year, 10 months ago

Oh... And thanks a lot for continuing this mod. I really find it to be such a huge improvement over having to continuously go to character menu to craft items.

1 year, 9 months ago

Thank you for contributing. A github repo allready exists:
https://github.com/kuxynator/Kux-CraftingTools
Feel free to make a PR

1 year, 9 months ago

Please tell me those links were not in there before - or did I go completely crazy? :D

Great, I've created the pull request already. A small suggestion/request on my part would be to create tags for releases if possible - makes it slightly simpler to work with troubleshooting from the source :)

And thanks once again for the mod continuation, much appreciated!

1 year, 7 months ago

Hi. sorry, as you noticed, I haven't found time to apply the patch yet. Do you want to become a contributor and do the updates yourself? then contact me pls via discord or telegram

1 year, 6 months ago

Hello again,

Sorry for the late reply from my side - got a bit busy IRL. :)

I would be interested in helping out with this mod at least, although unfortunately I don't use Discord or Telegram - I do have an XMPP account as well as an account on Libera/Freenode IRC servers, though, if that helps (in addition to account on Factorio forums).

If you had any feedback on that PR, I would be more than happy to address it as well :)

Best regards,
Branko

1 year, 6 months ago

There is no reason not to use Discord or Telegram for certain things. I always find it amazing when someone says they don't use this or that communication channel. No one requires that they make it their life's work or provide more information than necessary. An account is created so quickly. Like this XMPP one now: kuxynator@jabbers.one
But whether I use this permanently or even look in daily ,will be seen when I see how user friendly it is ;-) I have no contact yet who has used this.

New response