Jump to content

[1.15.2] Using doubles for decrementing a HUD bar


ultra_reemun

Recommended Posts

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
Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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