Skip to content
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

Add some new configs #530

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open

Add some new configs #530

wants to merge 1 commit into from

Conversation

strubium
Copy link
Contributor

📝 Description

Adds some new configs: bulletHitParticleMult and enableStatusMessages

Why?

  • enableStatusMessages: It should be possible to disable status messages like the ammo counter
  • bulletHitParticleMult: Not sure about this one, it was a TODO in MWC.java

🎯 Goals

Add some new configs for modpack makers (Ex: me for ValkReno)

❌ Non Goals

Break the mod

🚦 Testing

Yes, also bulletHitParticleMult cant be changed in-game

⏮️ Backwards Compatibility

1.12.2

📚 Related Issues & Documents

N/a

📖 Added to documentation?

  • 📜 README.md
  • 📑 Documentation
  • 📓 Javadoc
  • 🍕 Comments
  • 🙅 No documentation needed

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications across several classes related to bullet hit particle management and status messaging in the game. A static variable for bullet hit particle multiplier was removed from the MWC class, while the configuration for this multiplier has been shifted to the ModernConfigManager. Additionally, the handling of status messages for fire mode changes and zoom adjustments in the Weapon class has been refined to depend on a new configuration setting. The WeaponFireAspect class has also been updated to conditionally send messages based on the new configuration.

Changes

File Path Change Summary
src/main/java/com/paneedah/mwc/MWC.java Removed static variable bulletHitParticleMult.
src/main/java/com/paneedah/mwc/network/handlers/BlockHitMessageHandler.java Removed import for MWC, added import for ModernConfigManager. Updated loop to use ModernConfigManager.bulletHitParticleMult.
src/main/java/com/paneedah/weaponlib/Weapon.java Added conditional checks for ModernConfigManager.enableStatusMessages in methods handling fire mode and zoom adjustments.
src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java Added conditional check for ModernConfigManager.enableStatusMessages in cannotFire method.
src/main/java/com/paneedah/weaponlib/config/ModernConfigManager.java Added new properties: public static boolean enableStatusMessages and public static int bulletHitParticleMult.

Sequence Diagram(s)

sequenceDiagram
    participant Player
    participant Weapon
    participant ModernConfigManager
    participant WeaponFireAspect

    Player->>Weapon: Change fire mode
    alt Status messages enabled
        Weapon->>Player: Send fire mode change message
    end

    Player->>Weapon: Adjust zoom
    alt Status messages enabled
        Weapon->>Player: Send zoom adjustment message
    end

    Player->>WeaponFireAspect: Attempt to fire
    alt No ammo
        WeaponFireAspect->>Player: Send no ammo message
    end
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (5)
src/main/java/com/paneedah/weaponlib/config/ModernConfigManager.java (1)

143-145: Improve the configuration comment for clarity.

While the implementation is correct, the comment could be more descriptive to better explain the purpose and impact of this setting.

Consider updating the comment to be more specific:

-    @ConfigSync(category = CATEGORY_GAMEPLAY, comment = "How much particles should be spawned by a bullet.")
+    @ConfigSync(category = CATEGORY_GAMEPLAY, comment = "Multiplier for the number of particles spawned when a bullet hits a surface (range: 1-10).")
src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java (3)

213-222: LGTM! Consider fixing the indentation.

The status message configuration is correctly implemented, maintaining the sound feedback as a separate concern. The indentation of the closing brace could be improved for better readability.

-            }
+        }

Line range hint 1-654: Implementation maintains good separation of concerns.

The changes effectively integrate the status message configuration while:

  • Maintaining backward compatibility
  • Preserving core weapon functionality
  • Keeping proper error handling
  • Separating visual feedback from gameplay mechanics

Missing implementation of bulletHitParticleMult in WeaponFireAspect.java.
The configuration bulletHitParticleMult is defined and used elsewhere but is not implemented in WeaponFireAspect.java as intended. Please ensure it is integrated correctly in this file.

🔗 Analysis chain

Line range hint 8-8: Verify implementation of bulletHitParticleMult config.

The PR objectives mention adding bulletHitParticleMult config, but it's not utilized in this file. Please verify if this configuration should be implemented here or in another class.


shell
#!/bin/bash

Find the definition of bulletHitParticleMult

rg "bulletHitParticleMult\s*="

Check usage of bulletHitParticleMult in WeaponFireAspect.java

rg "bulletHitParticleMult" src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for bulletHitParticleMult usage across the codebase
echo "Searching for bulletHitParticleMult usage..."
rg -l "bulletHitParticleMult"

# Search for particle-related code in ModernConfigManager
echo "Checking ModernConfigManager for particle configurations..."
rg -A 5 "class ModernConfigManager"

Length of output: 1058


Script:

Length of output: 98


Script:

#!/bin/bash
# Locate the definition of bulletHitParticleMult
rg "bulletHitParticleMult\s*="

# Find all occurrences of bulletHitParticleMult in the codebase
rg "bulletHitParticleMult"

Length of output: 453

src/main/java/com/paneedah/weaponlib/Weapon.java (1)

1398-1414: Consider extracting status message logic to reduce nesting.

The conditional logic for sending status messages is valid but could be extracted to improve readability.

Consider extracting the status message logic into a helper method:

-        if (ModernConfigManager.enableStatusMessages){
-            String message;
-            if (result == 1) {
-                message = I18n.format("gui.firearmMode.semi");
-            } else if (result == Integer.MAX_VALUE) {
-                message = I18n.format("gui.firearmMode.auto");
-            } else {
-                message = I18n.format("gui.firearmMode.burst");
-            }
-            LOGGER.debug("Changed fire mode of {} to {}", instance, result);
-
-            if (instance.getPlayer() instanceof EntityPlayer) {
-                ((EntityPlayer) instance.getPlayer()).sendStatusMessage(new TextComponentString(I18n.format("gui.firearmMode", message)), true);
-            }
-        }
+        sendFireModeStatusMessage(instance, result);

// Add helper method:
+    private void sendFireModeStatusMessage(PlayerWeaponInstance instance, int fireMode) {
+        if (!ModernConfigManager.enableStatusMessages || !(instance.getPlayer() instanceof EntityPlayer)) {
+            return;
+        }
+        
+        String message = fireMode == 1 ? I18n.format("gui.firearmMode.semi") 
+            : fireMode == Integer.MAX_VALUE ? I18n.format("gui.firearmMode.auto")
+            : I18n.format("gui.firearmMode.burst");
+            
+        LOGGER.debug("Changed fire mode of {} to {}", instance, fireMode);
+        ((EntityPlayer) instance.getPlayer()).sendStatusMessage(
+            new TextComponentString(I18n.format("gui.firearmMode", message)), true);
+    }
🧰 Tools
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)

[warning] 1398-1414: ❌ New issue: Bumpy Road Ahead
changeFireMode has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fd70ef6 and c2a9651.

📒 Files selected for processing (5)
  • src/main/java/com/paneedah/mwc/MWC.java (0 hunks)
  • src/main/java/com/paneedah/mwc/network/handlers/BlockHitMessageHandler.java (2 hunks)
  • src/main/java/com/paneedah/weaponlib/Weapon.java (3 hunks)
  • src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java (1 hunks)
  • src/main/java/com/paneedah/weaponlib/config/ModernConfigManager.java (2 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/com/paneedah/mwc/MWC.java
🧰 Additional context used
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)
src/main/java/com/paneedah/weaponlib/Weapon.java

[warning] 1398-1414: ❌ New issue: Bumpy Road Ahead
changeFireMode has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.


[warning] 1481-1484: ❌ New issue: Bumpy Road Ahead
incrementZoom has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.


[warning] 1509-1512: ❌ New issue: Bumpy Road Ahead
decrementZoom has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

🔇 Additional comments (2)
src/main/java/com/paneedah/mwc/network/handlers/BlockHitMessageHandler.java (1)

4-4: LGTM: Import change aligns with configuration centralization

The import change correctly reflects the move from hardcoded values to centralized configuration management.

src/main/java/com/paneedah/weaponlib/config/ModernConfigManager.java (1)

95-96: LGTM! Well-structured status messages configuration.

The new configuration option is properly implemented with clear documentation and appropriate categorization.

Comment on lines +1481 to +1484
if (ModernConfigManager.enableStatusMessages){
if (instance.getPlayer() instanceof EntityPlayer) {
((EntityPlayer) instance.getPlayer()).sendStatusMessage(new TextComponentString(I18n.format("gui.currentZoom", Math.round(ratio * 100))), true);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor duplicated zoom status message logic.

The status message logic is duplicated between incrementZoom and decrementZoom methods.

Extract the common logic into a helper method:

// Add helper method:
+    private void sendZoomStatusMessage(PlayerWeaponInstance instance, float ratio) {
+        if (ModernConfigManager.enableStatusMessages && instance.getPlayer() instanceof EntityPlayer) {
+            ((EntityPlayer) instance.getPlayer()).sendStatusMessage(
+                new TextComponentString(I18n.format("gui.currentZoom", Math.round(ratio * 100))), true);
+        }
+    }

// In incrementZoom:
-            if (ModernConfigManager.enableStatusMessages){
-                if (instance.getPlayer() instanceof EntityPlayer) {
-                    ((EntityPlayer) instance.getPlayer()).sendStatusMessage(new TextComponentString(I18n.format("gui.currentZoom", Math.round(ratio * 100))), true);
-                }
-            }
+            sendZoomStatusMessage(instance, ratio);

// In decrementZoom:
-            if(ModernConfigManager.enableStatusMessages){
-                if (instance.getPlayer() instanceof EntityPlayer) {
-                    ((EntityPlayer) instance.getPlayer()).sendStatusMessage(new TextComponentString(I18n.format("gui.currentZoom", Math.round(ratio * 100))), true);
-                }
-            }
+            sendZoomStatusMessage(instance, ratio);

This refactoring will:

  1. Eliminate code duplication
  2. Reduce nested conditional complexity
  3. Make the code more maintainable

Also applies to: 1509-1512

🧰 Tools
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)

[warning] 1481-1484: ❌ New issue: Bumpy Road Ahead
incrementZoom has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Copy link

Qodana for JVM

21603 new problems were found

Inspection name Severity Problems
Unchecked warning 🔶 Warning 10614
Unnecessary 'this' qualifier 🔶 Warning 4012
Deprecated API usage 🔶 Warning 1510
Auto-boxing 🔶 Warning 886
@NotNull/@Nullable problems 🔶 Warning 417
Statement with empty body 🔶 Warning 361
Field can be local 🔶 Warning 313
Lombok @Getter may be used 🔶 Warning 276
Nullability and data flow problems 🔶 Warning 183
Auto-unboxing 🔶 Warning 144
Unused assignment 🔶 Warning 126
Non-constant field with upper-case name 🔶 Warning 114
Constant values 🔶 Warning 108
Redundant local variable 🔶 Warning 101
Javadoc declaration problems 🔶 Warning 95
Lombok @Setter may be used 🔶 Warning 89
Questionable name 🔶 Warning 76
Possibly lossy implicit cast in compound assignment 🔶 Warning 46
Call to 'printStackTrace()' 🔶 Warning 36
Declaration has problems in Javadoc references 🔶 Warning 24
Result of method call ignored 🔶 Warning 18
Deprecated member is still used 🔶 Warning 14
'size() == 0' can be replaced with 'isEmpty()' 🔶 Warning 14
Dynamic regular expression can be replaced by compiled 'Pattern' 🔶 Warning 13
Link specified as plain text 🔶 Warning 13
Method is identical to its super method 🔶 Warning 13
Suspicious collection method call 🔶 Warning 13
'Set' can be replaced with 'EnumSet' 🔶 Warning 11
Integer division in floating-point context 🔶 Warning 9
Mismatched query and update of collection 🔶 Warning 9
Unused import 🔶 Warning 9
'Map' can be replaced with 'EnumMap' 🔶 Warning 8
String concatenation as argument to 'StringBuilder.append()' call 🔶 Warning 8
Class is exposed outside of its visibility scope 🔶 Warning 7
Condition is covered by further condition 🔶 Warning 7
Octal integer 🔶 Warning 7
Suspicious variable/parameter name combination 🔶 Warning 7
Vulnerable imported dependency 🔶 Warning 7
Functional expression can be folded 🔶 Warning 6
Copy of existing static method body 🔶 Warning 6
Unnecessary unary minus 🔶 Warning 6
Unstable API Usage 🔶 Warning 6
Bulk operation can be used instead of iteration 🔶 Warning 6
Catch block may ignore exception 🔶 Warning 5
Redundant type cast 🔶 Warning 5
Variable is assigned to itself 🔶 Warning 5
Stream API call chain can be simplified 🔶 Warning 5
Dangling Javadoc comment 🔶 Warning 4
Duplicate condition 🔶 Warning 4
Inner class may be 'static' 🔶 Warning 4
Manual min/max calculation 🔶 Warning 4
AutoCloseable used without 'try'-with-resources 🔶 Warning 3
Too weak variable type leads to unnecessary cast 🔶 Warning 3
Mismatched read and write of array 🔶 Warning 3
Value passed as parameter never read 🔶 Warning 3
String concatenation in loop 🔶 Warning 3
Local variable used and declared in different 'switch' branches 🔶 Warning 3
Unnecessary 'continue' statement 🔶 Warning 3
'default' not last case in 'switch' 🔶 Warning 2
Call math rounding with 'int' argument 🔶 Warning 2
Redundant operation on empty container 🔶 Warning 2
Redundant usage of unmodifiable collection wrappers 🔶 Warning 2
Method does not call super method 🔶 Warning 2
Caught exception is immediately rethrown 🔶 Warning 1
Redundant 'Collection.addAll()' call 🔶 Warning 1
'static' method declared 'final' 🔶 Warning 1
Call to 'toString()' on array 🔶 Warning 1
Method name same as class name 🔶 Warning 1
String comparison using '==', instead of 'equals()' 🔶 Warning 1
'String.equals()' can be replaced with 'String.isEmpty()' 🔶 Warning 1
Minimum 'switch' branches 🔶 Warning 1
Unary plus 🔶 Warning 1
Commented out code ◽️ Notice 1004
Duplicated code fragment ◽️ Notice 676
Non-distinguishable logging calls ◽️ Notice 33
Non-constant string concatenation as argument to logging call ◽️ Notice 17
'if' statement with identical branches or common parts ◽️ Notice 15
Constant values ◽️ Notice 14
Method can be extracted ◽️ Notice 12
Multiple occurrences of the same expression ◽️ Notice 4
Duplicate branches in 'switch' ◽️ Notice 3
Non-strict inequality '>=' or '<=' can be replaced with '==' ◽️ Notice 1

☁️ View the detailed Qodana report

Detected 18 dependencies

Third-party software list

This page lists the third-party software dependencies used in Modern Warfare Cubed

Dependency Version Licenses
commons-codec 1.10 Apache-2.0
commons-compress 1.8.1 Apache-2.0
commons-io 2.5 Apache-2.0
commons-lang3 3.5 Apache-2.0
commons-logging 1.1.3 Apache-2.0
groovyscript 1.2.0-hotfix1 MIT
httpclient 4.3.3 Apache-2.0
httpcore 4.3.2 Apache-2.0
CC-BY-2.5
icu4j-core-mojang 51.2 IBM-ICU
java-objc-bridge 1.0.0 Apache-2.0
jline 3.5.1 BSD-3-Clause
jopt-simple 5.0.3 MIT
log4j-api 2.17.1 Apache-2.0
log4j-core 2.17.1 Apache-2.0
lombok 1.18.32 BSD-3-CLAUSE-NO-TRADEMARK
MIT
maven-artifact 3.5.3 Apache-2.0
plexus-utils 3.1.0 Apache-2.0
vecmath 1.5.2 GPL-2.0-only
ORACLE-OPENJDK-EXCEPTION-2.0
Contact Qodana team

Contact us at [email protected]

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.

1 participant