Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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...

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

  • Author
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?

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.

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

  • Author
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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.