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

Started by dkrdjdi on

Topic category: User side tutorials

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
[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
Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
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);

 }

 }

 }

 }

 

Active 7 months ago
Joined Dec 2021
Points:
466

User statistics:

  • Modifications: 0
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 5
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?

Active 7 months ago
Joined Dec 2021
Points:
466

User statistics:

  • Modifications: 0
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 5
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

 

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
    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

Active 3 weeks ago
Joined Feb 2016
Points:
741

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 58
Hey mate, thanks for this…
Sat, 11/02/2024 - 10:54

Hey mate, thanks for this awesome tutorial, and i would like to know if you have any idea on how i could set it to a variable instead of an item? because i have a button that would switch it to the new hud and the vanilla one depending on that logic variable, it would help a lot!

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
It does not work in version…
Mon, 11/04/2024 - 12:58

It does not work in version 1.21.1.

First of all, Vanilla Gui Overlay
I confirmed that it was changed to Vanilla Gui Layers,

RenderGuiOverlayEvent
Changed to RenderGuiLayerEvent.

However, even if you change it like this, it doesn't work in-game.

Active 3 weeks ago
Joined Feb 2016
Points:
741

User statistics:

  • Modifications: 0
  • Forum topics: 1
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 58
ah i see, well im using 1.20…
Wed, 11/06/2024 - 18:03

ah i see, well im using 1.20.1, i think it could work?

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
It's hard to check because I…
Thu, 11/07/2024 - 12:34

It's hard to check because I updated the MCreator to the latest version...

The code was created through a question with AI.

If the name of the global variable is "bar"
This is how the code works.
However, there is a possibility that there is a build error or it will not work because it cannot be verified.

@SubscribeEvent
public void onRenderOverlay(RenderGameOverlayEvent.Post event) {
   if ("bar".equals(true)) {  //global variable is "bar"
       if (event.getType() == RenderGameOverlayEvent.ElementType.HEALTH) {
           event.setCanceled(true);
       }
   }
}
 

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
If there is a build error,…
Thu, 11/07/2024 - 12:37

If there is a build error, if you share that code and the build error content in ChatGPT, it will tell you what to add or how to fix the code.

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
Maybe it's better to add it…
Thu, 11/07/2024 - 12:41

Maybe it's better to add it like this than to use it on top.


@SubscribeEvent
    public static void onRenderGuiOverlay(RenderGuiOverlayEvent.Pre event) {
      if ("bar".equals(true)) {  //global variable is "bar"
        if (event.getOverlay() == VanillaGuiOverlay.PLAYER_HEALTH.type()) {
            event.setCanceled(true);
        }
    }
}

 

Active 1 week ago
Joined May 2013
Points:
905

User statistics:

  • Modifications: 0
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 110
if ("bar".equals(true)) {  /…
Thu, 11/07/2024 - 12:44

if ("bar".equals(true)) {  //global variable is "bar"
ChatGPT informed me to use below code if this code doesn't work.


if (MCreatorVariables.bar) {

I wish you all the best :)