Posted April 2, 20205 yr Hi there, I am currently trying to make a cooldown bar decrement gradually over a set time, however am unable to do so as that would require me to decrement each tick by a double, which ingameGUI.blit does not support. Is there anyway around this? My problem is this: 182 needs to gradually go down to 0 over X amount of ticks, by even decrements. However, each decrement must be an int. Is there anyway to allow this to happen? Currently X = 80, which means if it decrements evenly each tick it must be a float, 2,275, which blit does not support. I have tried Math.round() and Math.ceil(), however that messes up the timing of my cooldown Here's my code: @SubscribeEvent public static void playerTick(TickEvent.PlayerTickEvent event) { if (event.phase == TickEvent.Phase.END) { Minecraft mc = Minecraft.getInstance(); PlayerEntity player = event.player; if (player == mc.player) { if (player.world.isRemote) { cooldown++; //DodgeGui.dlen is the length of the dodge bar // Handle GUI. every tick, it needs to go down by cooldownLength/182 if (DodgeGui.dlen > 0) { DodgeGui.dlen = (int) (DodgeGui.dlen-Math.ceil(182/80)); System.out.println(80/182); } if (cooldown == cooldownLength) { Minecraft.getInstance().player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1); DodgeGui.dlen = 0; //Ensure it's hidden } } } } } } Any help would be greatly appreciated! Edited April 2, 20205 yr by ultra_reemun Fixed code
April 2, 20205 yr Author 16 minutes ago, diesieben07 said: Keep the value as a float and only round before drawing? Thank you for your reply. I've tried rounding it when I draw it however I am running into the same issue, the cooldown ends before the GUI shows it does.
April 2, 20205 yr Author An unideal fix I have found for this is to base my timer off of the length of the cooldown bar. I'm worried however that this will lead to unpredictable values aswell as my time not being entirely accurate.
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.