Jump to content

[1.14.4] HUD adaptation


cinsiian

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

4 minutes ago, cinsiian said:

Do horse health work like player health?

I believe so. Post 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.

Link to comment
Share on other sites

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);
			}

		}
	}

}

 

 

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

15 minutes ago, cinsiian said:

if(e.getHealth() > 20) { isInWater = true; }

You don't actually do anything what did you expect to happen?

  • Thanks 1

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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