Get Attack (Swing) Cooldown 1.10

Discussion in 'Spigot Plugin Development' started by FanaticNinja, Jun 26, 2016.

  1. I am trying to get a players swing cooldown for 1.10. I have found this thread, https://www.spigotmc.org/threads/get-attack-indicator.132402/#post-1408260 however, when i call EntityHuman.o(0); it always returns 0.

    I am assuming the obfuscated variables have changed for the 1.10 update, perhaps someone knows what they are now?

    Ill be testing to see if i can figure it out. If i do, ill edit this post.
     
  2. I guess to be more specific, the time since last attack. To check if its a fully recharged attack vs a half attack.

    I could always track their time since last attack, get their attack speed. and do my own math. But it seems this is already tracked in the obfuscated variables.
     
  3. Necroing because I'm having exactly the same issue. It's stupid, the methods don't seem to have changed at all but they just aren't working.

    I've found this little snippet in the EntityHuman#attack(Entity) method, but it doesn't seem to be dynamic either.
    Code (Java):
    float f2 = this.o(0.5F);
    f *= 0.2F + f2 * f2 * 0.8F;
    f1 *= f2;
    this.de();
    where f2 seems to be the "cooldown" calculations, f is damage base got from the generic attribute and f1 being enchantment modifier. And de() method is resetting the time since last attack I think.

    I tried to use the code above like so to see how if it does anything. It doesn't.
    My try (in EntityDamageByEntityEvent):
    Code (Java):
    float dmg = 4.0F;
    float modif = ((CraftPlayer)e.getDamager()).getHandle().o(0.5F);
    dmg *= 0.2F + modif * modif * 0.8F;
    System.out.println("modif: " + modif);
    System.out.println("dmg: " + dmg);
    Result:
    Code (Text):
    [14:01:20 INFO]: modif: 0.019999998
    [14:01:20 INFO]: dmg: 0.80128
    [14:01:20 INFO]: modif: 0.019999998
    [14:01:20 INFO]: dmg: 0.80128
    [14:01:21 INFO]: modif: 0.019999998
    [14:01:21 INFO]: dmg: 0.80128
    All the same numbers over and over again. Like what the heck.

    Where else could be the calculations made? I couldn't find anything of use. Everything seems to be just unmodified numbers everywhere. It's a mess pretty much.
     
  4. Just try using a HashMap and storing System.currentTimeMillis() and updating that hashmap everytime someone interacts with an entity or the world. Kinda lousy method but it might work.
     
  5. That's why I don't really want to use it. As OP said, the calculations are already made nevertheless. I don't want to do exactly the same work twice for no reason.
     
  6. I'm a bit confused, I don't see any problem with EntityHuman's o(float) method in 1.10.2

    I grabbed an axe and ran the following code and it looked like it was working just fine:
    Code (Java):
    new BukkitRunnable(){public void run(){
        for(Player player : Bukkit.getOnlinePlayers()){
            EntityPlayer ep = ((CraftPlayer)player).getHandle();
            player.sendMessage("o(0) == "+ep.o(0));
        }
    }}.runTaskTimer(plugin, 0, 1);
    I'd swing, and it'd count back up to 1.0

    (I actually used the action bar during the test instead of sendMessage, but meh. You can also send a title instead >.<)

    [​IMG]
     
    • Winner Winner x 3
  7. Well, that makes sense. I'm just a stupid goon. The damage event is being called after all the calculations are made so it was logically supposed to always display the same value (lowest possible for the cooldown) for me.
    Thanks, man. Now I feel bad about myself. >:[ But the issue is resolved - too bad I'm not the OP and cannot mark the thread.
     
    • Friendly Friendly x 1