Better Combat Bug: Item Loss On Toolbelt Swap (1.20.1)

by Viktoria Ivanova 55 views

Hey everyone! Today, we're diving deep into a peculiar bug report concerning Better Combat and Toolbelt interactions in Minecraft 1.20.1. This issue, reported by mickelus and further explored with Tetra, reveals a scenario where swapping items with a two-handed weapon equipped can lead to items vanishing into thin air. Let's break down the problem, explore the steps to reproduce it, and discuss potential solutions.

Observed Behavior

This bug stems from the two-handed weapon mechanic introduced by Better Combat. Essentially, when wielding a two-handed weapon, the offhand slot gets disabled. Now, Better Combat doesn't natively include any two-handed weapons, so this issue becomes apparent when combined with mods like Simply Swords, which adds a variety of weapons utilizing this mechanic. Simply Swords is strongly recommended for testing purposes, as it readily provides access to weapons with the two-handed attribute.

The core issue manifests in a couple of ways:

  1. Swapping from Offhand to Toolbelt: If you're holding a two-handed weapon and try to swap an item from your offhand into the toolbelt, the item in the belt will correctly move to your offhand. However, the item you were trying to store in the toolbelt simply vanishes – it's voided!
  2. Two-Handed Weapons in Offhand: Holding a two-handed weapon in your offhand can also cause problems during swapping. While the exact mechanism might be similar to the first issue, it's worth noting as a potential complication.

It’s crucial to understand the mechanics at play here. The Better Combat mod, when combined with mods adding two-handed weapons, introduces a unique interaction with the toolbelt. The disabling of the offhand slot by two-handed weapons is the root cause, leading to unexpected item loss during swaps. This isn't just a minor inconvenience; it can lead to the loss of valuable tools or resources, impacting the overall gameplay experience.

Expected Behavior

Ideally, when the offhand slot is disabled, swapping items should not lead to their deletion. A workaround explored via a KubeJS script suggests that the disabled offhand should return a reference to an empty slot, rather than simply voiding the item. The underlying inventory should still retain the item, preventing its loss. The expected behavior is that the toolbelt swap respects the item’s existence, regardless of the offhand's disabled state. Instead of voiding the item, it should either remain in the offhand's logical storage or be correctly placed into the toolbelt.

This expectation is based on the principle of data integrity. Players should be able to trust that their actions within the game world, such as swapping items, will not result in permanent item loss. The current behavior violates this principle, creating a frustrating and potentially game-breaking experience. It’s imperative that the system handles item swapping in a way that preserves the player’s inventory and prevents accidental voiding of items.

Steps to Reproduce

Guys, if you want to see this bug in action, follow these steps:

  1. Get a Belt: First things first, you'll need a toolbelt. Standard procedure.

  2. Acquire a Two-Handed Weapon: This is where it gets interesting. You'll need a weapon with the Two-Handed property. Keep an eye out for tooltips that look something like this:

    Image

    Remember, Better Combat itself doesn't add any two-handed weapons to vanilla Minecraft. Simply Swords is your best bet here, as it seamlessly integrates with Better Combat and provides a good selection of these weapons.

  3. Reproducing the Bug:

    • 3.a Offhand Swap: Place any item in your toolbelt and a different item in your offhand. Now, hold the two-handed weapon and use the swap tool keybind. You'll notice the item from your belt correctly moves to your offhand, but the item you tried to store in the belt vanishes! Using two distinct items visually confirms this one-way swap, highlighting the voiding issue.
    • 3.b Two-Handed in Offhand: Hold the two-handed weapon in your offhand. It'll disappear visually, but if you check your inventory, it'll still be present in the offhand slot (this is normal, as two-handed weapons need to be in the main hand). Now, try storing the weapon using the toolbelt keybind. While not fully confirmed, this scenario likely produces the same voiding effect as 3.a.

These steps provide a clear and reproducible method for experiencing the bug. The visual confirmation aspect, using two different items, is particularly helpful in demonstrating the item loss. By following these steps, developers and players alike can easily verify the existence and behavior of the bug, facilitating more efficient testing and debugging.

Possible Solution

One potential fix lies in revising how offhand items are referenced within the code. Instead of relying solely on the offhand slot's state, a fallback mechanism that checks the player's inventory directly could be implemented. This approach would ensure that items are not lost simply because the offhand slot is temporarily disabled.

Additionally, it's worth considering that this issue might not be unique to Better Combat. Other mods that disable the offhand slot could potentially exhibit the same behavior. Therefore, a more generalized solution that addresses the underlying problem of item referencing in disabled slots would be ideal.

The recommended approach involves a layered check: first, attempt to retrieve the item from the offhand slot. If the slot is disabled or returns null, then consult the player's inventory directly. This ensures that items are accounted for even when the offhand slot's typical functionality is altered. This method provides a robust solution that not only addresses the current bug but also anticipates potential issues with other mods that might interact with the offhand slot in similar ways. By implementing this, the game can maintain item integrity and provide a more consistent user experience.

Additional Information

  • Tetra Version: 6.9.0 (likely present in 6.9.10 as well)
  • Mutil/MGui Version: 6.2.0
  • Forge Version: 1.20.1 - 47.4.2 (likely present on other versions)
  • Other Mods: Better Combat (required), Simply Swords (strongly recommended)

Crashlog

(No response in the original report)

This information provides a comprehensive overview of the bug, its context, and potential solutions. By understanding the specifics of the issue and the suggested remedies, the developers can effectively address the problem and enhance the gameplay experience for all users. The inclusion of version numbers and other relevant mods helps in pinpointing the source of the bug and ensuring that the fix is appropriately targeted.