[Tutorial] How to hide player's health bar.

Started by dkrdjdi on

Topic category: User side tutorials

Last seen on 13:59, 12. Oct 2024
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] How to hide player's health bar.
Thu, 08/22/2024 - 14:44 (edited)

Create a simple procedure and apply the code there.

 

  1. global trigger On player tick update

    https://imgur.com/jRnLkea

  2. Enter the code editor in the procedure and import it.


     

    import net.minecraftforge.client.event.RenderGuiOverlayEvent;
    import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;

    https://imgur.com/rgLfgZa

     

  3. Paste the code you present at the bottom of this code and you're done.


     

        private static void execute(@Nullable Event event) {
        }

    ...


     

        private static void execute(@Nullable Event event) {
        }

     

    //+Add code

     

    @SubscribeEvent
        public static void onRenderGuiOverlay(RenderGuiOverlayEvent.Pre event) {
            if (event.getOverlay() == VanillaGuiOverlay.PLAYER_HEALTH.type()) {
                event.setCanceled(true);
            }
        }
    }
     


 

Just because you're hiding your health bar doesn't mean you're invincible.

It will be useful when creating a custom health bar.

Edited by dkrdjdi on Thu, 08/22/2024 - 14:44
Last seen on 13:59, 12. Oct 2024
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you want to hide your…
Thu, 08/22/2024 - 14:36

If you want to hide your health bar only when you have an item in your hand, you need to add a code.

https://imgur.com/ACYlNi4

 

+Add import

import net.minecraft.world.item.Items;

import net.minecraft.world.item.ItemStack; 

import net.minecraft.world.entity.LivingEntity; 

import net.minecraft.world.entity.Entity;

 

 

+Add code

Entity entity = net.minecraft.client.Minecraft.getInstance().player; 

if (entity instanceof LivingEntity _livEnt && _livEnt.getMainHandItem().getItem() == Items.item tag name) { event.setCanceled(true);

 }

 }

 }

 }

 

Last seen on 16:35, 7. Sep 2024
Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hello, I couldn't figure out…
Mon, 09/02/2024 - 02:41

Hello, I couldn't figure out your guide, could you show the finished code or send me a photo of it?

Last seen on 16:35, 7. Sep 2024
Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No longer necessary, my…
Mon, 09/02/2024 - 02:47

No longer necessary, my translator translated the information very poorly and I couldn't understand it, but after turning it off I was able to understand everything, thanks for the guide

 

Last seen on 13:59, 12. Oct 2024
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
    private static void…
Wed, 10/09/2024 - 01:58

    private static void execute(@Nullable Event event) {
    }
} ← X
There are two "}"s.
Please remove one and put it in the last row.

 

https://imgur.com/Il50U25