1. ICY_Nerd

    ICY_Nerd New Member

    Messages:
    8
    Hey, I'm making a mod that replies whenever you send a certain message, for ex, if someone types "hi" it will reply with "hello." after a certain amount of seconds. however thread.sleep() freezes the game and I don't necessarily want my game to freeze/crash.. so is there an alternative for that orrr?

    my listener class:
    Code:
    public class ARListener {
        @SubscribeEvent
        public void onMessageRecieved(ClientChatReceivedEvent e)
        {
            Minecraft mc = Minecraft.getMinecraft();
            String raw = e.message.getUnformattedTextForChat();
            if (raw.contains("hi"))
            {
                 //wait for 5 seconds
                 mc.thePlayer.sendChatMessage("hello!");
            }
            else
            {
                 return;
            }
        }
            }
     
    #1
    Last edited: Sep 27, 2019
  2. Hey, I'm sorry but I don't know how you can do it, however can you please use the code tag so you can keep indentation etc so it is easier to read it ;)
    You can do it by clicking on the + near the Media Button and then Code, or you can write [CODE ] at the beggining of your code and [/CODE ] at the end (without the space :p)
     
    #2
  3. ICY_Nerd

    ICY_Nerd New Member

    Messages:
    8
    kk
     
    #3
  4. Dance

    Dance Well-Known Member

    Dance_Dog
    MVP+
    LimboFish
    Guild Master
    Messages:
    4,950
    Haven't done forge in a while but have you tried creating a separate Thread for this task? That way you could sleep on that thread without stopping the game's thread.

    An alternative would be to save the time the command was executed and setup a tick listener that fires once the current time is 5 seconds greater than the original execution time.
     
    #4
    • Agree Agree x 1
  5. Aycy

    Aycy Well-Known Member

    Messages:
    635
    your sleep method is called on the main mc thread, so the game freezes. create a new Thread and Runnable, and run code/sleep method inside it
     
    #5
  6. ICY_Nerd

    ICY_Nerd New Member

    Messages:
    8
    ? wdym by that
     
    #6
  7. ICY_Nerd

    ICY_Nerd New Member

    Messages:
    8
    how would i do that?
     
    #7
  8. Dance

    Dance Well-Known Member

    Dance_Dog
    MVP+
    LimboFish
    Guild Master
    Messages:
    4,950
    Code:
    new Thread() {
        @Override
        public void run() {
            // Do something...
        }
    }.start();
    
     
    #8
  9. ICY_Nerd

    ICY_Nerd New Member

    Messages:
    8
    hey uh can u add me on discordf so we can talk better?
     
    #9
  10. Dance

    Dance Well-Known Member

    Dance_Dog
    MVP+
    LimboFish
    Guild Master
    Messages:
    4,950
    Yep:
    Dance#7859
     
    #10
  11. You can count Minecraft ticks.
     
    #11

Share This Page