-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fixed block interaction logic for adventure mode! #289
base: next
Are you sure you want to change the base?
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
WalkthroughThe changes modify the Changes
Sequence Diagram(s)sequenceDiagram
participant P as Player
participant W as WorldInteraction
participant B as CursorBlock
P->>W: Initiate block dig/check
alt cursorBlock is null
W->>W: Set diggable to null
else
alt Player in adventure mode?
W->>W: Set diggable to null
else
alt Cannot dig block and not in creative mode?
W->>W: Set diggable to null
else
W->>W: Mark block as diggable
end
end
end
sequenceDiagram
participant P as Player
participant W as WorldInteraction
P->>W: Attempt block placement/interaction
alt Player in adventure mode?
W->>W: Prevent block interaction
else
W->>W: Process block interaction
end
Poem
✨ Finishing Touches
🪧 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 (
|
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/worldInteractions.ts
(2 hunks)
🧰 Additional context used
🪛 ESLint
src/worldInteractions.ts
[error] 283-283: This branch's code block is the same as the block for the branch on line 282.
(sonarjs/no-duplicated-branches)
[error] 284-284: Expected '!==' and instead saw '!='.
(eqeqeq)
[error] 284-284: This branch's code block is the same as the block for the branch on line 283.
(sonarjs/no-duplicated-branches)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-deploy
🔇 Additional comments (1)
src/worldInteractions.ts (1)
323-323
: LGTM: Adventure mode check correctly implemented.The addition of the adventure mode check before placing blocks aligns with Minecraft's game rules, where players in adventure mode cannot place blocks unless specifically allowed to.
if (!cursorBlock) cursorBlockDiggable = null | ||
else if (inAdventure) cursorBlockDiggable = null | ||
else if (!bot.canDigBlock(cursorBlock) && bot.game.gameMode != 'creative') cursorBlockDiggable = null |
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.
🛠️ Refactor suggestion
Improve the conditional checks for better code quality.
The refactoring of the cursor block diggability logic into sequential checks improves readability, but there are two issues that should be addressed:
- Line 284 uses
!=
instead of the strict equality operator!==
which is the recommended practice in TypeScript. - The three conditions have identical code blocks which could be refactored for cleaner code.
- if (!cursorBlock) cursorBlockDiggable = null
- else if (inAdventure) cursorBlockDiggable = null
- else if (!bot.canDigBlock(cursorBlock) && bot.game.gameMode != 'creative') cursorBlockDiggable = null
+ cursorBlockDiggable = (
+ !cursorBlock ||
+ inAdventure ||
+ (!bot.canDigBlock(cursorBlock) && bot.game.gameMode !== 'creative')
+ ) ? null : cursorBlock;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (!cursorBlock) cursorBlockDiggable = null | |
else if (inAdventure) cursorBlockDiggable = null | |
else if (!bot.canDigBlock(cursorBlock) && bot.game.gameMode != 'creative') cursorBlockDiggable = null | |
cursorBlockDiggable = ( | |
!cursorBlock || | |
inAdventure || | |
(!bot.canDigBlock(cursorBlock) && bot.game.gameMode !== 'creative') | |
) ? null : cursorBlock; |
🧰 Tools
🪛 ESLint
[error] 283-283: This branch's code block is the same as the block for the branch on line 282.
(sonarjs/no-duplicated-branches)
[error] 284-284: Expected '!==' and instead saw '!='.
(eqeqeq)
[error] 284-284: This branch's code block is the same as the block for the branch on line 283.
(sonarjs/no-duplicated-branches)
already fixed in #286 , will be merged soon (I removed worldInteractions.ts completely ther) |
@@ -318,7 +320,7 @@ class WorldInteraction { | |||
} | |||
} | |||
// todo placing with offhand | |||
if (cursorBlock && !activate && !stop) { | |||
if (!inAdventure && cursorBlock && !activate && !stop) { |
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.
@Mqxx oh i missed this part. I believe this is not correct since it also disables block interactions (like crafting table, buttons!), you are free to help implement this fix in github.com/zardoy/mineflayer-mouse
PR Type
Bug fix
Description
Fixed block interaction logic for adventure mode.
Adjusted conditions for
cursorBlockDiggable
assignment.Prevented block placement in adventure mode.
Changes walkthrough 📝
worldInteractions.ts
Refine block interaction and placement logic
src/worldInteractions.ts
cursorBlockDiggable
assignment.Summary by CodeRabbit