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.

Featured Replies

Posted

Title says a lot. Also, the  "System.out.println("PlayerTickEvent Working");" does not print every tick. Here's my code:

 

    @SubscribeEvent
    public void entitiesInRadius(PlayerTickEvent event)
    {
         EntityPlayer player = event.player;
        
         int monsterCount = player.world.getEntitiesWithinAABB(EntityMob.class, new AxisAlignedBB(player.posX - 16, player.posY - 8, player.posZ - 16, player.posX + 16, player.posY + 8, player.posZ + 16)).size();
         boolean isplayerinrange = false;
         
         System.out.println("PlayerTickEvent Working");
         if(monsterCount > 0) 
         {
             System.out.println("isplayerinrange is true");
             isplayerinrange = true;
             
             if(isplayerinrange = true) 
                {    
                 System.out.println("Battle Music Initiated");
                player.playSound(ModSounds.BATTLE_MUSIC, 1, 1);
                }
          }
         
         else
         {
             isplayerinrange = false;
         }
         
    }

Edited by Plgue

  • Author
1 hour ago, Plaigon said:

Hi, you can maybe try using the LivingSetAttackTargetEvent ?

So I updated my code:

 

    @SubscribeEvent
    public void livingSetAttacktargetEvent(LivingSetAttackTargetEvent event)
    {
        EntityLivingBase player = event.getTarget();
        
        System.out.println("Set attack target");
        if(event.getTarget() == player)
        {
            System.out.println("Battle Music Play");
            player.playSound(ModSounds.BATTLE_MUSIC, 100, 1);
        }
        
        else
        {
            
        } 
    }

 

It's still a work in progress, but no matter what I do I can't seem to get the event to start my method. The System.out.println's don't even go off, I'm really stumped here. 

 

Edit: This is my common proxy, just in case you wanna see it:

 

public class CommonProxy {


    public void preInit(FMLPreInitializationEvent e) 
    {
        ModItems.init();
        ModItems.register();;
        
        ModEntities.init();

    }

    public void init(FMLInitializationEvent e) 
    {
        MinecraftForge.EVENT_BUS.register(ModSounds.class);
        MinecraftForge.EVENT_BUS.register(EventHandler.class);
    }

    public void postInit(FMLPostInitializationEvent e) 
    {
        
    }
}

Edited by Plgue

  • Author
1 hour ago, Plaigon said:

Hi, you can maybe try using the LivingSetAttackTargetEvent ?

Also, thanks for this idea! This event does exactly what I need it to do.

  • Author
7 minutes ago, diesieben07 said:

Look at this very closely. Can this ever be false? No, it cannot.

Still not the issue :/

  • Author
1 hour ago, Plgue said:

player.playSound(ModSounds.BATTLE_MUSIC, 100, 1);

Isn't that what i'm doing here? I'm playing the sound to the target.

  • Author

I do understand it to an extent, but I don't know how I would use it here. And sorry if I sound ignorant or like an idiot, I'm still learning :/

Use Eclipse to look into source code of vanilla entities . See what they do to make sounds, especially from server side decisions.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

  • Author

So after everything I've seen in this thread, this is what I came up with:

 

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void playBattleSong(LivingSetAttackTargetEvent event)
    {

          EntityLivingBase entity = event.getEntityLiving().getAttackingEntity();

          entity.playSound(ModSounds.BATTLE_MUSIC, 75, 1);
    }

 

It still does not play the sound.

How does EventPriority.HIGHEST solve the client-vs-server issue?

I'll give you one hint:

It does fuck all about it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author
38 minutes ago, Draco18s said:

How does EventPriority.HIGHEST solve the client-vs-server issue?

I'll give you one hint:

It does fuck all about it.

The priority was just me messing around

  • Author
7 hours ago, diesieben07 said:

Don't "just mess around". Read the documentation about playing sounds that I linked.

But this code should work right? I'm playing a sound from an entity, vanilla Minecraft does the same thing.

So I don't know why it does not work.

Edited by Plgue

  • Author
Just now, diesieben07 said:

It does not work because you are calling a method that is designed to be called from both sides only on the server.

You would know this if you had read the documentation that I linked.

So in this case I should be using "World.playsound" ?

  • Author
Just now, diesieben07 said:

That is one solution, yes.

Again i'm really sorry if I sound like an idiot, but I don't know how to get the sound to play using "World.playsound()"

Because I don't know how to get my method non static, I did not set it as static though.

 

  • Author
1 minute ago, diesieben07 said:

Please clarify what you are talking about. Which method? Why do you want it to be non-static? Do you even know what that means?

Never mind, this is what i'm currently using

entity.world.playSound(null, entity.chunkCoordX, entity.chunkCoordY, entity.chunkCoordZ, ModSounds.BATTLE_MUSIC, SoundCategory.MUSIC, 100, 1);

But it still does not work

4 hours ago, Plgue said:

Never mind, this is what i'm currently using

entity.world.playSound(null, entity.chunkCoordX, entity.chunkCoordY, entity.chunkCoordZ, ModSounds.BATTLE_MUSIC, SoundCategory.MUSIC, 100, 1);

But it still does not work

It's not working because you are passing chunk coordinates into a method that takes world coordinates. You want Entity#posXEntity#posY & Entity#posZ.

  • Author
8 hours ago, diesieben07 said:

Are you sure the code is executed?

Sorry for the late response, but yeah it's being executed 

  • Author
3 hours ago, Leviathan143 said:

It's not working because you are passing chunk coordinates into a method that takes world coordinates. You want Entity#posXEntity#posY & Entity#posZ.

Did this and it's still not working

 

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.