Jump to content

wierd sound glitch in smp (not present in ssp or idea)


mrgreaper

Recommended Posts

so heres the issue, when a player holds certain items in my mod a sound is played just once at thier location. In ssp and in idea tests it works perfectly.....however when in multiplayer it trys to play the sound every tick! resulting in a barrage of noise.

 

this is from my event handler class

 @SubscribeEvent
    public void TwistedTickEvent(TickEvent.PlayerTickEvent event) {
        //LogHelper.info("the event is working : TwistedTickEvent");
        ItemStack itemstack = event.player.getCurrentEquippedItem();
        if (itemstack != null) {
            current = (event.player.getDisplayName() + itemstack.getItem().getUnlocalizedName()).toString();
        }//should clear up npe when we try to get the itemstack details from null or nothing ...oops
        else {
            current = (event.player.getDisplayName() + "item.nothing");
        }
        //LogHelper.info("current = : " + current);
        //LogHelper.info("condition test 1 : " + current.equals(old));
        if (!current.equals(old) && !event.player.worldObj.isRemote) {
            //LogHelper.info("should only be seen on one side");
            old = current;
            if (itemstack != null) {//have to check its not null first or BLAM there goes the server when it trys to look up the item
                //i could do these as arrays in the sound.json....that would make adding and removing new sounds much easier....hmmm
                //TODO move these to arrays in sound.json ...possibly


                if (itemstack.getItem() == FluidInfo.orphanTearsBucket && !event.player.worldObj.isRemote){
                    //SoundHandler.onEntityPlay("orphanCry", event.player.worldObj, event.player,1,1);
                    SoundHandler.atWorldplace(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, "orphanCry", 1, 1);//test other sound methods
                }
                if (itemstack.getItem() == ItemInfo.itemDeathOrb && !event.player.worldObj.isRemote){
                    SoundHandler.onEntityPlay("deathOrbStartup", event.player.worldObj, event.player, 1, 1);
                }
                if (itemstack.getItem() == ItemInfo.itemDeadBunny && !event.player.worldObj.isRemote){
                    int ran =ThreadLocalRandom.current().nextInt(5)+1;
                    switch(ran){
                        case 1:
                           SoundHandler.miniSoundPlay("evilvoice-IsItDead",event.player);
                            break;
                        case 2:
                            SoundHandler.miniSoundPlay("evilvoice-BringToLife",event.player);
                            break;
                        case 3:
                            SoundHandler.miniSoundPlay("evilvoice-WeakBringLife",event.player);
                            break;
                        case 4:
                            SoundHandler.miniSoundPlay("evilvoice-NoPower",event.player);
                            break;
                        case 5:
                            SoundHandler.miniSoundPlay("evilvoice-WorldTremble",event.player);
                    }
                }
                if (itemstack.getItem() == ItemInfo.itemLivingBunny && !event.player.worldObj.isRemote){
                    int ran =ThreadLocalRandom.current().nextInt(7)+1;
                    switch(ran){
                        case 1:
                            SoundHandler.miniSoundPlay("evilvoice-Beautiful",event.player);
                            break;
                        case 2:
                            SoundHandler.miniSoundPlay("evilvoice-BeCareful",event.player);
                            break;
                        case 3:
                            SoundHandler.miniSoundPlay("evilvoice-BurnIt",event.player);
                            break;
                        case 4:
                            SoundHandler.miniSoundPlay("evilvoice-LookCreated",event.player);
                            break;
                        case 5:
                            SoundHandler.miniSoundPlay("evilvoice-NoseTwitch",event.player);
                            break;
                        case 6:
                            SoundHandler.miniSoundPlay("evilvoice-ReleaseEvilCreature",event.player);
                            break;
                        case 7:
                            SoundHandler.miniSoundPlay("evilvoice-ThePowerCalls",event.player);
                            break;
                    }
                }

                if (itemstack.getItem() == ItemInfo.itemOrphanLeg && !event.player.worldObj.isRemote){
                    int ran =ThreadLocalRandom.current().nextInt(3)+1;
                    switch(ran){
                        case 1:
                            SoundHandler.miniSoundPlay("evilvoice-Delicous",event.player);
                            break;
                        case 2:
                            SoundHandler.miniSoundPlay("evilvoice-DoNotPityOrphan",event.player);
                            break;
                        case 3:
                            SoundHandler.miniSoundPlay("evilvoice-Replant",event.player);
                            break;
                        case 4:
                            //SoundHandler.miniSoundPlay("evilvoice-NoPower",event.player);
                            break;
                        case 5:
                            //SoundHandler.miniSoundPlay("evilvoice-WorldTremble",event.player);
                    }
                }


                if (itemstack.getItem() == ItemInfo.itemEnergizedBunny && !event.player.worldObj.isRemote) {
                    int ran = ThreadLocalRandom.current().nextInt(5) + 1;
                    switch (ran) { //use that number
                        case 1:
                            SoundHandler.onEntityPlay("bunnyBegA", event.player.worldObj, event.player, 1, 1);
                            break;
                        case 2:
                            SoundHandler.onEntityPlay("bunnyBegB", event.player.worldObj, event.player, 1, 1);
                            break;
                        case 3:
                            SoundHandler.onEntityPlay("bunnyBegC", event.player.worldObj, event.player, 1, 1);
                            break;
                        case 4:
                            SoundHandler.onEntityPlay("bunnyBegD", event.player.worldObj, event.player, 1, 1);
                            break;
                        case 5:
                            SoundHandler.onEntityPlay("bunnyBegE", event.player.worldObj, event.player, 1, 1);
                            break;
                    }
                }
            }
        }
    }

 

and this is my sound handler

 

 public static void onEntityPlay(String name, World world, Entity entityName, float volume, float pitch) {
        world.playSoundAtEntity(entityName, (Reference.MODID + ":" + name), (float) volume, (float) pitch);
    }

 

this is forge 1188 mc 1.7.10

any ideas why my mod is not working right in smp?

Link to comment
Share on other sites

Where is the old field initialized?

 

What is the console saying?

 

Which of the sounds is involved in the problem?

 

Also you can clean up your logic a bit -- you check if you're on server side before the block of checking for items, so you don't need to check again for being on server side when you check for each item.

 

Why are you adding the player display name to the item name?  Since you're getting the itemstack from the player passed with the event, the itemstack should already be unique to that one player.

 

Why do you bother creating an onEntityPlay() method if you can just use the almost exactly the same playSoundAtEntity() method?'

 

Why are you using atWorldPlace() for one sound and onEntityPlay() for another -- what's the difference?

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Where is the old field initialized?

 

What is the console saying?

 

Which of the sounds is involved in the problem?

 

Also you can clean up your logic a bit -- you check if you're on server side before the block of checking for items, so you don't need to check again for being on server side when you check for each item.

 

Why are you adding the player display name to the item name?  Since you're getting the itemstack from the player passed with the event, the itemstack should already be unique to that one player.

 

Why do you bother creating an onEntityPlay() method if you can just use the almost exactly the same playSoundAtEntity() method?'

 

Why are you using atWorldPlace() for one sound and onEntityPlay() for another -- what's the difference?

 

old field is initialized here https://github.com/mrgreaper/TwistedMod2-reboot/blob/master/src/main/java/com/mrgreaper/twistedmod2/handlers/TwistedEventHandler.java#L30 well...created, it gets a value when the player holds an item.

the idea being that it is supposed to stop the sound being played multiple times as on the second tick the code should say "oh thats what you were holding last tick ok" in idea and ssp this works fine (infact with out it i get the same issue in ssp as smp)

 

no errors in the console, nothing of any use in the console at all

 

as original post, all sounds that play on holding an item are glitching.

 

my code is untidy agreed but then this is more a hobby, a play about for me rather then anything serous, though this issue is bugging me, as for redundent checks, when it comes to things that should only be on one side a redundent check wont hurt things.

 

player name is being added to the item name to make it unique so in the instance running on johns client it will be johnitemname and wont conflict with the instance on freds computer otherwise when one player holds the item it would then not play for any other players as there is no way to tell the difference between john holding the item or fred (maybe i have this wrong, im self taught after all)

 

the onEntityPlay is one of the methods i use, its what im used to and as i say works great in ssp and in idea, if using playSoundAtEntity() is the fix i will use that but if its exactly the same then why use that rather then what i know to work (atleast in ssp)

 

the atWorldPlace was a test it plays a sound at a set of cordinates i pass through to it rather then the other one that targets the entity, again though its not relevent to the issue

 

the full sound handler file

package com.mrgreaper.twistedmod2.handlers;

import com.mrgreaper.twistedmod2.reference.Reference;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;

/**
* Created by david on 04/07/2014.
*/
public class SoundHandler {

    //for when we want complete control
    public static void onEntityPlay(String name, World world, Entity entityName, float volume, float pitch) {
        world.playSoundAtEntity(entityName, (Reference.MODID + ":" + name), (float) volume, (float) pitch);
    }

    //test sound handler
    public static void atWorldplace(World worldObj, double xCord, double yCord, double zCord, String SoundName, float volume, float pitch) {
        worldObj.playSoundEffect((double) xCord, (double) yCord, (double) zCord, (Reference.MODID + ":" + SoundName), (float) volume, (float) pitch);
    }

    //mini call to save typing
    public static void miniSoundPlay(String soundName, Entity entityName) {
        World world = entityName.worldObj;
        world.playSoundAtEntity(entityName, (Reference.MODID + ":" + soundName), 1, 1);
    }


}

 

given the lack of replys im guessing its a bug with forge thats causing the sound system to mess up in smp and not ssp so when i get home from work ill try a newer forge version

Link to comment
Share on other sites

Regarding old initialization, you have the declaration and you will set it equal to current later on, but where do you actually initialize it (set if first time)?  You test it before you set it to current.  I suppose that might work because if it is null it would still test true, but not really good programming practice -- you should actually initialize (set it to something) the field before you use it.

 

Regarding console statements you currently have them all commented out.  Can you uncomment them and see what the logger is putting out?  It should tell you a lot.

 

Regarding the coding style the only reason I mention it is that the more complicated, unnecessary code can cause bugs.  The simpler the better.

 

Regarding the player name, I disagree that other players would be affected -- the event passes a player field which will be unique already, and then you get the itemstack from that player.  So for each time the event handler executes it should only process one player.  Since you're not storing anything outside the method it shouldn't affect other players as far as I can see (I could be wrong).

 

Anyway, enable all the console statements.  Tracing the code execution like that usually can tell you a lot.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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