Jump to content

Recommended Posts

Posted

Hello,

so I made a custom bar above the hunger bar, and sometimes it overrites vanilla's guis.

I already managed to move it up if the player is swimming/in water to make the air bar appear.

The problem is that when you get out the water the air bar keeps getting shown and i need to hide it.

I tried to do that but it doesnt work:

Spoiler

@SubscribeEvent
    public void render2(RenderGameOverlayEvent.Pre event) {
        Minecraft mc = Minecraft.getInstance();
        if (event.getType() == ElementType.AIR) {
            if(mc.player.getAir() < 20 && !(mc.player.areEyesInFluid(FluidTags.WATER)) && !(mc.player.isSwimming())) {
                event.setCanceled(true);
            }
        }
    }

I also need to check if the player is rinding an entity and get the entity's health.

In this case i will check if the health is > 2, and then if its true, render my hud above the entity health's bar.

How can I do that?

Thanks.

Posted
1 minute ago, cinsiian said:

The problem is that when you get out the water the air bar keeps getting shown and i need to hide it.

Post all of your code.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
18 minutes ago, cinsiian said:

Its in the spoiler..

That's not the code I was talking about but upon your further clarification I understand what you are trying to do. I thought the Air still rendering was a bug from something you were doing not it regenerating.

25 minutes ago, cinsiian said:

mc.player.getAir() < 20

This is your problem getAir() returns a value 0-300 not 0-20. The value represents the number of ticks you can breath in water.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
10 minutes ago, Animefan8888 said:

I thought the Air still rendering was a bug from something you were doing not it regenerating.

No its not, in 1.13 mojang made that you need to regenerate the air outside the water.

But yea, I fixed it. Now I just need to know

38 minutes ago, cinsiian said:

I also need to check if the player is rinding an entity and get the entity's health.

In this case i will check if the health is > 2, and then if its true, render my hud above the entity health's bar.

How can I do that?

Thanks.

 

Posted
39 minutes ago, cinsiian said:

I also need to check if the player is rinding an entity

Use Entity#getRidingEntity make sure it is not null in the case of health cast to LivingEntity.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
Spoiler

package cinsiian.urtima.proxy.client;

import cinsiian.urtima.util.ManaProvider;
import cinsiian.urtima.util.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.LivingEntity;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@OnlyIn(Dist.CLIENT)
public class ClientHandler {

	public final ResourceLocation TEXTURE = new ResourceLocation(Reference.MODID, "textures/gui/mana_hud.png");
	public int x, y;

	@SubscribeEvent
	public void renderOverlay(RenderGameOverlayEvent.Post event) {
		if (event.getType() == ElementType.POTION_ICONS) {
			Minecraft mc = Minecraft.getInstance();
			x = event.getWindow().getScaledWidth() / 2 + 10;
			y = event.getWindow().getScaledHeight() - 48;
			boolean isInWater = false;
			if (!(mc.player.isSpectator() || mc.player.isCreative())) {
				mc.getTextureManager().bindTexture(TEXTURE);	
				if (mc.player.isSwimming() || mc.player.areEyesInFluid(FluidTags.WATER)) {
					if (mc.player.getAir() < 1) {
						isInWater = false;
					} else {
						isInWater = true;
					}
				}
				if (mc.player.isAlive()) {
					drawBackground(isInWater);
				}
			}
			if(mc.player.getRidingEntity() != null) {
				if(mc.player.getRidingEntity() instanceof LivingEntity) {
					LivingEntity e = (LivingEntity) mc.player.getRidingEntity();
					if(e.getHealth() > 20) {
						isInWater = true;
					}
				}
			}
		}
	}
	
	@SubscribeEvent
	public void render2(RenderGameOverlayEvent.Pre event) {
		Minecraft mc = Minecraft.getInstance();
		if (event.getType() == ElementType.AIR) {
			if(mc.player.getAir() < mc.player.getMaxAir() && !(mc.player.areEyesInFluid(FluidTags.WATER)) && !(mc.player.isSwimming())) {
				event.setCanceled(true);
			}
		}
	}

	private void drawBackground(boolean isInWater) {
		this.drawMana(0, isInWater);
		this.drawMana(1, isInWater);
		this.drawMana(2, isInWater);
		this.drawMana(3, isInWater);
		this.drawMana(4, isInWater);
		this.drawMana(5, isInWater);
		this.drawMana(6, isInWater);
		this.drawMana(7, isInWater);
		this.drawMana(8, isInWater);
		this.drawMana(9, isInWater);
		this.drawMana(10, isInWater);
		this.drawMana(11, isInWater);
		this.drawMana(12, isInWater);
		this.drawMana(13, isInWater);
		this.drawMana(14, isInWater);
		this.drawMana(15, isInWater);
		this.drawMana(16, isInWater);
		this.drawMana(17, isInWater);
		this.drawMana(18, isInWater);
	}

	private void drawMana(int manaRequired, boolean isInWater) {
		Minecraft mc = Minecraft.getInstance();
		if (mc.player.getCapability(ManaProvider.MANA, null).orElseThrow(null).get() == manaRequired) {
			if (isInWater) {
				mc.ingameGUI.blit(x, y - 10, 0, manaRequired * 9, 80, 8);
			} else {
				mc.ingameGUI.blit(x, y, 0, manaRequired * 9, 80, 8);
			}

		}
	}

}

 

 

Posted
1 hour ago, cinsiian said:

Hello,

so I made a custom bar above the hunger bar, and sometimes it overrites vanilla's guis.

I already managed to move it up if the player is swimming/in water to make the air bar appear.

The problem is that when you get out the water the air bar keeps getting shown and i need to hide it.

I tried to do that but it doesnt work:

  Reveal hidden contents

@SubscribeEvent
    public void render2(RenderGameOverlayEvent.Pre event) {
        Minecraft mc = Minecraft.getInstance();
        if (event.getType() == ElementType.AIR) {
            if(mc.player.getAir() < 20 && !(mc.player.areEyesInFluid(FluidTags.WATER)) && !(mc.player.isSwimming())) {
                event.setCanceled(true);
            }
        }
    }

I also need to check if the player is rinding an entity and get the entity's health.

In this case i will check if the health is > 2, and then if its true, render my hud above the entity health's bar.

How can I do that?

Thanks.

Hey! If I am reading correctly, your bar gets moved, but after the player exits the water, the air bar is still there. I saw a similar effect after my post: 

It seems if you do not bind the texture to the ui ANYTIME you update it, it stays or renders odd. 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.