-
Notifications
You must be signed in to change notification settings - Fork 0
Add auto-select mode to nuker #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@coderabbitai full review |
✅ Actions performedFull review triggered. |
Warning Rate limit exceeded@visz11 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 11 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Player
participant NukerModule
Player->>NukerModule: Activate (with ListMode = AutoSelect)
NukerModule->>Player: Get block under crosshair
NukerModule->>NukerModule: Set autoSelectBlock
loop OnTickPre event
NukerModule->>NukerModule: Check block matches autoSelectBlock
alt Match
NukerModule->>NukerModule: Break block
end
end
Player->>NukerModule: Deactivate
NukerModule->>NukerModule: Clear autoSelectBlock
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
/refacto-test |
Refacto is reviewing this PR. Please wait for the review comments to be posted. |
Solid Implementation - Address Critical AutoSelect Mode Issues
|
if (listMode.get() == ListMode.AutoSelect) { | ||
HitResult hitResult = mc.crosshairTarget; | ||
if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK) { | ||
BlockPos pos = ((BlockHitResult) hitResult).getBlockPos(); | ||
autoSelectBlock = mc.world.getBlockState(pos).getBlock(); | ||
} else { | ||
autoSelectBlock = null; | ||
warning("No block is being targeted for auto-select mode."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Validation for AutoSelect Block Target
The AutoSelect mode initializes the target block only once when the module is activated, but does not validate that a block is successfully selected before allowing the module to run. If no block is targeted during activation (autoSelectBlock is null), the module will still be enabled but won't break any blocks, potentially confusing users. More critically, if the module is activated with no block in sight and then the user looks at a block, the module will remain ineffective without any clear indication of the problem.
if (listMode.get() == ListMode.AutoSelect) {
HitResult hitResult = mc.crosshairTarget;
if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
autoSelectBlock = mc.world.getBlockState(pos).getBlock();
info("Auto-selected block: " + autoSelectBlock.getName().getString());
} else {
autoSelectBlock = null;
error("No block is being targeted for auto-select mode. Please look at a block and try again.");
this.toggle(); // Disable the module if no block is targeted
return; // Exit early
}
}
References
Standard: CWE-754: Improper Check for Unusual or Exceptional Conditions
Standard: OWASP Top 10 2021: A08 - Software and Data Integrity Failures
switch (listMode.get()) { | ||
case AutoSelect -> { | ||
if (autoSelectBlock == null || !blockState.getBlock().equals(autoSelectBlock)) | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential NullPointerException in Block Selection Logic
The AutoSelect mode implementation checks if autoSelectBlock is null or doesn't match the current block, but there's no safeguard against autoSelectBlock being null during module operation. While the onActivate method attempts to initialize it, there could be cases where it remains null (e.g., if the target block changes after activation). This could lead to unpredictable behavior or crashes when the module is running.
case AutoSelect -> {
if (autoSelectBlock == null) {
error("Auto-select block is null. Disabling module.");
toggle();
return;
}
if (!blockState.getBlock().equals(autoSelectBlock))
return;
}
References
Standard: Design by Contract - Precondition Validation
switch (listMode.get()) { | ||
case AutoSelect -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant Block Type Checking in AutoSelect Mode
The AutoSelect mode performs an equality check on every block in range, which is inefficient. For large ranges, this can result in thousands of object equality comparisons per tick. The current implementation also doesn't handle the case where autoSelectBlock is null efficiently, as it will still iterate through all blocks in range before determining none match.
case AutoSelect -> {
// Skip all processing if no block is selected
if (autoSelectBlock == null) return;
// Use == for faster reference comparison before equals()
if (blockState.getBlock() != autoSelectBlock && !blockState.getBlock().equals(autoSelectBlock))
return;
References
Standard: Java Performance Best Practices - Object Comparison Optimization
Type of change
Description
Added a new whitelist mode 'AutoSelect'. It can just select the block you are looking at when active.
This is convenient when using keybind to mine specific blocks and also can be switched through activation.
Related issues
Mention any issues that this pr relates to.
How Has This Been Tested?
It works on my local test.
Checklist:
Summary by CodeRabbit