How would I make a custom Heart?

Started by Ahlad Gameing on

Topic category: Help with modding (Java Edition)

Last seen on 13:16, 30. Mar 2021
Joined Mar 2021
Points:

User statistics:

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

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

Last seen on 13:16, 30. Mar 2021
Joined Mar 2021
Points:

User statistics:

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

I'm fine with coding

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

It work fine but it makes the Food Bar bugged

 

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

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

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

 

Last seen on 16:35, 26. Apr 2024
Joined Mar 2020
Points:

User statistics:

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

?

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

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

 

Last seen on 22:32, 6. Dec 2023
Joined Aug 2019
Points:

User statistics:

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