Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)
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.

Posted
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?

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

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

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