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
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!
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.
ah i see, well im using 1.20.1, i think it could work?
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);
}
}
}
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.
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);
}
}
}
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 :)