Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by ultra_reemun
Fixed code

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

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.