A little issue with potion's and drinking animation.

Discussion in 'Plugin Development' started by Ziszek, Jul 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Ziszek

    Hey guys.
    I have a little problem with my first plugin.
    The plugin makes player drunk (5 tiers of drunk).
    First beer(potion of water) just add little potioneffect to the player.
    After 5 beer's the player lose his consciousness (blindess) and teleport to appointed place.
    But, i have a little issue when player is drinking the potion of water.
    Here's a scrap of my code:
    Code:
    public void onPlayerInteract(PlayerInteractEvent wypicie){
            Player gracz = wypicie.getPlayer();
            if(wypicie.getPlayer().getItemInHand().getTypeId()==373){
                gracz.getInventory().setItemInHand(null);
                ++stopien_napicia;
                if(stopien_napicia == 1){
    ...
    PlayerInteractEvent start when player click the right mouse button. But there's an animation :<
    So, when player just right click, plugin starts work but the bottle is still full.
    I'v tried to avoid that by immediately removing it from hand. Its work's if you do it slow. But if player enable an panic mode clicking, its not work and he can get 5 fiers of drunk by one beer.
    I'm sorry if someone had that problem before me and i didn't realise that (i used search).
    Also i'm new in coding minecraft plugins so dont be angry :p
    I think, maybe delaying(animation time), and again checking the ItemInHand will solve my problem?
    Sorry for bad english.
    Regards, Ziszek.
     
  2. Offline

    Father Of Time

    You problem is coming from the fact that you can only track when a potion has been successfully consumed, not when the player attempts to drink the pot but then stops half way through; I ran into this exact same issue with the nether portal animation (I could tell when the teleportation was complete, but not when they walked into/out of the purple stuff).

    Unfortunately, I don't know of a fix for this... The animation is handled client side and therefore as far as I am aware the server is never notified of the animations cancelation; because if they drink it and stop then the client can just stop the animation, the server never actually "drank" the potion so it's not notified. It's only when the client completely the animation cycle that it sends a packet to the server to notify it.

    So in short (and I hate saying this) what you are asking for is not impossible, but extremely difficult, buggy, and likely not worth the time it would take to complete.

    I really am sorry, but I figured sometimes bad news is more useful then no news (because atleast you can stop the search). However; this is only my opinion, so there may be additional avenues that you can take that I am unaware of.

    Good luck with your project, bottoms up! :cool:
     
  3. Offline

    Ziszek

    Thank's for you answer!
    And you are fully right about that bad news are really useful. I just wasted (maybe not?) at leats 2 days to search the solution :p
    Still looking for it, but now i know thats may be impossible only on server side.
    I'll try to avoid that by delaying task, but that's mean i have to learn about schedulers <oh crap>.
    In fact, there's a PlayerBucketEmptyEvent, so maybe its not a bad idea for PlayerPotionEmptyEvent?=D
     
  4. you can do some native mc stuff that does it, I am pretty sure some kind of packets wil be send between the client and server when they do it
     
  5. Offline

    Firefly

    How about putting the player in a list when they right click, and then continually checking to see if the water bottle itemstack changed to an empty water bottle: granted only checking the players in the list.
     
  6. Offline

    LucasEmanuel

    The scheduler is as easy as it can get and youll be doing miracles with it within 1 hour if you get your head around it. Dont be afraid of something that seems hard but embrace it for the experience you will gain. If you are thinking about some serious plugin projects you are going to have to learn the scheduler sooner or later so why not start now?

    You will know exactly how to work with it withing 30 minutes i can promise you that :)

    The easiest way i can think of is making a delayed sync task that checks your players inventory to see if there is now an empty bottle where it didnt use to be, just have it execute after like 40 ticks or whatever the time it takes to finish the animation.
     
  7. Offline

    Deathmarine

    if you cancel the event it will stop part of the animation. I know it will stop part of eating animation.
     
  8. Offline

    Ziszek

    Thanks all of you! :)
    I'm pleasantly surprised by the number of replies!
    I'll try all that solutions soon, and answer here which one is working :)
    Thank you for your words of encouragement! I'm pretty sure that i'll get that fast :)

    Regards all of you, Ziszek.
     
  9. Offline

    nanhyh

    Now is it possible to speed dip the animation?
     
  10. Offline

    EnvisionRed

    Speed dipping is my expertise. But I don't think it can be done for the animation.
     
Thread Status:
Not open for further replies.

Share This Page