Skip to content

RealisticSound Try#551

Draft
Charpyy wants to merge 28 commits intoCubed-Development:nextfrom
Charpyy:next
Draft

RealisticSound Try#551
Charpyy wants to merge 28 commits intoCubed-Development:nextfrom
Charpyy:next

Conversation

@Charpyy
Copy link
Copy Markdown

@Charpyy Charpyy commented Dec 6, 2024

📝 Description

adds: 2 handlers | 2 packetMessage | 2 classes
edit: WeaponFireAspect when player shoot, and MWC to add packet, handler

Note: im sorry i didnt make any description on my commit since most of the time i didnt know how the game work
and so i wasnt sure of what i was trying to make, but its pretty easy to understand now because its clear for me:

First: you got the WeaponFireAspect, when a player shoot it send a packet to the server with some details (origin, type of sound, silencer or no, world id), after that, server check who is in the same world to send a packet to client and play the sound with the class ClientSoundPlayer and calculate the volume of the sound using the distance between player and origin of the sound after that we use minecraft existing function to playDelayed sound to the player
Most important commit are from december 6th

🎯 Goals

The aim is for players to hear the sound of weapons from further away and with a delay depending on their distance from the source of the sound.

  • Weapon with silencer can be heard up to 100 block and without silencer 400 block
  • We have realistic delay calculated from distance

❌ Non Goals

Using different sound depend on distance, because that isnt realistic

🚦 Testing

Launch: - Server - OfcClient - Client to get 2 clients and 1 server, go at 200 block with gun, shoot with and without silencer
and see the delay and the sound

⏮️ Backwards Compatibility

I coded this on the 1.7 version of the mod so yeah its compatible with new and older version (i guess)

discord link of the video
https://cdn.discordapp.com/attachments/850422558691164201/1314567980193021952/shoottest.mp4?ex=67543e55&is=6752ecd5&hm=9d5c7350414809653e755c344e67468d01835074405f0bdd518a5d16a9c5ce81&

📚 Related Issues & Documents

Nothing to say here

🖼️ Screenshots/Recordings

📖 Added to documentation?

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

😄 [optional] What gif best describes this PR or how it makes you feel?

After spending almost 50 hours on that shit, i want to kill myself and and the guy who created gradle but everything fine now because it work ! yeay

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 6, 2024

Warning

Rate limit exceeded

@Desoroxxx has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 13 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between c41ee0c and 3c905e5.

📒 Files selected for processing (7)
  • src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundClientHandler.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/messages/RealisticSoundClientMessage.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/messages/RealisticSoundMessage.java (1 hunks)
  • src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java (8 hunks)
  • src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java (1 hunks)
  • src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java (1 hunks)
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces modifications to several files in a Minecraft mod project, primarily focusing on sound handling functionalities. Key changes include the addition of new classes and message handlers for realistic sound effects, updates to the MWC class for message registration, and adjustments to the WeaponFireAspect class to utilize these new sound messages. Additionally, the build.gradle.kts file is updated to reflect a change in the Minecraft session username. Overall, the changes enhance the mod's sound capabilities while maintaining existing structures.

Changes

File Path Change Summary
build.gradle.kts Changed Minecraft session username from "Desoroxxx" to "Chapy". No changes to repositories, dependencies, or tasks.
src/main/java/com/paneedah/mwc/MWC.java Removed two import statements; added message handlers for realistic sound client and server messages.
src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundClientHandler.java Added a new class for handling client-side realistic sound messages with an onMessage method.
src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java Added a new class for handling server-side realistic sound messages with an onMessage method.
src/main/java/com/paneedah/mwc/network/messages/RealisticSoundClientMessage.java Added a new message class for client-side sound messages, including serialization methods and fields for sound data.
src/main/java/com/paneedah/mwc/network/messages/RealisticSoundMessage.java Added a new message class for server-side sound messages, including serialization methods and fields for sound data.
src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java Updated to use RealisticSoundMessage for sound handling during weapon firing, replacing previous local sound logic.
src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java Introduced a new class for client-side sound playback with a method for playing sounds based on distance.
src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java Added a new class to manage realistic sound events, including methods for volume adjustment based on distance.

Possibly related PRs

  • Overhaul SIG SLX Silencer #531: The changes in this PR involve modifications to the Suppressor556x39 class, which may relate to sound handling in the context of weapon attachments, similar to the sound functionalities introduced in the main PR.

Suggested labels

Enhancement

Suggested reviewers

  • Desoroxxx

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Copy Markdown
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: 9

🧹 Outside diff range and nitpick comments (8)
src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (1)

26-32: Avoid unnecessary task scheduling inside an already scheduled task

You are scheduling a new task inside an existing scheduled task, which is unnecessary since the outer task runs on the main server thread. This can be simplified by sending the message directly within the current task.

Apply this diff to simplify the code:

-                playerMP.getServerWorld().addScheduledTask(() -> {
                     CHANNEL.sendTo(
                         new RealisticSoundClientMessage(sound.getSound(), message.getPos(), sound.getVolumeIn(), sound.getPitchIn(), distance),
                         playerMP
                     );
-                });
src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java (1)

13-13: Method name should follow camelCase convention

The method PlaySoundClient should be renamed to playSoundClient to adhere to Java naming conventions for method names.

Apply this diff to rename the method:

-    public void PlaySoundClient(double distance, SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, float xIn, float yIn, float zIn) {
+    public void playSoundClient(double distance, SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, float xIn, float yIn, float zIn) {
🧰 Tools
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)

[warning] 13-23: ❌ New issue: Excess Number of Function Arguments
PlaySoundClient has 8 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java (1)

28-36: Consider enhancing volume attenuation for realism

The current linear attenuation model may not accurately reflect how sound diminishes over distance in reality. Consider using an inverse square law or exponential attenuation for more realistic sound fading.

Modify the adjustVolumeForDistance method to use an exponential decay:

-        return 1.0 - (distance / maxDistance);
+        return Math.exp(-distance / maxDistance);

This change will make distant sounds fade more realistically.

src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java (5)

289-289: Consider extracting world type ID to a constant.

The world type ID is used directly in the message. Consider extracting it to a named constant for better maintainability.

+ private static final String WORLD_TYPE_ID = "world_type_id";
- CHANNEL.sendToServer(new RealisticSoundMessage(silencerOn, shootSound, player.getPosition(), player.getEntityWorld().getWorldType().getId()));
+ CHANNEL.sendToServer(new RealisticSoundMessage(silencerOn, shootSound, player.getPosition(), WORLD_TYPE_ID));
🧰 Tools
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)

[notice] 289-368: ✅ Getting better: Complex Method
fire decreases in cyclomatic complexity from 26 to 25, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.


300-303: Consider extracting sound message sending logic to a helper method.

The sound message sending logic is duplicated between regular shots and end-of-shoot sounds. Consider extracting it to a helper method.

+ private void sendSoundMessage(EntityLivingBase player, boolean silencerOn, SoundEvent sound) {
+     if (!FMLCommonHandler.instance().getSide().isServer()) {
+         CHANNEL.sendToServer(new RealisticSoundMessage(silencerOn, sound, 
+             player.getPosition(), player.getEntityWorld().getWorldType().getId()));
+     }
+ }

- if(currentAmmo == 1 && weapon.getEndOfShootSound() != null && !FMLCommonHandler.instance().getSide().isServer()) {
-     CHANNEL.sendToServer(new RealisticSoundMessage(silencerOn,weapon.getEndOfShootSound(), 
-         player.getPosition(), player.getEntityWorld().getWorldType().getId()));
+ if(currentAmmo == 1 && weapon.getEndOfShootSound() != null) {
+     sendSoundMessage(player, silencerOn, weapon.getEndOfShootSound());

Line range hint 353-372: Remove commented out code.

Large blocks of commented code should be removed as they add unnecessary noise to the codebase. If this code is needed for reference, it should be documented in the commit history or documentation.


Line range hint 423-434: Remove commented out code block.

This block of commented code should be removed. If the functionality is needed in the future, it can be retrieved from version control.


Line range hint 289-303: Sound system architecture looks good.

The transition from client-side to server-side sound handling with distance-based playback is a good architectural choice. It allows for:

  1. Centralized sound management
  2. Better synchronization across clients
  3. More realistic sound propagation based on distance

Consider documenting the sound propagation mechanics (distance calculations, delay factors) in the class-level documentation for future maintenance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8636f60 and a0babf9.

📒 Files selected for processing (9)
  • build.gradle.kts (1 hunks)
  • src/main/java/com/paneedah/mwc/MWC.java (2 hunks)
  • src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundClientHandler.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/messages/RealisticSoundClientMessage.java (1 hunks)
  • src/main/java/com/paneedah/mwc/network/messages/RealisticSoundMessage.java (1 hunks)
  • src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java (8 hunks)
  • src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java (1 hunks)
  • src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeScene Cloud Delta Analysis (next)
src/main/java/com/paneedah/weaponlib/WeaponFireAspect.java

[notice] 289-368: ✅ Getting better: Complex Method
fire decreases in cyclomatic complexity from 26 to 25, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.


[notice] 289-368: ✅ Getting better: Complex Method
fire decreases in cyclomatic complexity from 26 to 25, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java

[warning] 13-23: ❌ New issue: Excess Number of Function Arguments
PlaySoundClient has 8 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

🔇 Additional comments (4)
src/main/java/com/paneedah/mwc/network/messages/RealisticSoundClientMessage.java (1)

13-22: LGTM! Class structure is well-organized.

The use of Lombok annotations effectively reduces boilerplate code. The fields are appropriately chosen for sound message handling.

build.gradle.kts (1)

26-26: LGTM! Configuration update.

The username change is straightforward and doesn't impact functionality.

src/main/java/com/paneedah/mwc/MWC.java (1)

126-126: LGTM! Message handlers are properly registered.

The registration of RealisticSound handlers follows the established pattern:

  • Client handler with negative ID (-17)
  • Server handler with positive ID (14)

Let's verify there are no ID conflicts:

Also applies to: 141-141

✅ Verification successful

Message handler IDs are unique and properly segregated

The verification confirms that:

  • All client-side handlers use negative IDs (-1 to -17)
  • All server-side handlers use positive IDs (1 to 14)
  • There are no duplicate IDs
  • The RealisticSound handlers follow this pattern with -17 (client) and 14 (server)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate message handler IDs
# Expect: No duplicate IDs in the output

rg -A 1 'CHANNEL\.registerMessage.*class,\s*[+-]?\d+,\s*Side\.' | grep -o '[+-]\d\+' | sort -n | uniq -d

Length of output: 106


Script:

#!/bin/bash
# Let's try a more flexible pattern to find message registrations
rg -A 1 'CHANNEL\.registerMessage.*Side\.' --no-heading

Length of output: 4953

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

7-7: LGTM: Import addition aligns with sound enhancement objectives.

double distance = Math.sqrt(message.getPos().distanceSq(playerInWorld.getPosition()));
RealisticSound sound = RealisticSound.createSound(message.getSilencer(), message.getSound(), message.getPos(), playerInWorld.getPosition());
if (sound.getVolumeIn() > 0.0F) {
EntityPlayerMP playerMP = (EntityPlayerMP) playerInWorld;

This comment was marked as off-topic.

Comment thread src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java
Comment thread src/main/java/com/paneedah/weaponlib/sound/ClientSoundPlayer.java Outdated
Comment thread build.gradle.kts
@strubium strubium requested a review from Desoroxxx December 6, 2024 18:20
Copy link
Copy Markdown
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: 1

🧹 Outside diff range and nitpick comments (1)
src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (1)

25-26: Add null checks and optimize distance calculation.

The current implementation lacks null checks and uses a potentially expensive square root operation.

Consider these improvements:

-                double distance = Math.sqrt(message.getPos().distanceSq(playerInWorld.getPosition()));
-                RealisticSound sound = RealisticSound.createSound(message.getSilencer(), message.getSound(), message.getPos(), playerInWorld.getPosition());
+                if (message.getPos() != null && playerInWorld.getPosition() != null) {
+                    // Use distanceSq for volume checks to avoid sqrt
+                    double distanceSq = message.getPos().distanceSq(playerInWorld.getPosition());
+                    // Only calculate actual distance if needed for sound delay
+                    double distance = Math.sqrt(distanceSq);
+                    RealisticSound sound = RealisticSound.createSound(message.getSilencer(), message.getSound(), message.getPos(), playerInWorld.getPosition());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a0babf9 and c41ee0c.

📒 Files selected for processing (2)
  • src/main/java/com/paneedah/mwc/MWC.java (2 hunks)
  • src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/paneedah/mwc/MWC.java
🔇 Additional comments (4)
src/main/java/com/paneedah/mwc/network/handlers/RealisticSoundHandler.java (4)

1-16: LGTM! Imports are clean and appropriate.

All necessary imports are present and properly organized.


17-17: LGTM! Class declaration follows Forge's networking patterns.

The class properly implements IMessageHandler with correct generic type parameters.


28-36: Previous instance check implementation is correct.

The code already implements the safe casting pattern that was suggested in the previous review.


31-34: Verify sound distance limits.

According to the PR objectives, weapons with silencers should be heard up to 100 blocks away, while those without can be heard up to 400 blocks.

Let's verify the distance limits in the codebase:

✅ Verification successful

Based on the search results, I found the relevant distance limits defined in RealisticSound.java:

private static final double MAX_DISTANCE = 400D;
private static final double MAX_DISTANCE_SILENCER = 100D;

The code shows that the distance limits are correctly implemented:

  • Weapons with silencers have a max sound distance of 100 blocks
  • Weapons without silencers have a max sound distance of 400 blocks

The volume is adjusted based on these limits using the adjustVolumeForDistance() method, which scales the volume linearly from 1.0 at distance 0 to 0.0 at the max distance.

The distance limits match the PR objectives exactly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for distance-related constants in RealisticSound class
ast-grep --pattern 'class RealisticSound {
  $$$
  private static final $_ MAX_DISTANCE = $_;
  $$$
}'

Length of output: 104


Script:

#!/bin/bash
# Let's search for distance-related constants and configurations more broadly
rg -i "distance|range" --type java -A 5 -B 5

Length of output: 68422

Comment on lines +12 to +13
@SideOnly(Side.CLIENT)
public void PlaySoundClient(double distance, SoundEvent soundIn, SoundCategory categoryIn, float volumeIn, float pitchIn, float xIn, float yIn, float zIn) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be camelCase

Copy link
Copy Markdown
Member

@Desoroxxx Desoroxxx left a comment

Choose a reason for hiding this comment

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

Pretty good for a first PR, this might look like a lot but it ain't a lot is suggestions that will be merged by me and the rest is renames and minor changes.

But there is one big change that I would like to see, it's time for erm actually
☝🏻🤓
So sounds, they travel far, like real far.
I searched a bit on the internet, did a lil math and ball parkin' and I found realistic numbers for
each type of weapons.
(Yes, silencers really work, like really really well)

Type Range (Meters) Silenced Range (Meters)
HANDGUN 500 - 1600 50 - 100
LONG_GUN 800 - 1600 100 - 200
RIFLE 800 - 1600 100 - 200
SHOTGUN 800 - 3200 100 - 200
CARBINE 800 - 1600 100 - 200
ASSAULT_RIFLE 800 - 1600 100 - 200
BATTLE_RIFLE 800 - 1600 100 - 200
SNIPER_RIFLE 800 - 1600 100 - 200
MACHINE_GUN 1200 - 2400 100 - 200
SUBMACHINE_GUN 500 - 1200 50 - 100

Now when playing a sound, the range should be a random number between RANGE MAX - RANGE MIN.
This might get too crazy on server so include a new config which is a multiplier for the range that should be applied on the random number found.


@Override
public IMessage onMessage(RealisticSoundClientMessage message, MessageContext ctx) {
Minecraft.getMinecraft().addScheduledTask(() -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use NetworkUtil (See other place in the project it was used with ctrl + shift + f in IDEA and search NetworkUtil)

@Override
public IMessage onMessage(RealisticSoundClientMessage message, MessageContext ctx) {
Minecraft.getMinecraft().addScheduledTask(() -> {
Minecraft minecraft = Minecraft.getMinecraft();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use the constant MC with a static import (See other place in the project it was used with ctrl + shift + f in IDEA and search MC)

Comment on lines +18 to +19
ClientSoundPlayer csp = new ClientSoundPlayer();
csp.PlaySoundClient(message.getDistance(), message.getSound(), SoundCategory.PLAYERS, message.getVolume(), message.getPitch(), (float)message.getPos().getX(), (float)message.getPos().getY(), (float)message.getPos().getZ());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In this case using a local variable is useless as you aren't using it twice, simply do new ClientSoundPlayer.PlaySoundClient.

Although for better performance get rid of ClientSoundPlayer and simply put the code here since it's the only usage

import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class RealisticSoundClientHandler implements IMessageHandler<RealisticSoundClientMessage, IMessage> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be RealisticSoundClientMessageHandler, also should be final

Comment on lines +23 to +25
double distance = Math.sqrt(playercoord.distanceSq(origin));
float volume = (float) adjustVolumeForDistance(silencer, distance);
return new RealisticSound(soundIn, volume, 1.0F);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

local variables are unecessary here

Comment thread src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java Outdated
Comment thread src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java Outdated
Comment thread src/main/java/com/paneedah/weaponlib/sound/RealisticSound.java Outdated
Comment on lines +39 to +49
public SoundEvent getSound() {
return sound;
}

public float getVolumeIn() {
return volumeIn;
}

public float getPitchIn() {
return pitchIn;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use @Getter on these fields

@Desoroxxx Desoroxxx marked this pull request as draft November 24, 2025 10:59
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.

3 participants