Started by
Ahlad Gameing
on
Topic category: Help with Minecraft modding (Java Edition)
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?
everything is possible, but what you want is not possible without coding, and the process is quite complicated.
I'm fine with coding
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.
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...
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:
and change it to:
then somewhere below you'll need to add a line
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.
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
It work fine but it makes the Food Bar bugged
yeah, i believe thats because the binded texture is not correct. add a line at the end of the above mentioned if block:
don't forget to import AbstractGui
when do i import AbstractGui each time i put it at the beginning, its just make an error
show me your code. also, which version of forge are you modding?
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);
}
}
}
}
?
yeah sorry, if you don't reply to my post i won't get notified.
put this line at top where the imports are:
and then put this line in at the end of that if statement: