How would I make a custom Heart?

Started by Ahlad Gameing on

Topic category: Help with Minecraft modding (Java Edition)

Active 8 months ago
Joined Mar 2021
Points:
555

User statistics:

  • Modifications: 0
  • Forum topics: 2
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
How would I make a custom Heart?

I am making a space related dimension where you need a certain armor set and an oxygen canister in your offhand to not die (which I have already done), but I want your hearts to switch textures, similar to poison and withered, whenever you don't have the armor equipped, is it even possible?

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
everything is possible, but…
Mon, 03/15/2021 - 12:53

everything is possible, but what you want is not possible without coding, and the process is quite complicated.

Active 8 months ago
Joined Mar 2021
Points:
555

User statistics:

  • Modifications: 0
  • Forum topics: 2
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 3
I'm fine with coding
Mon, 03/15/2021 - 22:21

I'm fine with coding

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
you're gonna need to hook…
Tue, 03/16/2021 - 02:11

you're gonna need to hook net.minecraftforge.client.event.RenderGameOverlayEvent event, check if the event element type is ElementType.HEALTH, if so, cancel it, get the screen resolution and start drawing your own hearts.

to start yourself off, you could create an overlay in mcreator, draw the hearts there, save and build it, and then edit that overlay's code. in that code you will find its checking for ElementType.HELMET, change it to HEALTH, cancel the event, then modify the code as needed.

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
HUH did u say that u can…
Mon, 03/22/2021 - 02:28

HUH did u say that u can cancel de Health bar?!????, please show me how. i need that, u know, when you make a mod with player that have over 300 HP and need to remove health bar cuz it hide 4/9 of ur screen...

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
like I said, start yourself…
Mon, 03/22/2021 - 06:30

like I said, start yourself off with creating an overlay in mcreator. use "add images" to add little hearts that you made, or just put one image at the start position of your new health bar. save and build the overlay.

next you'll have to edit the overlay's code. find the line: 

if (!event.isCancelable() && event.getType() == RenderGameOverlayEvent.ElementType.HELMET) {

and change it to:

if (event.isCancelable() && event.getType() == RenderGameOverlayEvent.ElementType.HEALTH) {

then somewhere below you'll need to add a line

event.setCanceled(true);

to cancel forge drawing the health bar. 

next you'll need to write your own code to calculate where to draw your new health bar. the start position is already there in the code when you used the "add images" in the mcreator overlay creation gui.

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
is something like this ok…
Tue, 03/23/2021 - 20:41

is something like this ok for an overlay(about the Ki bar, dont worry its just some kind of energy)Imgur: The magic of the Internet

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
It work fine but it makes…
Tue, 03/23/2021 - 20:51

It work fine but it makes the Food Bar bugged

 

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
yeah, i believe thats…
Wed, 03/24/2021 - 07:49

yeah, i believe thats because the binded texture is not correct. add a line at the end of the above mentioned if block:

Minecraft.getInstance().getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);

don't forget to import AbstractGui

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
when do i import AbstractGui…
Mon, 03/29/2021 - 20:54

when do i import AbstractGui each time i put it at the beginning, its just make an error

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
show me your code. also,…
Tue, 03/30/2021 - 16:00

show me your code. also, which version of forge are you modding?

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
sorry im late. its 1.15.2: …
Wed, 04/07/2021 - 01:20

sorry im late. its 1.15.2:

package net.mcreator.dbm.gui.overlay;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.api.distmarker.Dist;

import net.minecraft.world.World;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.client.Minecraft;

import net.mcreator.dbm.DbmModVariables;
import net.mcreator.dbm.DbmModElements;

@DbmModElements.ModElement.Tag
public class InfoBarOverlay extends DbmModElements.ModElement {
    public InfoBarOverlay(DbmModElements instance) {
        super(instance, 44);
    }

    @Override
    public void initElements() {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent(priority = EventPriority.NORMAL)
    public void eventHandler(RenderGameOverlayEvent event) {
        if (event.isCancelable() && event.getType() == RenderGameOverlayEvent.ElementType.HEALTH) {
            event.setCanceled(true);
            int posX = (event.getWindow().getScaledWidth()) / 2;
            int posY = (event.getWindow().getScaledHeight()) / 2;
            PlayerEntity entity = Minecraft.getInstance().player;
            World world = entity.world;
            double x = entity.getPosX();
            double y = entity.getPosY();
            double z = entity.getPosZ();
            if (true) {
                Minecraft.getInstance().fontRenderer.drawString("Ki:", posX + -207, posY + -103, -16724737);
                Minecraft.getInstance().fontRenderer.drawString(""
                        + (int) ((entity.getCapability(DbmModVariables.PLAYER_VARIABLES_CAPABILITY, null)
                                .orElse(new DbmModVariables.PlayerVariables())).Ki)
                        + "/" + (int) ((entity.getCapability(DbmModVariables.PLAYER_VARIABLES_CAPABILITY, null)
                                .orElse(new DbmModVariables.PlayerVariables())).KiMax)
                        + " ", posX + -198, posY + -103, -16724737);
                Minecraft.getInstance().fontRenderer.drawString("Health:", posX + -207, posY + -112, -16724890);
                Minecraft.getInstance().fontRenderer.drawString(""
                        + (int) ((entity.getCapability(DbmModVariables.PLAYER_VARIABLES_CAPABILITY, null)
                                .orElse(new DbmModVariables.PlayerVariables())).Health)
                        + "/" + (int) ((entity.getCapability(DbmModVariables.PLAYER_VARIABLES_CAPABILITY, null)
                                .orElse(new DbmModVariables.PlayerVariables())).HealthMax)
                        + "", posX + -180, posY + -112, -16724890);
            }
        }
    }
}

 

Active 6 hours ago
Joined Mar 2020
Points:
1168

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
?
Sat, 05/22/2021 - 16:27

?

Active 3 years ago
Joined Nov 2019
Points:
867

User statistics:

  • Modifications: 0
  • Forum topics: 8
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 387
yeah sorry, if you don't…
Sat, 05/22/2021 - 17:40

yeah sorry, if you don't reply to my post i won't get notified.

put this line at top where the imports are:

import net.minecraft.client.gui.AbstractGui;

and then put this line in at the end of that if statement:

if (event.isCancelable() && event.getType() == RenderGameOverlayEvent.ElementType.HEALTH) {

    ...

    Minecraft.getInstance().getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);
}

 

Active 3 months ago
Joined Aug 2019
Points:
667

User statistics:

  • Modifications: 0
  • Forum topics: 4
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 7
I can't code the armor bar. …
Thu, 01/06/2022 - 22:32
I can't code the armor bar. 
If I had written ALL and I wrote ARMOR instead. So I wrote a mistake.
Here is the code:
if (event.getType () == RenderGameOverlayEvent.ElementType.ARMOR)