fix(experimental/particle_trail): toggle always resolved to on - #34
Merged
Conversation
The toggle logic removed the tag first, then re-checked 'if entity @s[tag=...trail]' — which was now always false since the tag had just been removed on the previous line — so the early 'return 0' never fired and execution fell through to the 'add' line, re-adding the tag on every call. Net effect: toggle never actually turned the trail off. Split into toggle_on/toggle_off helpers and use 'execute ... run return run function ...' so the tag is tested exactly once and the two branches are truly mutually exclusive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
experimental/particle_trail/toggle.mcfunctionwas always getting stuck in the "on" state instead of actually toggling (reported on 1.21.2).Root Cause
The tag is removed on the first line. The second line checks the same condition again, but since the tag no longer exists, the
ifcondition can never match. Therefore, the earlyreturn 0never executes, and execution falls through to the third line, which immediately adds the tag back.Net effect: the trail always ends up "on" after every invocation.
Solution
The tag is now tested once before any mutation and the logic is split into two completely separate branches (
toggle_on/toggle_offhelper functions).return run function ...ensures that the second branch can never execute after the first branch has been triggered.Test Status
A real
server.jartest could not be performed in this environment (network access is disabled). Only static validation was performed: file paths, balanced parentheses/quotes, and manual step-by-step simulation of the logic. It still needs to be tested on a real 1.21.2 server.Note: The GitHub token used to create this PR was exposed during this task. It is recommended to revoke the token once the operation is complete.