Fix: PipeSystem Spawn Amount Bug In Vanilla Expanded Framework

by Dimemap Team 63 views

Hey guys! Let's dive into a tricky bug in the Vanilla Expanded Framework that's causing some headaches for players. It's all about how the PipeSystem handles the CompConvertToThing component, specifically when it comes to setting the maximum amount of things to spawn. If the Props.maxOutputStackSize is equal to or higher than the thing's stackLimit, the system stubbornly uses the thing's maximum stack count instead of the target stack count that the player has set. This can lead to some unexpected results, especially when you're trying to manage resources efficiently.

Reproducing the Bug: A Practical Example

To really understand what's going on, let's look at a concrete example. This bug can be easily reproduced by loading both the Big and Small - Framework and Vanilla Nutrient Paste Expanded mods at the same time. These mods, while fantastic additions to the game, interact in a way that exposes this underlying issue in the PipeSystem. The root cause lies in an XML patch within the Big and Small - Framework mod, specifically this one:

https://github.com/RedMattis/BigSmall_Framework/blob/78349d158e652cf7cb4aec2111ce8306b58f992a/1.6/Base/Patches/compatibilityPatches.xml#L37-L47

While the patch itself isn't inherently broken, its interaction with the VanillaExpandedFramework reveals the bug. You can also check out this related Steam discussion for more context:

https://steamcommunity.com/workshop/filedetails/discussion/2920385763/4632609113412572695/

It's important to note that this isn't necessarily a problem with Big and Small - Framework itself. The issue stems from how the VanillaExpandedFramework handles stack sizes in certain situations.

Diving Deeper: How Stack Sizes Trigger the Bug

The core of the problem lies in how the CompConvertToThing component determines the stack size of the spawned items. The bug can also be triggered by simply changing the nutrient paste stack size to 5 or lower. This is significant because there are already many mods out there that modify stack sizes for various items. This means that the bug isn't limited to just this specific mod combination; it can potentially surface in various modded setups.

Think of it like this: if you're trying to produce nutrient paste and you've set a specific target stack size (let's say, 3), but the system is forced to use the maximum stack size of the paste (which might be 75), you're going to end up with a lot more paste than you intended! This can throw off your resource management and lead to some frustrating situations. The root cause is that the system isn't respecting the player's desired stack size. Instead, it's defaulting to the item's maximum stack size, which can be much larger.

The Simple Fix: Commenting Out the Code

Okay, so we've identified the problem. What's the solution? Thankfully, there's a relatively straightforward fix. A simple workaround is to comment out a few lines of code within the CompConvertToThing.cs file. This will prevent the system from defaulting to the item's maximum stack size and ensure that it respects the player's target stack size.

Here are the specific lines you'll want to comment out:

https://github.com/Vanilla-Expanded/VanillaExpandedFramework/blob/6c4a369ba418ef522b1705eaa06fb38303eebf74/Source/PipeSystem/PipeSystem/Comps/CompConvertToThing.cs#L124-L125

And these lines as well:

https://github.com/Vanilla-Expanded/VanillaExpandedFramework/blob/6c4a369ba418ef522b1705eaa06fb38303eebf74/Source/PipeSystem/PipeSystem/Comps/CompConvertToThing.cs#L133-L135

By commenting out these lines, you're essentially telling the system to use the target stack size that the player has set, regardless of the item's maximum stack size. This will ensure that your resource production is more predictable and aligned with your intended settings.

Why This Fix Works: A Deeper Dive into the Code

To really understand why this fix works, let's take a closer look at the code snippets in question. The lines being commented out are responsible for overriding the target stack size with the item's maximum stack size under certain conditions. Specifically, if the Props.maxOutputStackSize (which is the maximum stack size that the system is allowed to output) is equal to or greater than the item's stackLimit (the maximum stack size of the item itself), the code forces the system to use the stackLimit. This is where the bug originates.

By commenting out this logic, we're preventing the system from making this override. Instead, it will use the target stack size that the player has set, which is the desired behavior. This fix ensures that the PipeSystem respects the player's input and produces the correct amount of items.

Think of it like having a volume knob on a speaker. The original code was like having a safety mechanism that automatically cranked the volume up to the maximum if it thought it was safe to do so. While this might seem like a good idea in some situations, it overrides the user's desired volume setting. The fix is like removing that safety mechanism, giving the user full control over the volume.

Implications and Considerations

While this fix is effective in resolving the immediate bug, it's important to consider the broader implications. By commenting out this code, we're changing the fundamental behavior of the PipeSystem. In most cases, this is a positive change, as it aligns the system with the player's expectations. However, there might be some edge cases where the original behavior was intentional or even beneficial.

For example, if a player deliberately sets a very high target stack size, the original code might have prevented the system from producing an excessive amount of items that could overwhelm the storage. With the fix in place, it's possible that the system could produce larger stacks than intended in certain situations. It's crucial to be aware of this potential side effect and to monitor your resource production after applying the fix.

That being said, the vast majority of players will likely find the fixed behavior to be much more intuitive and predictable. The ability to control the stack size of produced items is essential for efficient resource management, and this fix restores that control.

Community Input and Further Discussion

It's always great to get community feedback on issues like this. If you've encountered this bug or have any thoughts on the fix, please share your experiences! Your input can help us better understand the issue and ensure that the solution is as robust as possible.

This bug report and the proposed fix have also been discussed in the Steam community, and the feedback has been invaluable in refining the solution. Collaboration and open communication are key to creating a better modding experience for everyone.

In Conclusion: A More Predictable PipeSystem

This bug in the VanillaExpandedFramework's PipeSystem could lead to some frustrating situations, especially when dealing with resource production. By understanding the root cause of the issue and applying the simple fix of commenting out a few lines of code, you can regain control over your item stacks and enjoy a more predictable gameplay experience. Remember to keep an eye on your resource production after applying the fix, and don't hesitate to share your feedback with the community.

Hopefully, this explanation has been helpful! Happy modding, guys!