Skip to content

Move broken tool head drop from DamageItem to DestroyItem - #139

Open
MetaflameDragon wants to merge 2 commits into
jayugg:masterfrom
MetaflameDragon:fix/duplicate-tool-heads
Open

Move broken tool head drop from DamageItem to DestroyItem#139
MetaflameDragon wants to merge 2 commits into
jayugg:masterfrom
MetaflameDragon:fix/duplicate-tool-heads

Conversation

@MetaflameDragon

@MetaflameDragon MetaflameDragon commented Aug 2, 2026

Copy link
Copy Markdown

Previously, the mod would drop a broken tool head whenever a tool was about to get destroyed by checking the expected durability loss before DamageItem runs. With this change, it instead reacts to when the tool is destroyed by having DestroyItem called.

This PR retains the previous logic of checking for durability. This was a necessity in DamageItem, but doing this in DestroyItem means that we check whether the tool was at 0 durability the moment it was destroyed. This means that the broken tool head won't drop if the item is destroyed early for another reason, though this check may also be undesirable at this point. If the tool head should drop even if the item is destroyed by other means, this durability check should also be removed.

This fixes #138 (and, by extension, Mario90900/Toolsmith#49)

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MetaflameDragon, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8d88498f-30e4-4246-9a79-12e4085c13c5

📥 Commits

Reviewing files that changed from the base of the PR and between 7fb14d0 and 629f6c5.

📒 Files selected for processing (3)
  • SmithingPlus/Core.Cache.cs
  • SmithingPlus/ToolRecovery/CollectibleBehaviorRepairableTool.cs
  • SmithingPlus/ToolRecovery/ItemDamagedPatches.cs
📝 Walkthrough

Walkthrough

The tool recovery patch now hooks CollectibleObject.DestroyItem instead of DamageItem. It checks remaining durability directly and retains server-side, repairable-tool, and recovery behavior.

Changes

Tool recovery

Layer / File(s) Summary
Use the destruction hook
SmithingPlus/ToolRecovery/ItemDamagedPatches.cs
The prefix now handles DestroyItem, removes damage-related parameters, and checks for zero or unavailable durability before recovery.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 138 — The patch implements the switch from DamageItem prediction to the actual DestroyItem event.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes moving broken tool head drops from DamageItem to DestroyItem.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@SmithingPlus/ToolRecovery/ItemDamagedPatches.cs`:
- Around line 56-65: Update Prefix_DestroyItem so recovery does not create or
give a broken head until DestroyItem has actually succeeded; account for
CollectibleBehavior.OnDestroyItem cancellation through a post-success hook or
equivalent validation. Preserve the existing server-side and zero-durability
checks, and ensure canceled destruction leaves the original item state
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 105d094f-d96e-4858-953a-c2b591a96f31

📥 Commits

Reviewing files that changed from the base of the PR and between 241b9f2 and 7fb14d0.

📒 Files selected for processing (1)
  • SmithingPlus/ToolRecovery/ItemDamagedPatches.cs

Comment thread SmithingPlus/ToolRecovery/ItemDamagedPatches.cs Outdated
@MetaflameDragon

MetaflameDragon commented Aug 2, 2026

Copy link
Copy Markdown
Author

As per the auto-review, running the tool head drop code would be the cleanest within an OnDestroyItem method override rather than using a Harmony patch.

I'm unsure about the reason behind why a patch was used previously, and wanted to submit only minimal changes, but given the suggestion, might as well move everything to a method override. I've never modded VS, but it seemed like a sensible implementation change. The behavior already exists and was checked for in the prefix patch, so I believe this should behave the same way.

The change also includes a few small fixes regarding nullability to make the linter happy. I think the previous code relied on these assumptions already, so I just tweaked some ?'s and !'s where appropriate to make the yellow squigglies go away. Should be semantically the same.

Use this second commit as-is if the method override in CollectibleBehaviorRepairableTool is okay; revert the change if you'd rather just use the patch like before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken tool head drops when tool damage is skipped due to custom behavior

1 participant