#Sound help?

90 messages · Page 1 of 1 (latest)

latent shard
#

My sound isnt triggering:
if (!attacker.getWorld().isClient) {
attacker.getWorld().playSound(
null, // null = all nearby players hear it
attacker.getBlockPos(), // position of sound
ScytheSound.SCYTHE_SLASH, // your custom sound
SoundCategory.PLAYERS, // category
1.0F, // volume
1.0F // pitch
);

dusty fox
#

!!code

tranquil ospreyBOT
#

You can use codeblocks in discord as shown below:
```java
code
```

You can also specify the syntax highlighting to use by specifying the language after the last backtick (`) on the top.

latent shard
#
            attacker.getWorld().playSound(
                    null,                                      // null = all nearby players hear it
                    attacker.getBlockPos(),                    // position of sound
                    ScytheSound.SCYTHE_SLASH,                  // your custom sound
                    SoundCategory.PLAYERS,                     // category
                    1.0F,                                      // volume
                    1.0F                                       // pitch
            );
#

sorry about that didnt know how to do that lol

dusty fox
#

!!llm

tranquil ospreyBOT
#

Whilst LLMs (Large Language Models) like ChatGPT and Gemini are impressive tools, **they are not recommended for first-time Fabric mod developers due to their inconsistency and potential for generating inaccurate code. **

LLMs may generate incorrect code that:

  • Targets the wrong Minecraft version, leading to outdated or incompatible features.
  • Uses incorrect mappings, causing errors or unexpected behavior.
  • Is designed for the wrong loader (NeoForge vs. Fabric), resulting in incompatibility.
  • Relies on non-existent Fabric API modules, creating code that references features that don't exist (called LLM hallucinations)

It's crucial to remember that LLMs should be seen as problem-solving aids, not code-generating machines. The output they provide often requires significant modification and understanding of Java before it can be implemented as a functional mod.

Therefore, learning Java is an absolute necessity before attempting to use any LLM-generated code in your mod. Knowing how the generated code works is key to using it effectively and fixing any problems that may arise.

dusty fox
#

probably the passing null as the first argument in playSound() is causing no one to hear anything

devout ice
latent shard
#

originally my code was attacker.playSound(SCYTHE_SLASH,1.0F,1.0F);

latent shard
#

the other code works but not the sound

latent shard
dusty fox
devout ice
#

they're asking you to pass in an actual entity instead of null but that might not be the issue

dusty fox
#

probably an entity list

#

not sure

latent shard
#

I can send the full class if you want

#

if its helpful*

devout ice
devout ice
latent shard
#

im going to leave out the imports

#

    public scytheItem(Settings settings) {
        super(settings);
    }

    @Override
    public void postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) {
        Pvp_mod.LOGGER.info("TEST SUCCESS POST DAMAGE SCYTHE");
        Vec3d direction = attacker.getRotationVec(1.0F);
        Vec3d knockback = direction.multiply(-1);
        knockback = new Vec3d(knockback.x, 0, knockback.z);
        Vec3d movement = target.getVelocity();
        movement = movement.add(knockback);
        target.setVelocity(movement);
        if (!attacker.getWorld().isClient) {
            attacker.playSound(SCYTHE_SLASH,1.0F,1.0F);
            if (target instanceof ServerPlayerEntity serverPlayerEntity) {
                serverPlayerEntity.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(serverPlayerEntity));
            }

        }
    }

}```
devout ice
latent shard
devout ice
latent shard
#

I replaced it with attacker.playSound(SoundEvents.BLOCK_IRON_BREAK,1.0F,1.0F);

#

still didnt work

#

is there another way to implement this

devout ice
latent shard
#

that worked thanks!

#

at least for vanilla sound

#

So close yet so far....

#

formatted like this right? if (!attacker.getWorld().isClient && attacker.getWorld() instanceof ServerWorld serverWorld) { serverWorld.playSound( null, // Null = send to all nearby players attacker.getBlockPos(), // Position to play sound at ScytheSound.SCYTHE_SLASH, // Sound to play (can be your custom sound) SoundCategory.PLAYERS, // Affects volume slider 1.0f, // Volume 1.0f // Pitch ); }

devout ice
#

there's plenty of overloads so use whatever works for you

latent shard
#

how do I format the custom sound SCYTHE_SLASH

#

because i tested both SCYTHE_SLASH and scytheslash.SCYTHE_SLASH

devout ice
#

you can also just cast world to ServerWorld without using an instanceof check since postHit always runs on the server

devout ice
latent shard
#
    public static final SoundEvent SCYTHE_SLASH = registerSoundEvent("scythe_slash");


    private static SoundEvent registerSoundEvent(String name) {
        Identifier id = Identifier.of(Pvp_mod.MOD_ID, name);
        return Registry.register(Registries.SOUND_EVENT, id, SoundEvent.of(id));
    }


    public static void registerSounds() {
        Pvp_mod.LOGGER.info("Registering Mod Sounds " + Pvp_mod.MOD_ID);

    }
}```
#

idk why It doesnt work the sound shows up in the game

devout ice
#

so vanilla sounds play but yours does not, correct?

#

because i tested your exact structure and it works fine on my end with custom sounds

cyan igloo
#

An issue with the registering of your sound perhaps or is your sound not in the correct format?

cyan igloo
latent shard
cyan igloo
#

https://convertio.co/mp3-ogg/

Change channel to mono and it might work. Sound should be singular channel. This site can do it or you can even do it in audacity

latent shard
#

ok thanks i’m not home rn but ill try when I get there

tulip zealot
latent shard
#

Im crashing out

#

I changed it to mono and it still doesnt work wtf

dusty fox
devout ice
latent shard
#

I can do /playsound and it works fine

#

but the actuall code that plays the custom sound on hit doesnt work for CUSTOM sounds

#

but does for vanilla

#

im double checking the mono file

#

it doesnt work 😭

finite citrus
# latent shard it doesnt work 😭

I just ran into this exact same issue, so if you're still having issues what I finally found worked was
ENTITY.getWorld().playSound(null, ENTITY.getBlockPos(), SOUND, SOUNDCATEGORY, 1f, 1f);

latent shard
#

i’ll give that a try

#

is there some sort of import or override I need to do to define ENTITY

finite citrus
#

Entity is just whatever entity you want playing the sound

#

I just left the standins in caps

latent shard
#

i’m a lil bit new so idk if i’m being dumb

finite citrus
#

Like the exact code I have is
attacker.getWorld().playSound(null, target.getBlockPos(), Sounds.VINE_BOOM, SoundCategory.MASTER, 1f, 1f);

latent shard
#

thanks that’s helpful I thought entity was a predefined thing 🤦

finite citrus
#

All good

#

I probably could have been more specific

finite citrus
#

I've been working on this on and off for like 3 weeks and it's my first time really even using java

tulip zealot
# latent shard

Entity#getWorld can be replaced with ServerWorld because serverWorld is a world too

#

Then you can avoid redundant getWorld calls because they should return the same world

latent shard
#

also i can’t tell if my registry file isn’t working or if it’s my json

finite citrus
#

The way I tested it was playing vanilla sounds

#

Like SoundEvents.BLOCK_ANVIL_FALL

latent shard
#

oh i got vanilla events down i just cant add custom sounds

#

Do i need to reformat the Identifier code because im doing this on 1.21.8?

finite citrus
#
  "vine_boom": {
    "subtitle": "sound.socwars.vine_boom",
    "sounds": [
      "socwars:vine_boom"
    ]
  }
}```
```public interface Sounds {
    static void initialise() {}

    private static SoundEvent register(String id) {
        return Registry.register(Registries.SOUND_EVENT, Identifier.of(SocWars.MOD_ID, id), SoundEvent.of(Identifier.of(SocWars.MOD_ID, id)));
    }

    SoundEvent VINE_BOOM = register("vine_boom");
}```
#

Not sure since this is how I'm doing it on 1.21.8 and it looks like exactly the same thing you have

latent shard
#

got it to work sound file can’t be caps…

#

stupid mojang

knotty cloak
#

oh do i have to convert it to an ogg?