Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Timer not working...


Naiakoa
 Share

Recommended Posts

In my mod I got a small boss fight that spawns a random 3D object in the world within 10 blocks from the player, the same player runs to said object and right clicks it. It will have 1 out of 10 choices to see if the player gains a helpful buff or not that lasts for 1 or 4 minutes. After that the object gets deleted from the world and is disabled by setting a public variable to true so that the object cannot be used anymore.

 

Now here is the problem, the object is suppose to be re-enabled for use after 10 seconds but for some reason I cannot get a countdown timer from 10 seconds to re-enable the changed variable...Here is the object class file with the timer in it.

 

 

public class BlockHarkar extends BlockNXD

{

    private Random rand = new Random(3);

    public static boolean alreadyExecuted = false; //sets the variable to false by default so that said object can be used

 

    static int interval;

    static Timer timer;

 

    public BlockHarkar(int id)

{

 

        super(id, Material.rock);

        this.setUnlocalizedName(Strings.Harkar);

        this.setCreativeTab(Nexion.nBlocks);

        this.setHardness(5F);

        this.setBlockBounds(0.1F, 0.0F, 0.1F, 0.9F, 1.0F, 0.9F);

    }

 

    @Override

    public boolean renderAsNormalBlock() {

 

        return false;

    }

 

    @Override

    public boolean isOpaqueCube() {

 

        return false;

    }

 

    @Override

    public int getRenderType() {

 

        return RenderIds.HarkarRenderId;

    }

 

    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)

    {

            //int i = rand.nextInt(3);

        switch(rand.nextInt(3))

        {

            case 1: //give more hp for player for a duration of 1 minute

            {

                if(!alreadyExecuted)

                {

                    par5EntityPlayer.addPotionEffect(new PotionEffect(Potion.field_76434_w.id, 1200, 4));

                    alreadyExecuted = true; //disables the orb and prevents the buff from double stacking

                    par1World.setBlockToAir(par2, par3, par4);

                }

            }

            case 2: //Player is refused of an ability

            {

                if(!alreadyExecuted)

                {

                    par5EntityPlayer.addChatMessage(EnumChatFormatting.RED + "The God Spirit Harkar Looks down upon you..." + alreadyExecuted);

                    alreadyExecuted = true; //disables the orb and prevents the buff from double stacking

                    par1World.setBlockToAir(par2, par3, par4);

                }

            }

        }

        return true;

    }

 

    public static void main(String[] args) //current not working timer system

    {

            int period = 1000;

 

            timer = new Timer();

            interval = 20;

 

            System.out.println(interval);

            timer.scheduleAtFixedRate(new TimerTask()

            {

 

                public void run()

                {

                    System.out.println(setInterval());

                }

            }, 1000, period);

    }

    private static final int setInterval()

    {

        if(interval == 1)

        {

            alreadyExecuted = false; //Does not work

        }

        System.out.println(alreadyExecuted);

        return --interval;

    }

}

 

 

And for some reason in a new blank project in eclipse the timer works FLAWLESSLY and yet in minecraft it refuses to even start the countdown...

 

Also note I do not wish to use Thread.sleep for that will cause the whole minecraft game to sleep for X seconds set, I do not want this. It needs to be some kind of timer system where the player still fights the boss and so forth.

A modder uses search for solutions, a coder asks for help only after looking into the main source of the game modding. A master java programmer has solutions and is helpful. Be friendly to others, they will be friendly to you (depending on how their day goes ;) )

Link to comment
Share on other sites

Don't use timers....

 

Count ticks.

 

Even if your timer worked, you'd find that if the player pauses the game the timer will keep ticking.  Which is not correct.

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.

Link to comment
Share on other sites

The only thing that comes close to what I am searching for when it comes to ticks is:

 

 

    @Override

    public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)

    {

        par1World.scheduleBlockUpdate(par2, par3, par4, BlockIds.HarkarSphere, 1);

        if(alreadyExecuted = true)

        {

            ticks ++;

            System.out.println("Ticks "+ticks);

            if(ticks > 20)

            {

                ticks = 0;

                alreadyExecuted = false;

            }

        }

        else

        {

            ticks = 0;

            System.out.println(ticks);

        }

    }

 

    @Override

    public int tickRate(World par1World)

    {

        if(alreadyExecuted = true)

        {

            return 1;

        }

        else

        {

            return 0;

        }

    }

 

 

But it only sets the variable back to false for only a 1/2 a second. thus keeping the tick counter in a endless loop. And ontop of that the only way that the tick will start is if I add this.setTickRandomly(true); at the top, hence why I was giving timers a try :/

A modder uses search for solutions, a coder asks for help only after looking into the main source of the game modding. A master java programmer has solutions and is helpful. Be friendly to others, they will be friendly to you (depending on how their day goes ;) )

Link to comment
Share on other sites

Block#updateTick()?

World#scheduleUpdateTick()?

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.

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.