Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.12.2] Can't figure out how to get playSound to play in multiplayer

Featured Replies

Posted

Hello, I've been trying all different approaches to try to get playSound to work in multiplayer. It does play in singleplayer. Anyone know what I am doing wrong?

 

Spoiler
 
 
 
Spoiler

package com.papavinny.swordfight;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

@EventBusSubscriber
public class Dodge{
    
    private static int dodgeLength = 0;
    private static int invulnerablityPeriod = 10;
    private static boolean wasHolding = false;
    private static EntityPlayer entity;

     @SubscribeEvent
        public static void Dodges(ClientTickEvent event) {
        entity = Minecraft.getMinecraft().player; // <---- could be the problem?
         
         if(Minecraft.getMinecraft().inGameHasFocus && GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint)) 
         {
            if(         //Dodge back.
                     GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindBack)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindForward)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindRight)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindLeft)
                    && dodgeLength==0
                    && !wasHolding
              )
            {
                Stamina.staminaDeplete(3);
                dodgeLength = 30;
                playWoosh();

            }
         
            if(        //TODO: Dodge right. 
                     !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindBack)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindForward)
                    && GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindRight)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindLeft)
                    && dodgeLength==0
                    && !wasHolding
              )
            {
                Stamina.staminaDeplete(3);

            }
            
            if(         //TODO: Dodge left.
                     !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindBack)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindForward)
                    && !GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindRight)
                    && GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindLeft)
                    && dodgeLength==0
                    && !wasHolding
              )
            
          {
            Stamina.staminaDeplete(3);
    
          }
         }
            
            if(Minecraft.getMinecraft().inGameHasFocus && GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindSprint))
            {
                wasHolding = true;
            }else wasHolding = false;
            
            if(dodgeLength > 0) {
                
                dodgeLength--;
            }

     } 
     
     public static void playWoosh()
     {

            entity.world.playSound(entity,entity.getPosition().getX(), entity.getPosition().getY(), entity.getPosition().getZ(),
                    SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, SoundCategory.MASTER, 10.0f, 1.0f);
     }
     
    
}

 

The playSound is in playWoosh, I'm thinking the value of the variable "entity" is causing the problem.

Edited by PapaVinny

  • Author
 
 
 
2 minutes ago, diesieben07 said:

 

What even? Why?

 


LOL im dying. I'm new to modding, and somewhat to java. I did that because if I make EntityPlayer = (the player) a field, the game would crash unless the declaration was in the TickEvent I encased what's within the ClientTickEvent in if(event.phase ==Phase.START). When I type KeyBinding.(Anything) I don't get the option for isKeyDown. Guessing it has something to do with that # but even when I type that it's a syntax error, same with the Tickevent#Phase, never seen that before

 


 

  • Author

gotya, is that why the sound is not playing on the server btw? cuz my class isn't instantiated or am I supposed to send playSound to the server ie packets. Think I'm "Reaching across logical sides" from what I read in the forge docs

Edited by PapaVinny

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.