Started by
dkrdjdi
on
Topic category: User side tutorials
Create a simple procedure and apply the code there.
-
global trigger On player tick update
-
Enter the code editor in the procedure and import it.
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
-
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
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);
}
}
}
}
This is how it applies in in-game.
https://imgur.com/o4gCzrz
Hello, I couldn't figure out your guide, could you show the finished code or send me a photo of it?
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
It's isn't quite working for me, what did I do wrong?
https://www.dropbox.com/scl/fi/23sinfq9hp0bvewrcjlp5/CODE1.png?rlkey=4v…
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