Jump to content

mrgreaper

Forge Modder
  • Posts

    105
  • Joined

  • Last visited

Posts posted by mrgreaper

  1. i do https://github.com/mrgreaper/TwistedMod2-reboot

     

    Ok clearly past me is a muppet! when i copyed the movingsoundminecart class i removed all the code that delt with it moving with the mine cart....i dont need that code says past mrgreaper.

     

    what actual me just discovered is that since that code actualy sets the xyz and volume of the sound, its pretty important...well ok its not but those values are ...past me your such a moron!

     

    ok so having dutifully chastised myself i now have the sound playing in a loop it turns on and off as the block changes now i desperatly need food and a cafine injection then i will work on making a new block that will use 1 tile entity that can store the sound file we want to play (well the name) and can have the sound started and stopped at command...then i can work on adding a gui where the alarm can be chosen from a list

     

    But my god im glad i have a looping sound working, i was pretty much losing my sanity over it (those that look at my mod may argue that its too late for that)

  2. 1) i dont know how to use hasTileEntity, ill look into that.

    It's just a method you override.

    2) eeeeek!
    Huh?

    3) custom sounds working perfectly for anything non Looped, i was one of the first to figure it out on 1.7.2 (and actually wrote the guide on it lol)  http://www.minecraftforge.net/wiki/MrGReapers_tutorials/1.7.2_sound_tutorial
    Oh ok. I saw that part of your video, too. But I meant the actual sound you are trying to play looped.

    4) i didnt think you could have two tile entitys in the same space (whole quantum explosion scenario) ?
    Of course you can't do that. You'll have only one TileEntity at a time. One when it's powered and another one when it's not powered.

     

    what is my point you may be wondering? well if you have knowledge that can make this work (or really anything some one is stuck on) what does it hurt to share that knowledge? to help that person. you must be able to tell how much grief this issue is causing me, would it hurt to actually show how its done? to give a quick explanation of how it works (im not talking about the hasTile entitiy bit, i havent researched that yet at all , but the playing the sound bit, you can see i have tried to make it work, you can see the approaches i have made, love of god put me out of my misery and let me know how its done!)
    I haven't done this myself yet, either. I am going by the code.

    edit: seems that hasTileEntity is depreciated

     

    @Deprecated //Forge: New Metadata sensitive version.
        public boolean hasTileEntity()
        {
            return hasTileEntity(0);
        }
    

     

    sure enough when i try to over ride it i get a line through it.

    Well, maybe READ what it fu**ing says there? .. Srsly.

     

    1) yeah i understand that but at first glance its a boolen so you can only pass true and false no way to specify the tile entity name etc, ofcourse mute as its deapreciated

     

    2) its short for oh crap i hadnt noticed that, what a muppet i am, i should fix that.

     

    3) yes the sound works is indexed perfectly etc but only when played in the same way as i play other sounds and not when played looped.

     

    4) but if you cant have two tile entitys in the same place at the same time how do you send data from one to the other? the only way i know how to get and set data is to specificly reference it, if only one can exist at a time then how do you do that....i guess i could make it a small multiblock, a controller and a sounder.

     

    "Well, maybe READ what it fu**ing says there? .. Srsly."

    ? i did, its deapreciated, there is no more to it then i posted above and bellow are different methods, that seem irelevent to it

     

    above deals with tick setting

    bellow deals with block bounds

     

    i am on forge 1166 so maybe the version of forge you have gives extra details? what to use instead would be handy lol

     

    I haven't done this myself yet, either. I am going by the code.

    ok sorry, i thought you knew how its done, but had decided to give hints rather then tell how, didnt realise you were likewise stumped, my bad. if its got a forge moderator stumped its possible its just not doable.

     

     

     

     

  3. 1) You don't need removeTileEntity, if you'd followed my advice and used hasTileEntity to specify which metadata values have a TileEntity.

    2) In your TileEntity#onUpdate you should check if the world is the client world (with .isRemote). Otherwise you'll get Threading problems eventually in Singleplayer and a dedicated server will crash entirely.

    3) For your sound not playing... Is your sounds.json, etc. set up correctly? Have you tried just playing the sound normally with just world.playSound to see if the sound itself actually works?

    4) For the sound name... What makes you think you can't set it? Of course you can set the sound name just fine. You can have a TE for the non-active metadata as well, just don't make it play the sound.

     

    1) i dont know how to use hasTileEntity, ill look into that.

    2) eeeeek!

    3) custom sounds working perfectly for anything non Looped, i was one of the first to figure it out on 1.7.2 (and actually wrote the guide on it lol)  http://www.minecraftforge.net/wiki/MrGReapers_tutorials/1.7.2_sound_tutorial

    4) i didnt think you could have two tile entitys in the same space (whole quantum explosion scenario) ?

     

    I will be honest i am at the stage where i could really do with seeing how its actually done, hints are good and welcome but i have been bashing my head at this issue for 2 days now, i know some forge team are of the belief unless you are a hard core programmer you should not be modding but please renember thier are hobby coders such as myself, i dont just cut and paste i work out how stuff is done to, look over my code and you will see that. when i discover something new i share that knowledge :

    For 1.7.2 (and 1.7.10)

    adding speech synth : http://www.minecraftforge.net/wiki/MrGReapers_tutorials/1.7.2_how_to_add_a_speech_Synth

    adding a chatbot : http://www.minecraftforge.net/wiki/Tutorials/MrGReapers_tutorials/1.7.2_how_to_add_a_chatbot_to_your_mod

    and the aforementioned sound guide (standard custom sounds)

     

    when i have a java issue i try to learn all i can to solve it and make sure that (to my ability) i know how it works

     

    i even went through a few of the recommanded learn java tutorials in my little free time to learn more

     

    At one point when i was first starting out i came to the irc channel for help, was riddliculed for my lack of java knowledge and banned, it almost resulted in me giving up on it entirely.

     

    what is my point you may be wondering? well if you have knowledge that can make this work (or really anything some one is stuck on) what does it hurt to share that knowledge? to help that person. you must be able to tell how much grief this issue is causing me, would it hurt to actually show how its done? to give a quick explanation of how it works (im not talking about the hasTile entitiy bit, i havent researched that yet at all , but the playing the sound bit, you can see i have tried to make it work, you can see the approaches i have made, love of god put me out of my misery and let me know how its done!)

     

    edit: seems that hasTileEntity is depreciated

     

    @Deprecated //Forge: New Metadata sensitive version.
        public boolean hasTileEntity()
        {
            return hasTileEntity(0);
        }
    

     

    sure enough when i try to over ride it i get a line through it.

  4. Ok progress of sorts

     

    video explains it better --> https://www.youtube.com/watch?v=55UJfX1CXjs (at time of posting youtube is still processing so 1080p may be a few mins)

     

    i now have the speaker block setup as metadata so its actually 2 blocks so to speak

    public class blockSpeaker extends BlockContainer {
    
        @SideOnly(Side.CLIENT)
        private IIcon[] texture;
        final static String[] metaBlocks = new String[] {"notActive","isActive"}; //this will be the different meta data blocks
    
        public blockSpeaker() {
            super(Material.iron);
            this.setHardness(3.0f);
            this.setResistance(5.0f);
            this.setStepSound(soundTypeMetal);
            this.setCreativeTab(TwistedMod2.TwistedModTab);
        }
    
    
        @Override
        public void onNeighborBlockChange(World world, int xCord, int yCord, int zCord, Block blockID) {
                if (!world.isRemote &&!world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord)) {
    
                    world.setBlockMetadataWithNotify(xCord,yCord,zCord,0,3);
                    world.removeTileEntity(xCord,yCord,zCord);
    
                } else if (!world.isRemote && world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord)) {
                    world.setBlockMetadataWithNotify(xCord,yCord,zCord,1,3);
    
                }
        }
    
        @SideOnly(Side.CLIENT)
        public void registerBlockIcons(IIconRegister iconRegister) {
            texture = new IIcon[metaBlocks.length];
    
            for (int i = 0; i< metaBlocks.length;i++){
                texture[i] = iconRegister.registerIcon(Reference.MODID + ":" + "speaker-"+metaBlocks[i]);
            }
        }
    
        @SideOnly(Side.CLIENT)
        public void getSubBlocks(Item block,CreativeTabs creativeTabs, List list){
            for (int i = 0; i< metaBlocks.length;i++){
                list.add(new ItemStack(block,1,i));
            }
        }
    
        @SideOnly(Side.CLIENT)
        public IIcon getIcon(int side,int meta){
            return  texture[meta];
        }
    
        public int damageDropped(int meta){
            return  meta;
        }
    
        @Override
        public TileEntity createNewTileEntity(World world, int metadata) {
            if (metadata ==1){
                return new TileEntityAlarm();
            }
            return null;
        }
    } 

    meta 0 is its inactive state

    meta 1 is its active state

     

    meta 1 has the tile entity

    tile entity:

    public class TileEntityAlarm extends TileEntity {
    
        private boolean isPlaying = false;
        private String soundName ="alarm-scifiA"; //set a default sound file...though i doubt we can change it
    
    
    
    
    
    
    
        @Override
        public void updateEntity() {
    
            LogHelper.info("ping ping ping ping ping ");
            if (!isPlaying){
                //code to start the alarm
                SoundHandlerLooped alarmSound = new SoundHandlerLooped(worldObj.getTileEntity(xCoord, yCoord, zCoord), soundName);
                Minecraft.getMinecraft().getSoundHandler().playSound(alarmSound);
                isPlaying=true;
            }
        }
    
    
        //since the sound will be stopped when we relaunchmc or in theory go to far from the chunk and it de-loads its
        //better to have it we load the isplaying at false so it restarts it
        //just need to save ths sound name were looping
        @Override
        public void readFromNBT(NBTTagCompound nbt) {
            super.readFromNBT(nbt);
            soundName = nbt.getString("sndName");
        }
    
        @Override
        public void writeToNBT(NBTTagCompound nbt) {
            super.writeToNBT(nbt);
    
            nbt.setString("sndName", soundName);
    
        }
    
    
        }
    

    ignore the sound name being a string, its a hold back from when i thought i would be able to set that from a gui in the block, thats clearly impossible as the block will only have a tileentity when playing the sound(HA if it can ever actually play the sound!, yep im losing hope...and possibly the will to live)

     

    the soundHandlerLooped is unchanged from further up

     

    so what happens?

    well when i place it in the world as its inactive form nothing will happen...its just a block.... good so far

    i give it a redstone signal:

    1)it changes to its active form ...JACKPOT

    2) the tile entity is created and i see my test text "ping ping ping "

    3) no sound, audio da 0, natta in the sound department, the noise of silence

     

    i remove the redstone signall:

    1) block goes back to its non active form

    2) the entity is removed and the test text cease being there

     

    I know you guys dont like to just hand the solution over, normaly i prefer that method as i learn by doing and enjoy the odd challenge...BUT i have been at this all day and most of yesterday, it has ceased being fun a long time ago, now i just want to get this issue behind me, please, why is my sound not playing?, what do i need to do to play the sound?

     

  5. a) ah damn it, i always think of it from the clients point of view so server would be remote but ofcourse im wrong, playing about with that in my present code still results in no sound though.

    b) yep im a muppet i forgot that, i will look at metadata again(need to refresh myself on that as i figured i would never need it)

    c) The ultimate end goal is to have a gui open on right clicking the block so you can choose the alarm sound to play on redstone input, that kind of needs a constant tile entity. .... i think though i have to accept that it cant be done on a constant tile entity and go the simpler route that does make more sense to me. 

     

    the issue still remains that the sound did not play at all despite the code for it to play being triggered , no errors either so i cant even locate where the issue is if i could find where movingsoundminecart is used to trigger sound i would be able to check how im playing my sound is correct but its not in the logical places .

  6. ok im still stuck, everything i have seems to suggest it SHOULD work

     

    but no sound is played.

    the code that should start the sound fires

     

    the code that should stop the sound fires

     

    but no sound

     

    also no errors or anything to use to find out where its going wrong.

     

    I have recorded a video as well to better show where the issue is and what parts are working but im totally stuck again.

     

    the classes i have that deal with this

     

    The block class https://gist.github.com/mrgreaper/d872e672f5ec076d8ebf

    package com.mrgreaper.twistedmod2.blocks;
    
    import com.mrgreaper.twistedmod2.TwistedMod2;
    import com.mrgreaper.twistedmod2.entitys.TileEntitySpeaker;
    import com.mrgreaper.twistedmod2.handlers.SoundHandler;
    import com.mrgreaper.twistedmod2.handlers.SoundHandlerLooped;
    import com.mrgreaper.twistedmod2.reference.Reference;
    import com.mrgreaper.twistedmod2.utility.LogHelper;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockContainer;
    import net.minecraft.block.material.Material;
    import net.minecraft.client.Minecraft;
    import net.minecraft.client.audio.ISound;
    import net.minecraft.client.renderer.texture.IIconRegister;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.IIcon;
    import net.minecraft.world.IBlockAccess;
    import net.minecraft.world.World;
    
    
    /**
    * Created by david on 23/06/2014.
    */
    public class blockSpeaker extends BlockContainer {
    
    private boolean isOn;
    
    //@SideOnly(Side.SERVER)
    public IIcon activeIcon;
    
    
    public blockSpeaker(Material material) {
    super(material);
    
    this.setHardness(3.0f);
    this.setResistance(5.0f);
    this.setStepSound(soundTypeMetal);
    this.setCreativeTab(TwistedMod2.TwistedModTab);
    }
    
    public TileEntity createNewTileEntity(World world, int i) {
    return new TileEntitySpeaker();
    }
    
    
    public void onNeighborBlockChange(World world, int xCord, int yCord, int zCord, Block blockID) {
    LogHelper.info(this.isOn);
    if (!world.isRemote) {
    if (this.isOn && !world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord)) {
    world.scheduleBlockUpdate(xCord, yCord, zCord, this, 4); //hmmm not sure what the 4 is
    isOn = false;
    TileEntitySpeaker spealer2 = (TileEntitySpeaker) world.getTileEntity(xCord, yCord, zCord);
    spealer2.setShouldStop(true);
    } else if (!this.isOn && world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord)) {
    isOn = true;
    TileEntitySpeaker spealer2 = (TileEntitySpeaker) world.getTileEntity(xCord, yCord, zCord);
    spealer2.activateSpeaker(true, "alarm-genericA");
    
    
    }
    }
    }
    
    
    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister) {
    this.blockIcon = iconRegister.registerIcon(Reference.MODID + ":" + this.getUnlocalizedName().substring(5));
    this.activeIcon = iconRegister.registerIcon(Reference.MODID + ":" + this.getUnlocalizedName().substring(5) + "_active");
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
    
    TileEntitySpeaker speaker = (TileEntitySpeaker) world.getTileEntity(x, y, z);
    
    return speaker.isActived() ? activeIcon : blockIcon;
    }
    }
    

     

    The tile Entity class https://gist.github.com/mrgreaper/d110ac8a89786aeeef20

    package com.mrgreaper.twistedmod2.entitys;
    
    import com.mrgreaper.twistedmod2.handlers.SoundHandlerLooped;
    import com.mrgreaper.twistedmod2.utility.LogHelper;
    import net.minecraft.client.Minecraft;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.world.World;
    
    /**
    * Created by david on 06/07/2014.
    */
    public class TileEntitySpeaker extends TileEntity {
    private String soundName = " ";
    private boolean isPlaying;
    private boolean shouldStop;
    public boolean Actived;
    private boolean start = false;
    private SoundHandlerLooped alarmSound;
    
    public boolean isActived() {
    return Actived;
    }
    
    public void activateSpeaker(boolean active, String sndName) {
    Actived = active;
    soundName = sndName;
    LogHelper.info(active + sndName);
    shouldStop = false;
    start = true;
    }
    
    public void setShouldStop(boolean toggle) {
    shouldStop = toggle;
    }
    
    
    @Override
    public void updateEntity() {
    //LogHelper.info("Start = "+start);
    if (start) {
    LogHelper.info("YES DETECETED");
    alarmSound = new SoundHandlerLooped(worldObj.getTileEntity(xCoord, yCoord, zCoord), soundName);
    start = false;
    isPlaying = true;
    if (!worldObj.isRemote) {
    LogHelper.info("YES IS CLIENT SIDE");
    Minecraft.getMinecraft().getSoundHandler().playSound(alarmSound);
    }
    }
    if (isPlaying && shouldStop) {
    LogHelper.info("stopping sound");
    isInvalid();
    shouldStop = false;
    }
    }
    
    
    @Override
    public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    
    soundName = nbt.getString("sndName");
    isPlaying = nbt.getBoolean("isPlay");
    shouldStop = nbt.getBoolean("shouldStop");
    Actived = nbt.getBoolean("activated");
    
    //nbt tags will be loaded in here...none at mo
    
    }
    
    @Override
    public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    
    nbt.setString("sndName", soundName);
    nbt.setBoolean("isPlay", isPlaying);
    nbt.setBoolean("shouldStop", shouldStop);
    nbt.setBoolean("activated", Actived);
    //nbt tags will be saved in here when we have some
    }
    }
    
    

     

     

    The SoundHandlerLooped class (which is a copy of movingsoundminecart with out the movement code)

    https://gist.github.com/mrgreaper/c14555f29379ad209a72

    package com.mrgreaper.twistedmod2.handlers;
    
    import com.mrgreaper.twistedmod2.reference.Reference;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import net.minecraft.client.audio.ITickableSound;
    import net.minecraft.client.audio.MovingSound;
    import net.minecraft.client.audio.PositionedSound;
    import net.minecraft.entity.item.EntityMinecart;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.MathHelper;
    import net.minecraft.util.ResourceLocation;
    
    /**
    * Created by david on 06/07/2014.
    */
    @SideOnly(Side.CLIENT)
    public class SoundHandlerLooped extends MovingSound {
    private final TileEntity tileentity;
    
    
    public SoundHandlerLooped(TileEntity tile, String Soundname) {
    super(new ResourceLocation(Reference.MODID + ":" + Soundname));
    this.tileentity = tile;
    this.repeat = true;
    }
    
    
    public void update() {
    if (this.tileentity.isInvalid()) {
    this.donePlaying = true;
    }
    }
    
    @Override
    public boolean isDonePlaying() {
    return this.donePlaying;
    }
    }
    

    The Video showing the issue and code:

    [media]http://youtu.be/5Vcw7Q59YBw[/media]

     

    doesnt seem to want to embed the video http://youtu.be/5Vcw7Q59YBw

  7. Ok, I'll guide you through the MovingSoundMinecart class (the classname MovingSound is stupid btw, it's should be LoopingSound. Every sound can move):

    First, we have a Field holding the EntityMinecart object, should be obvious. In your case this would refer to your TileEntity.

    Then we have a float field which is computed from the Minecart's motion to adjust the sound. You will not need this as your TileEntity obviously doesn't move.

    The constructor should also be self-explanatory, the important thing is to set repeat to true.

    Then we have the update method, which is called every tick (because this class implements ITickableSound).

    This just checks if the minecart is "dead" yet and if so, stops the sound. You do the same with your TileEntity, the equivalent method would be .isInvalid().

    Otherwise, if it's not dead it updates the position of the sound, which again you don't need to do because your TileEntity doesn't move.

     

    Now, which part of this do you find hard or complicated?

     

    I think i was thrown by the name of it, it does indeed make sense like that, i will retry once i have fixed an issue im working with and edit this post with the result.

     

    Thank you, sometimes having the code explained helps no end even when once explained it seems obvious, some times the wood just cant be seen for all trees so to speak.

  8. Just to clarify: This is not all that complicated. You just don't have copy-paste code ready for you in "Tutorial" form and have to actually use your programming skills and to be honest with you: It shows that you are not actually a programmer, which you need to be to make mods.

    nope im not a programmer, i have spent many hours/days/weeks following java guides and learning what i need to learn when stuck.

    I do not just copy and paste from tutorials! i like to know what im adding and why it works how it works, this is why i spent so many hours on getting that part to work.

    A good tutorial will guide you through doing something and teach you how to do it, not just a "heres some code, copy that"

    When i have discovered a way to do something i feel no one else has i have done a guide for it for others, with that approach in mind.

     

    But at the end of the day im modding for fun in my free time, im off work this week so i decided to focus on my mod. Last night started of as a challenge, can i do this, and indeed in a mess, i am completly stuck on it, you say its not all that complicated, maybe to yourself it isnt (in which case for the love of god how is it done!) for me its damn confusing.

     

    i keep going back to the source code of minecraft but the only way to turn it off i can see is the death of the entity its attached to, thats not the case of a minecart though. in many mods theres the sound being played in a loop while the machine is on, just no open source ones i can think of.

     

    To be honest the posts i have made in this thread should show im not just copy-pasting tutorial guides!

  9. i must admit i have been wondering why use proxys when you can tell what side code to be with "side only" but then i have never fully understood the proxy classes, most guides will tell you how to create them but not how to effectively use them, they along with packet handlers remain a bit of a mystery to me.

    I have always taken the approach that if my code works then im happy, im sure if many seasoned modders looked at my source code they would hunt me down with pitchforks :), but then im only modding for the fun of getting something working in game not for the masses(will be released as always for those that may want it but im not planning to be the next calclavia/xcompwizard/dan200 etc etc)

  10. 1st of all: You should probably subclass MovingSound, not PositionedSound. Then you already have the "donePlaying" Field and the "isDonePlaying" method.

    Why you can't access the setter is the follwing: You've declared your Sound field as ISound. So even though you have stored YOUR class into it, the field is still declared as holding and ISound instance. So you are not actually sure that it could (theoretically) not contain anything else, NOT your class.

    So when you access the field, you can of course only interact with it like with any ISound object.

     

    Furthermore you still have your Sound field in your Block. That means you will not be able to play multiple instances of your sound at once!

     

     

    hmmm i think i need to delete that bit entirely and start again on it! too edits - deletes - additions its not what it was lol

    Im not sure movingsound would be right as my sound doesnt need to move but i will re-look at the files

     

    yeah i know i need to move it to the tile entity i just wanted to get it working first lol

     

    as i say its really strange that something so simple ( a repeating until told not to sound file) is so damn complicated and undocumented in tutorial form for any of the minecraft versions.

     

    please understand though that despite my frustrations your help has been and is greatly appreciated.

  11. In my google searches i saw Calclavia had the same issue and solved it, he said in his post he created a tutorial, but the link did not work. So i asked in his thread how he solved the issue.

     

    I just checked back and found that thread deleted (it was in general discussion), rather displeased about that as im still looking to fix this and there was someone that knew the answer, a thread specificly about the issue im facing and its gone :(

     

    i have linked calclavia to this thread with luck he will renember the solution :) (if he gets time to look, i know he is a busy man)

     

    For now though i need sleep very much so, maybe when i awake i will see it with fresh eyes.

  12. Well im still stuck

     

    this is very frustrating

     

    my block class:

    public class blockSpeaker extends Block {
    
    
        public blockSpeaker(Material material) {
            super(material);
    
            this.setHardness(3.0f);
            this.setResistance(5.0f);
            this.setStepSound(soundTypeMetal);
            this.setCreativeTab(TwistedMod2.TwistedModTab);
        }
    
        public boolean isactive = false;
        private ISound testSound2 ;
    
    
        public TileEntity createNewTileEntity(World world, int i) {
            return new TileEntitySpeaker();
        }
    
    
        public void onNeighborBlockChange(World world,int xCord, int yCord, int zCord,Block blockID) {
            LogHelper.info("change");
            if (!world.isRemote && world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord))
            {
                LogHelper.info("I see it i see it!");
                testSound2 = new SoundHandlerLooped(Reference.MODID + ":alarm-genericB", xCord, yCord, zCord, 1, 1);
                Minecraft.getMinecraft().getSoundHandler().playSound(testSound2);
            }
    
            if (!world.isRemote && !world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord)){
                testSound2.setcontinuePlaying(false);
            }
        }
    
    
        @SideOnly(Side.CLIENT)
        public void registerBlockIcons(IIconRegister iconRegister) {
            this.blockIcon = iconRegister.registerIcon(Reference.MODID + ":" + this.getUnlocalizedName().substring(5));
        }
    }
    

     

    my SoundHandlerLooped class

    package com.mrgreaper.twistedmod2.handlers;
    
    import net.minecraft.client.audio.ITickableSound;
    import net.minecraft.client.audio.PositionedSound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ResourceLocation;
    
    /**
    * Created by david on 06/07/2014.
    */
    public class SoundHandlerLooped extends PositionedSound implements ITickableSound {
            protected boolean donePlaying = false;
            private boolean continuePlaying;
    
            public SoundHandlerLooped(ResourceLocation path,int xCord,int yCord,int zCord, float volume, float pitch) {
                super(path);
                this.repeat = true;
                this.volume = volume;
                this.field_147663_c = pitch;
                this.xPosF = xCord;
                this.yPosF = yCord;
                this.zPosF = zCord;
                this.field_147665_h = 0;
            }
    
            public SoundHandlerLooped(String path,int xCord,int yCord,int zCord, float volume, float pitch) {
                this(new ResourceLocation(path), xCord,yCord,zCord, volume, pitch);
            }
    
            @Override
            public boolean isDonePlaying() {
                return this.donePlaying;
            }
    
        @Override
        public void update() {
            if(!continuePlaying){this.donePlaying=false;}
        }
    
        public void setContinuePlaying(boolean var1) {
            this.continuePlaying = var1;
        }
    }
    

     

     

    At first glance they may seem the same as earlier quoted but theres minor changes

     

    the soundHandlerLooped has no errors on it code wise (well according to idea)

     

    the block class has an error ...it cant see setcontinuePlaying in the line testSound2.setcontinuePlaying(false);

     

     

    I have Re-read instancing and encaptuations to make sure i have this right but clearly i dont (or is mc doing something strange?)

     

    ok as i uderstand it when i run

    private ISound testSound2 ;

    and then later (upon recieving a redstone signal)

    testSound2 = new SoundHandlerLooped(Reference.MODID + ":alarm-genericB", xCord, yCord, zCord, 1, 1);

     

    i have created an instance of SoundHandlerLooped called testSound2 (and im assuming, linked to the instance of the block)

     

    so to access the setter method setcontinuePlaying i should just be able to do testSound2.setcontinuePlaying(false) ie Instance name . method name ( value i want to pass on)

    if i was to change setcontinuePlaying to static i would then have to change boolean continuePlaying to static i could reference it via the class name (ie SoundHandlerLooped.setcontinuePlaying(false) ) BUT all instances of SoundHandlerLooped would be effected ...as well its a static value so turn off one loop you turn off them all

     

    one of the sources that made instances clear to me is http://journals.ecs.soton.ac.uk/java/tutorial/java/javaOO/classvars.html ....is that incorrect? in which case i have gone horribly wrong

     

     

    so frustrating

     

    create a single one time sound you just need a function

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

     

    and call it when you need sound

     

    SoundHandler.miniSoundPlay("evilvoice-IsItDead",event.player);
    

     

    to play a looped sound file you need a seperate class and some sort of advanced physics degree in computer stuff (its 3 am and i have been working on this since around 2100, (i didnt post here until i was sure i couldnt find the info elsewhere) im a little fryed)

     

    Though your help has been appreciated (i wouldnt of gotten this far with out the hints you gave) and hay i have a looping sound...i cant kill it but i have it

     

    havent looked into switching it to be in the tile entity yet or making it persistant, need to figure out how to turn it on and off first then can look at the rest

  13. Ok i know that it is better to hint how to do it and help the other person to learn but im stuck 100%,  i have made progress, i have googled but i need more help, sorry but i just dont get it.

     

    heres what i have done, i have created a sound handler for looped sounds (since its method is MAJORLY different to how im used to making sounds)

     

    public class SoundHandlerLooped extends PositionedSound implements ITickableSound {
            protected boolean donePlaying = false;
    
            public SoundHandlerLooped(ResourceLocation path,int xCord,int yCord,int zCord, float volume, float pitch) {
                super(path);
                this.repeat = true;
                this.volume = volume;
                this.field_147663_c = pitch;
                this.xPosF = xCord;
                this.yPosF = yCord;
                this.zPosF = zCord;
                this.field_147665_h = 0;
            }
    
            public SoundHandlerLooped(String path,int xCord,int yCord,int zCord, float volume, float pitch) {
                this(new ResourceLocation(path), xCord,yCord,zCord, volume, pitch);
            }
    
            @Override
            public boolean isDonePlaying() {
                return this.donePlaying;
            }
    
        @Override
        public void update() {
    
        }
    }
    

     

    then i added in my redstone detection code on my block

     

    public boolean isactive = false;
        private ISound testSound2 ;
    
    
        public TileEntity createNewTileEntity(World world, int i) {
            return new TileEntitySpeaker();
        }
    
    
        public void onNeighborBlockChange(World world,int xCord, int yCord, int zCord,Block blockID) {
            LogHelper.info("change");
            if (!world.isRemote && world.isBlockIndirectlyGettingPowered(xCord, yCord, zCord))
            {
                LogHelper.info("I see it i see it!");
                testSound2 = new SoundHandlerLooped(Reference.MODID + ":alarm-genericB", xCord, yCord, zCord, 1, 1);
                Minecraft.getMinecraft().getSoundHandler().playSound(testSound2);
            }else{
                isactive = false;
            }
            if (!isactive){
                // testSound2.isDonePlaying = true;
                //why wont that work?!?
            }
        }
    

     

    only to stop the sound (if i understand correctly) i need to change the sound handlers (in thiscase the object known as testSound2)  isDonePlaying to true to make to sound stop....but testSound2.isDonePlaying is not valid

     

    thats not the only issue

     

    when redstone is led to the block and signal is applied the sound file plays in a loop! yay

    when the signal is stopped the sound carrys on (but ofcourse as we cant tell isDonePlaying to be true)

    if you log out when redstone is applied and log in again the sound does not play until you turn off the signal and turn it on again

     

     

    so heres where im stuck

    1) how do i tell it to make isDonePlaying true?

    2) unrelated to sound (i think) but have i missed something on onNeighborBlockChange ? (all looks right from Block.class)

  14. Herp derp, i had the old filename from 1.6.4 in my head. It's MovingSoundMinecart.

     

    i dont get it,

     

    i see where it sets the resource location, i can see that what calls it passes on the minecart entity,

    i can see where the x y and z are gotten

     

    i can see where it sets donePlaying (that bit is useful)

     

    i can see its actually tracking the entity so the sound moves with the entity (could be useful in the future indeed but my entity wont be moving, always good for the future as i say though)

     

    i can see where it sets the volume

     

    but i cant see where it actually plays the sound on a loop,

     

    im guessing it sends the sound to a function that will repeat the sound until donePlaying = false but i cant see where it does that?

     

    Have i missed something blatent? (its possible i have been working on my mod all day)

  15. hmmm cant find that class, could that be a 1.6.4 class?

     

    i found in net.minecraft.audio MovingSound but i cant get my head around how they are using it.

     

    for clarity the sound doesnt have to move with the entity as the entity should never be moving, onEntity is just how i have upto now delt with sound as its all been player based

     

    im gonna delve back into the files and see if i can suss this, its damn confusing though

     

  16.                                                                   **edit**

    solved, if you find this when looking for the same issue see page 2 for how it was solved....because yeah its horrible when your researching an issue and find someone that has the same problem who then goes *solved* with out saying how lol, recommend you read through the whole thread though.

                                                                  **end of edit**

     

                                                                    **edit 2**

    seems its not solved, can fix the server side crashes using a proxy so all good crash wise but now on a server you get no sound! its fine single player (which is a server/client) arghhhhhhhhhhhhhhhh

                                                                      **end of edit2**

     

    ok i know how to play a sound file at an entity, but is there anyway to make it loop for as long as a boolean is true

     

    my ultimate plan will be while the block is getting a redstone signal it would play a sound on a loop (the sound will target the tile entity rather then the block of course)

     

    i have googled and cant find any info on it, i can get a sound file to play multiple times at the same time though .....not quite the effect i want lol

     

    so is it possible?

    if so how?

     

    many thanks in advance

  17. ok i have no default minecraft sounds in the ide

     

    i get these errors in the log

    [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:music.menu

    [Client thread/WARN]: Unable to play unknown soundEvent: minecraft:gui.button.press

     

    i checked eclipse/assets and it was empty so i copyed the assets over but it still wouldnt work

     

    i re-ran gradlew clean  then setupdecompworkspace and finally gradlew idea but it that didnt fix it

     

    i went into userfolder and deleted .gradle and re-ran above forcing it to re-download everything.....still didnt fix it

     

    tried adding --assetsDir=eclipse/assets to the program arguments of the minecraft client inside idea...still no go

     

    im out of ideas, i mean i dont really need sound at the moment but it feels wierd when testing my mod and not hearing anything lol

     

    Forge Version: 1.7.10-10.13.0.1160

    Ide: idea

     

     

  18. Ok, i've done almost the same, i have made a playerhandler server side that extends from the ServerConfigurationManager who receive the packet and handle all the stuff i need server side.

    But in the latest 999 i have noticed that there are some event added to simplify the network handling, i will see how to use this stuff.

     

    that would be cool, been looking everywhere for info on the new system since 999 released yesterday all i can find is this thread. Looked all over the code too cant find it at all.

  19. i use this in my event handler

     

    @SubscribeEvent

        public void TwistedChatEvent(ServerChatEvent event) {

            String chatMessage = event.message;

            //System.out.println("message reads :"+chatMessage);

    if (chatMessage.startsWith("test") && chatMessage.endsWith("sound")) {

                SoundHandler.onEntityPlay("bunnyRelease", event.player.worldObj, event.player, 1, 1);

            }

            if (chatMessage.contains("need")&& chatMessage.contains("name")){//for future use

                System.out.println("wow it worked");

            }

        }

     

    hope that helps

     

  20. That's a tough one. I too sat there like: "what on earth?!?". But here is the problem: There are always 2 players, client & server and both will fire a TickEvent. So your stuff gets executed twice, which makes it derp up. You need to only do this either on the server or only on the client.

    Another flaw with your system is, that it will not work in multiplayer, because you only have one sound toggle. So as soon as there is more than one player on the server it will get screwed up again. You need to store the sound toggle "in" the entity player, I suggest using IExtendedEntityProperties for that.

     

    hmm i did it the same way in 1.6.4 (well ok i used a tick handler but now ticks are events) i did try to make it server side only and the debug text repeated indeafenatly when the item is held but no sound, and if i made it client side on sound repeated all the time the item was held (played over itself).

     

    im looking at a guide for IExtendedEntityProperties now and trying to absorb the knowledge contained thier in.

     

    @gotolink

    with out the sound toggle the sound will play every tick as every tick the conditions will be true, so it has to be there. my sound handler deals with all sounds and ensures that any sound that needs to be played is heard by all in range, it actualy gets the coords of the entity its given and plays the sound there, the upshot is all hear the sound (here thats not really needed but is a bonus, in other stuff it will be needed) the downside is the sound does not move with the entity that made it and stays localised to that area.... im sure theres ways of getting it to track with the entity i just havent looked into it yet.

  21. the video explains it better then the text

    http://www.youtube.com/watch?v=3jCbh0bnHWc

     

    ok the video explains the issue but to go over it briefly in text:

     

    the goal: when you hold an electric bunny you get a sound that plays just once untill you hold something else and then rehold the bunny at which point it plays a different sound again just once

     

    How is this ment to happen : well we check to see if the player has an item in thier hands, if they do we see what it is.. now if it is an electric bunny AND if the config allows the bunnys to cry AND our soundtoggler is set to false (which it starts off as) then we play a random sound then set the toggler to true to prevent it going on repeat. once another item is chosen (anything thats not an electric bunny) we set the sound toggle to false so another sound can be played

     

    What happens : when the player switches to electric bunny we see it is an electric bunny, the config is true and soundtoggle is false but it skips the playing of the sound and sets the soundtoggle to true, soon as we choose an item thats not an electric bunny it plays the sound, it then wont play it again untill we choose the electric bunny and again deselect it.

     

    Conclusion, it seems like its putting the sound in a buffer and not playing it until after sound is false again. i thought it was my soundhandler but other sounds play perfectly fine, despite using the same handler!

     

    the event handler in question https://github.com/mrgreaper/TwistedMod2/blob/master/src/main/java/com/mrgreaper/twisted/handlers/EventHookHandler.java (this will show the revised but still not working code)

     

    the sound handler

    https://github.com/mrgreaper/TwistedMod2/blob/master/src/main/java/com/mrgreaper/twisted/handlers/SoundHandler.java

     

     

     

     

    Changed the code under the advice of spacemaniac on irc, much neater code...same bug

     

    im thinking its a bug with forge perhaps

     

    http://www.youtube.com/watch?v=VrTv_SzCUHY

     

    as you can see the debug text that should be fired once when the bunny is selected and the sound is played fires twice when the object is selected but no sound and once when the item is no longer selected but the sound then plays....thats not how the code should work logicly!

     

     

     

     

  22. A video on how to add a speech synth to your mod

     

    **********************************************************

    *                                                The Video                                                *

    *                  http://www.youtube.com/watch?v=5XbnfTcQIkk                *

    *                                                                                                                *

    **********************************************************

     

    free tts : http://freetts.sourceforge.net/docs/index.php

    my speech handler : http://pastebin.com/akhMByAC

     

    **NOTE** only call the function client side! the server wont like you if you try to make it speak lol

     

    hope this helps people, im sure you guys can do much better armed with this knowledge then me :)

     

    Mods : i am trying to put this on the wiki now

×
×
  • Create New...

Important Information

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