Jump to content

[1.15.2] How can I render a texture on top of the screen?


Alicrack

Recommended Posts

I want to overlay a texture on top of the screen, like carved pumpkins do when equipped or when a totem of undying is being used, and dont know how can i implement it. I tried looking inside of carved pumpkins code, totem of undying or anywhere else, but didnt find anything related. Also, I want implement this texture overlay behaviour through renderParticle method in my CustomParticle class

Edited by Alicrack
Link to comment
Share on other sites

54 minutes ago, Alicrack said:

I want to overlay a texture on top of the screen, like carved pumpkins do when equipped or when a totem of undying is being used, and dont know how can i implement it. I tried looking inside of carved pumpkins code, totem of undying or anywhere else, but didnt find anything related. Also, I want implement this texture overlay behaviour through renderParticle method in my CustomParticle class

I think, this is rendered as gui. So probably you need to subscribe on RenderGameOverlayEvent, but instead use Pre subclass, if you need to be behind the actual gui (not sure). Here is my code example:
 

@SubscribeEvent
public static void drawManaBar(RenderGameOverlayEvent.Post event) {
  if (event.getType().equals(ElementType.HEALTH)) {
    if (minecraft == null) {
    	minecraft = Minecraft.getInstance();
    }

    if (!Minecraft.isGuiEnabled()) {
    	return;
	}

    if (minecraft.world == null) {
    	return;
    }

    minecraft.getTextureManager().bindTexture(TestMod.MANA_BAR);

    RenderSystem.pushTextureAttributes();
    RenderSystem.enableAlphaTest(); //I experimented with these a lot, not sure it works now as intended.

    fullPartial = getCurrentMana()/getMaxMana();

    //Not sure this works well, but it's the main idea.
    bufferbuilder = Tessellator.getInstance().getBuffer();
    bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);

	//Here is actual render code:
    //Rendering empty part
    bufferbuilder.pos(80f, 20f, 0).tex(0f, 0f).endVertex();
    bufferbuilder.pos(120f, 20f, 0).tex(0.5f, 0f).endVertex();
    bufferbuilder.pos(120f, 20f + (1-fullPartial) * 80f, 0).tex(0.5f, 1-fullPartial).endVertex();
    bufferbuilder.pos(80f, 20f + (1-fullPartial) * 80f, 0).tex(0f, 1-fullPartial).endVertex();

    //Rendering full part
    bufferbuilder.pos(80f, 20f + (1-fullPartial) * 80f, 0).tex(0.5f, 1-fullPartial).endVertex();
    bufferbuilder.pos(120f, 20f + (1-fullPartial) * 80f, 0).tex(1f, 1-fullPartial).endVertex();
    bufferbuilder.pos(120f, 100f, 0).tex(1f, 1).endVertex();
    bufferbuilder.pos(80f, 100f, 0).tex(0.5f, 1).endVertex();

    bufferbuilder.finishDrawing();
    WorldVertexBufferUploader.draw(bufferbuilder);

    RenderSystem.disableAlphaTest();
    RenderSystem.popAttributes();

    minecraft.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION); //I'm using .Post event, but anyway gui breaks, if you won's do that.
  }    
}

 

Also you may look at other ElementType instances and find HELMET one there. I suspect, that's what you need.

 

You won't find any mention about rendering at pumpkin Block/Item instance, because, I believe, render is made through subscribing to event, so actual render code can be anywhere.

Edited by Dzuchun
GenderGameOverlayEvent, omg...
  • Like 1

Everything said above may be absolutely wrong. No rights reserved.

Link to comment
Share on other sites

13 minutes ago, Dzuchun said:

I think, this is rendered as gui. So probably you need to subscribe on GenderGameOverlayEvent, but instead use Pre subclass, if you need to be behind the actual gui (not sure). Here is my code example:
 


@SubscribeEvent
public static void drawManaBar(RenderGameOverlayEvent.Post event) {
  if (event.getType().equals(ElementType.HEALTH)) {
    if (minecraft == null) {
    	minecraft = Minecraft.getInstance();
    }

    if (!Minecraft.isGuiEnabled()) {
    	return;
	}

    if (minecraft.world == null) {
    	return;
    }

    minecraft.getTextureManager().bindTexture(TestMod.MANA_BAR);

    RenderSystem.pushTextureAttributes();
    RenderSystem.enableAlphaTest(); //I experimented with these a lot, not sure it works now as intended.

    fullPartial = getCurrentMana()/getMaxMana();

    //Not sure this works well, but it's the main idea.
    bufferbuilder = Tessellator.getInstance().getBuffer();
    bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);

	//Here is actual render code:
    //Rendering empty part
    bufferbuilder.pos(80f, 20f, 0).tex(0f, 0f).endVertex();
    bufferbuilder.pos(120f, 20f, 0).tex(0.5f, 0f).endVertex();
    bufferbuilder.pos(120f, 20f + (1-fullPartial) * 80f, 0).tex(0.5f, 1-fullPartial).endVertex();
    bufferbuilder.pos(80f, 20f + (1-fullPartial) * 80f, 0).tex(0f, 1-fullPartial).endVertex();

    //Rendering full part
    bufferbuilder.pos(80f, 20f + (1-fullPartial) * 80f, 0).tex(0.5f, 1-fullPartial).endVertex();
    bufferbuilder.pos(120f, 20f + (1-fullPartial) * 80f, 0).tex(1f, 1-fullPartial).endVertex();
    bufferbuilder.pos(120f, 100f, 0).tex(1f, 1).endVertex();
    bufferbuilder.pos(80f, 100f, 0).tex(0.5f, 1).endVertex();

    bufferbuilder.finishDrawing();
    WorldVertexBufferUploader.draw(bufferbuilder);

    RenderSystem.disableAlphaTest();
    RenderSystem.popAttributes();

    minecraft.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION); //I'm using .Post event, but anyway gui breaks, if you won's do that.
  }    
}

 

Also you may look at other ElementType instances and find HELMET one there. I suspect, that's what you need.

 

You won't find any mention about rendering at pumpkin Block/Item instance, because, I believe, render is made through subscribing to event, so actual render code can be anywhere.

Thanks,but I still do not understand what BufferBuilder is, also, do you have any learning material about rendering I can take lesson from?

Link to comment
Share on other sites

6 minutes ago, Alicrack said:

learning material about rendering I can take lesson from?

Here You are:

https://youtu.be/gZ-8F94UT7k

he uses BufferBuilder for rendering TE, but same can be done anywhere, you only need to accuire a correct BufferBuilder.

Of course, it's not complete guide, and someone may propose better one, would be gracefull, too.

  • Like 1

Everything said above may be absolutely wrong. No rights reserved.

Link to comment
Share on other sites

3 minutes ago, poopoodice said:

You can check ForgeInGameGui/InGameGui, there are a lot of similar rendering going on there.

 

2 minutes ago, Dzuchun said:

Here You are:

https://youtu.be/gZ-8F94UT7k

he uses BufferBuilder for rendering TE, but same can be done anywhere, you only need to accuire a correct BufferBuilder.

Of course, it's not complete guide, and someone may propose better one, would be gracefull, too.

Thank you for support, I already found carvedPumpkinOverlay in ForgeInGameGui and will use it

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I started a Forge server which is hosted by cloudnord (don't know it this information is necessary or not). Everything's working fine, the mods are getting loaded, I can join and play on it. Then I wanted to give myself OP. That's where the problems began. I typed "op mc_nicky_com" in the console and just saw, that I automatically disconnected... Weird, I thought and promptly updated the forge version to the client sided version, 47.2.17. Nothing resolved. Thought of downgrading the server to 47.2.0 but still didn't work. Now the server is on 47.2.0 and I can play without OP, which is totally fine but if I want to do something only OPs can do, I have to put it into the console, where I don't have auto-completion. The error it is throwing is the following: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(31613) + length(1) exceeds writerIndex(31613): UnpooledHeapByteBuf(ridx: 31613, widx: 31613, cap: 31613/31613) I don't know how to fix this and I am thankful for every help attempt that comes here.  With best regards nicky.gg
    • Official Website Link ➲➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/Zyy6WGX5-gA   Product Name ➲➲➲ Keto Candies ACV Gummies It assists with smothering undesirable food desires and close to home dietary patterns.   Official facebook Link ➲➲➲  https://www.facebook.com/KetoCandiesACVGummiesUS/   Official Blogs ➲➲➲ https://groups.google.com/a/chromium.org/g/chromium-reviews/c/4LZAdq7rQSg https://groups.google.com/g/mozilla.dev.platform/c/Uy2KvvUkCbA https://groups.google.com/g/mozilla.dev.platform/c/L-RBHHTlJm0 https://groups.google.com/g/comp.protocols.time.ntp/c/aqbT3woiM9w https://groups.google.com/g/comp.protocols.time.ntp/c/L3J_LIFnET0 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/Zyy6WGX5-gA https://groups.google.com/a/chromium.org/g/chromium-reviews/c/4LZAdq7rQSg https://keto-candies-acv-gummies-2b37b5.webflow.io/ https://keto-candies-acv-gummies-1.jimdosite.com/ https://groups.google.com/g/getketocandiesacvgummies/c/PaSsvPpQsYw https://groups.google.com/g/getketocandiesacvgummies/c/YLKzSrTdeRI   Blue Vibe CBD Gummies Official Links ➲➲➲  https://www.deccanherald.com/brandspot/sponsored-health/blue-vibe-cbd-gummies-reviews-moneyworth-product-or-not-blue-vibe-cbd-gummies-for-sale-consumer-reports-mega-sale-2673730 https://www.facebook.com/GetBlueVibeCBDGummiesUS/ https://www.facebook.com/BlueVibeCBDGummiesUS/ https://www.facebook.com/BlueVibeCBDGummiesInUS/ https://www.facebook.com/events/334310428943928 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/eq2xmAl5Mm4 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/yb2GhvIIBvI Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/LEwhDmgZLHs Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/gREHzPUfMsw Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/FNtpXHp_r7c Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/KqdhsIEuP8k Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/XfZtZqnG-rM Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/DGXPLV27qCU Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/t-W4cjZOFSs Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/i0Ta7Qy4izw
    • Make a test without practical_plushies_mobs, practical_plushies_animals and dark-waters - looks like it is not working with sinytra connector
    • VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi
    • Maybe your file codes are missing. Therefore it is crashing.
  • Topics

×
×
  • Create New...

Important Information

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