Page 1 of 3

[0.17] Even Distribution

Posted: Thu May 04, 2017 12:17 am
by 321freddy
Image

Image

Description

Modifies vanilla behaviour for CTRL + Click Drag to evenly distribute the items over multiple buildings.

Pick an item, hold CTRL and Click Drag it over multiple buildings. Start dragging while NOT hovering over a building with the mouse.

Modes
  • CTRL + Left Click Drag = Evenly distribute all items in your inventory
  • CTRL + Right Click Drag = Evenly distribute half the items in your inventory

Inventory Cleanup Hotkey

Evenly distributes excess trash items from inventory into nearby machines and chests. (default SHIFT + C)
The mod has a default list of trash which includes raw ores, intermediates and science packs.
Any items from your trashslots are also distributed.

Customize the default trash list with
  • Vanilla autotrash. Use the configurable startup setting to enable autotrash in early game.
  • Logistic requests. Any items of which you have more than requested will be distributed.
  • Custom trash setting (Per player mod setting). A list of item names with the amounts to keep in inventory seperated by spaces.

Mod Portal Link

Source Code

This is my first mod so be kind! :D
Feedback and suggestions are welcome.

Re: [0.15] Even Distribution

Posted: Thu May 04, 2017 1:17 am
by bbgun06
Brilliant idea!

Re: [0.15] Even Distribution

Posted: Thu May 04, 2017 2:11 am
by 321freddy
bbgun06 wrote:Brilliant idea!
Thanks :)

Re: [0.15] Even Distribution

Posted: Thu May 04, 2017 6:23 am
by sparr

Code: Select all

Error while running even-distribution::on_selected_entity_changed (ID 52)
__even-distribution__/scripts/distribute.lua:108:attempt to index local 'recipe' (a nil value)
Happened as I placed an Assembler 2.

I'm adding a `if recipe == nil then return 0 end` to see if that resolves it.

Re: [0.15] Even Distribution

Posted: Thu May 04, 2017 8:17 am
by 321freddy
sparr wrote:

Code: Select all

Error while running even-distribution::on_selected_entity_changed (ID 52)
__even-distribution__/scripts/distribute.lua:108:attempt to index local 'recipe' (a nil value)
Happened as I placed an Assembler 2.

I'm adding a `if recipe == nil then return 0 end` to see if that resolves it.
Fixed for version 0.0.3. Seems like I forgot 2 brackets :D

Re: [0.15] Even Distribution

Posted: Thu May 04, 2017 6:09 pm
by db48x
I was just running along laying a belt and it fast-replaced a tile of belt going the opposite direction.

Code: Select all

Error while running event even-distribution::on_player_cursor_stack_changed (ID 29)
__even-distribution__/scripts/distribute.lua:90: attempt to index local 'entity' (a nil value)

Re: [0.15] Even Distribution

Posted: Fri May 05, 2017 2:48 am
by fritzy
db48x wrote:I was just running along laying a belt and it fast-replaced a tile of belt going the opposite direction.

Code: Select all

Error while running event even-distribution::on_player_cursor_stack_changed (ID 29)
__even-distribution__/scripts/distribute.lua:90: attempt to index local 'entity' (a nil value)
Same issue: I was holding M1 and moving along to place a line of inserters, and the game crashed with the message above. I'm running 0.15.6. Here's the log dump starting with the error, if it helps:

Code: Select all

   0.007 2017-05-04 21:39:00; Factorio 0.15.6 (build 29362, win64, steam)
   0.007 Operating system: Windows 10 (version 1607) 
...
3688.674 Error MainLoop.cpp:853: Exception at tick 179999: Error while running event even-distribution::on_player_cursor_stack_changed (ID 29)
__even-distribution__/scripts/distribute.lua:90: attempt to index local 'entity' (a nil value)
3688.674 Error ServerMultiplayerManager.cpp:93: MultiplayerManager failed: "Error while running event even-distribution::on_player_cursor_stack_changed (ID 29)
__even-distribution__/scripts/distribute.lua:90: attempt to index local 'entity' (a nil value)"
3688.674 Info ServerMultiplayerManager.cpp:663: mapTick(179999) changing state from(InGame) to(Failed)
3689.923 Info ServerMultiplayerManager.cpp:139: Quitting multiplayer connection.
3689.923 Info ServerMultiplayerManager.cpp:663: mapTick(179999) changing state from(Failed) to(Closed)
3690.051 Info HttpSharedState.cpp:44: Downloading https://multiplayer.factorio.com/remove-game/1794902
3690.192 Info HttpSharedState.cpp:111: Status code: 200
3690.192 Info UDPSocket.cpp:234: Socket closed
3690.288 Info UDPSocket.cpp:234: Socket closed
3690.290 Error CrashHandler.cpp:141: Exception Code: c0000005, Address: 0x00007ff7f151ef99
ModuleBase: 0x00007ff7f1110000, ImageSize: 0118f000, RelativeAddress: 0040ef99
3690.290 Error CrashHandler.cpp:151: Exception Context:
rax=0000028553b686a0, rbx=00000285b6006910, rcx=000000ca765ff5b0,
rdx=0000000000000000, rsi=0000000000000001, rdi=0000028551813070,
rip=00007ff7f151ef99, rsp=000000ca765ff580, rbp=000000ca765ff680,
 r8=0000028551813060,  r9=2aaaaaaaaaaaaaab, r10=0000000000000000,
r11=000000ca765ff970, r12=0000000000000000, r13=0000000000000000,
r14=0000000000000000, r15=0000000000000000
3690.290 Crashed in E:\Games\Steam\steamapps\common\Factorio\bin\x64\Factorio.exe (0x00007ff7f1110000 - 0x00007ff7f229f000)
Factorio crashed. Generating symbolized stacktrace, please wait ...
c:\cygwin64\tmp\factorio-0ypl8d\libraries\stackwalker\stackwalker.cpp (923): StackWalker::ShowCallstack
c:\cygwin64\tmp\factorio-0ypl8d\src\util\logger.cpp (354): Logger::writeStacktrace
c:\cygwin64\tmp\factorio-0ypl8d\src\util\logger.cpp (408): Logger::logStacktrace
c:\cygwin64\tmp\factorio-0ypl8d\src\util\crashhandler.cpp (105): CrashHandler::writeStackTrace
c:\cygwin64\tmp\factorio-0ypl8d\src\util\crashhandler.cpp (177): CrashHandler::SehHandler
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF947AA4F77)
00007FF947AA4F77 (KERNELBASE): (filename not available): UnhandledExceptionFilter
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94AA4ED1B)
00007FF94AA4ED1B (ntdll): (filename not available): memset
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94AA36BD6)
00007FF94AA36BD6 (ntdll): (filename not available): _C_specific_handler
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94AA4AB9D)
00007FF94AA4AB9D (ntdll): (filename not available): _chkstk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94A9E9913)
00007FF94A9E9913 (ntdll): (filename not available): RtlImageNtHeaderEx
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94AA49CBA)
00007FF94AA49CBA (ntdll): (filename not available): KiUserExceptionDispatcher
c:\cygwin64\tmp\factorio-0ypl8d\src\net\servermultiplayermanager.cpp (548): ServerMultiplayerManager::performServerUpdaterLogic
c:\cygwin64\tmp\factorio-0ypl8d\src\net\servermultiplayermanager.cpp (517): ServerMultiplayerManager::updateInternal
c:\cygwin64\tmp\factorio-0ypl8d\src\net\servermultiplayermanager.cpp (496): ServerMultiplayerManager::update
c:\cygwin64\tmp\factorio-0ypl8d\src\mainloop.cpp (710): MainLoop::gameUpdateLoop
c:\cygwin64\tmp\factorio-0ypl8d\src\util\workerthread.cpp (35): WorkerThread::loop
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread (247): std::_LaunchPad<std::unique_ptr<std::tuple<void (__cdecl*)(ParallelScenarioSaver * __ptr64),ParallelScenarioSaver * __ptr64>,std::default_delete<std::tuple<void (__cdecl*)(ParallelScenarioSaver * __ptr64),ParallelScenarioSaver * __ptr64> > > >::_Run
c:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread (210): std::_Pad::_Call_func
d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp (115): thread_start<unsigned int (__cdecl*)(void * __ptr64)>
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF9497F8364)
00007FF9497F8364 (KERNEL32): (filename not available): BaseThreadInitThunk
ERROR: SymGetLineFromAddr64, GetLastError: 487 (Address: 00007FF94AA070D1)
00007FF94AA070D1 (ntdll): (filename not available): RtlUserThreadStart
3695.067 Error Util.cpp:76: Unexpected error occurred. If you're running the latest version of the game you can help us solve the problem by posting the contents of the log file on the Factorio forums.
Please also include the save file(s), any mods you may be using, and any steps you know of to reproduce the crash.

I'm guessing you need a null-guard for entity on entry to distribute.getFullItemCount...

Re: [0.15] Even Distribution

Posted: Fri May 05, 2017 4:37 pm
by 321freddy
It should now be fixed for version 0.1.0 although I was not able to reproduce it so tell me if it still crashes.

Re: [0.15] Even Distribution

Posted: Fri May 05, 2017 6:37 pm
by db48x
Thanks. It hasn't crashed yet!

Re: [0.15] Even Distribution

Posted: Thu Jun 01, 2017 6:47 pm
by 321freddy
New version 0.2.2
  • Added inventory cleanup hotkey: Evenly distribute excess trash items into nearby machines
  • Added distribution text colors: Red = You have insufficient items; Yellow = Target inventory is full
  • Added fancy distribution fade out animation
  • Added option to prevent machines from starting to craft immediately upon selection
  • Fixed rare crash when evenly distributing
  • Fixed crash when dead players try to evenly distribute
  • Other small fixes

Re: [0.15] Even Distribution

Posted: Sat Jun 03, 2017 2:11 am
by Arumba
This mod is so freaking amazing. Just love it to death.

Re: [0.15] Even Distribution

Posted: Sat Jun 03, 2017 3:14 pm
by 321freddy
Hotfix version 0.2.3
  • Fixed that you could evenly distribute into player corpses
  • Fixed issues with dead players trying to evenly distribute or use inventory cleanup
  • Fixed that players in godmode couldn't evenly distribute
  • Fixed several crashes with inventory cleanup
  • Added proper error checking for custom player trash settings
  • Fixed that custom player trash settings sometimes wouldn't work
Arumba wrote:This mod is so freaking amazing. Just love it to death.
Thanks a lot :)

Re: [0.15] Even Distribution

Posted: Sun Jun 04, 2017 3:39 am
by Arumba
Can I ask for another feature?

Could you take a look at Choumiko's autotrash, or klonan's upgrade planner mods, and try to make a simple GUI for your trash items feature?

Looking up the entity names and typing them in by hand feels so... anti-factorio.

(And it reminds me of the god-awful autofill console command system).

Just an idea!

*Edit* oooh, and one more! A Box-Select 'GRAB FROM ALL THIS' function. We have the ability now to say 'DUMP ALL THE STUFFS', but we have to click drag over rows of furnaces instead of a quick box select on an entire column. Could it be done?

Re: [0.15] Even Distribution

Posted: Sun Jun 04, 2017 10:48 am
by 321freddy
Arumba wrote:Looking up the entity names and typing them in by hand feels so... anti-factorio.
You don't have to do that. That's specifically the reason why I made vanilla autotrash available in early game (configurable startup setting).
I just added the config trash list for the very early stages where you DON'T have autotrash.

I updated the above mod post to be more precise about this.
Just use the vanilla autotrash gui to select the items you don't want. Autotrash has priority over all the other options. ;)
Arumba wrote:*Edit* oooh, and one more! A Box-Select 'GRAB FROM ALL THIS' function. We have the ability now to say 'DUMP ALL THE STUFFS', but we have to click drag over rows of furnaces instead of a quick box select on an entire column. Could it be done?
I don't know about this one. The mod is already a bit cheaty in that you can run an entire factory by standing in the middle of it spamming a hotkey. This feature would make that even worse and it's not what I intended the trash hotkey to do. I just wanted it to get rid of useless items :roll:

And as I told you already the issue with box-select is that it only works with planner items like decon planner or upgrade planner, not with an empty hand. But again is it worth having a planner only to grab some stuff where you could just use CTRL click drag?

Re: [0.15] Even Distribution

Posted: Sun Jun 04, 2017 6:56 pm
by Arumba
That's fair. As it is right now its really fun to use, but it does seem very strong.

Is there any way you could somehow tweak the way it dumps items into furnaces? In our larger save we the omnimatter mod which generates ore that has a fuel value of 3mj and stacks up to 500 units. Even distribution just *loves* dumping 500 omnite into everything. Every furnace (and unfortunately it defaults to the fuel slot over the input slot, so burner entities that crush omnite have to first fill up their fuel input before they can start crushing), and even worse, every burner inserter end up hogging up all the stuff.

In autofill you could set limits to fill on placement, perhaps even distribution could have upper bounds to fill to? Say for example, only distribute up to X MJ worth of fuel value into a fuel slot? I don't know. It's just an annoyance ;)

Re: [0.15] Even Distribution

Posted: Sun Jun 04, 2017 10:28 pm
by 321freddy
Yeah that seems like a good addition :)
Although I wanted to cleanup the code a bit first because it is an inefficient mess right now.
The limits will be easier to implement with cleaner code so I'll do it afterwards.

I'll add it to a roadmap on the above mod post including some other stuff I had planned.

Re: [0.15] Even Distribution

Posted: Tue Jun 06, 2017 6:19 pm
by Helex288
Since 0.15.18 i'm getting the following error message every time i want to start a game:

Error while running the on_init: __even-distribution__/scripts/setup.lua:182: attempt to index field 'flags' (a nil value)

Not sure what is causing this issue? if i disable this mod the game runs fine

Re: [0.15] Even Distribution

Posted: Tue Jun 06, 2017 6:42 pm
by Factorie
Thank you for this! Hopefully it'll be something added into vanilla soon.

Re: [0.15] Even Distribution

Posted: Wed Jun 07, 2017 9:55 am
by 321freddy
Helex288 wrote:Since 0.15.18 i'm getting the following error message every time i want to start a game:

Error while running the on_init: __even-distribution__/scripts/setup.lua:182: attempt to index field 'flags' (a nil value)

Not sure what is causing this issue? if i disable this mod the game runs fine
This was probably caused by some other mod that modifies existing items, because it never happened to me. I fixed it for version 0.2.4. Make sure to update the mod.

Version 0.2.4
  • Fixed crash on startup caused by mods that modify item flags
Factorie wrote:Thank you for this! Hopefully it'll be something added into vanilla soon.
Yeah let's hope, they said they planned some QoL improvements for 0.16. :roll:

Re: [0.15] Even Distribution

Posted: Wed Jun 07, 2017 4:20 pm
by Helex288
Works like a charm now! tnx!!!!