Jump to content

[1.16] Need help with LayerRenderer


Tavi007

Recommended Posts

Hello!

I've been trying to add a special LayerRenderer, but I ran into a few problems. I want a layer that
1. can be applied to any LivingEntity.
2. is applied for a limited duration.
3. has a green, but also transparent, texture.
4. is the outermost layer.

My ultimate goal is to have a green flash, similar to the red flash, that happens, when the entity gets damaged. If you know of another method besides layers, please let me know.

I already tried to implement the renderer myself and this is my current state:

In RenderEvents.java:

	@SubscribeEvent
	public static void onRenderLivingEventPre(RenderLivingEvent.Pre<LivingEntity, EntityModel<LivingEntity>> event) {
		LivingEntity entityIn = event.getEntity();
		ImmersionData data = (ImmersionData) entityIn.getCapability(ImmersionDataCapability.IMMERSION_DATA_CAPABILITY, null).orElse(new ImmersionData());
		if(entityIn.hurtTime > 0) {
			if (data.disableFlag) {
				data.setHurtTime(entityIn.hurtTime);
				entityIn.hurtTime = 0; //desync client and server hurtTime. Is this a problem?

				//to do: add green overlay texture
				if (flag) {
					TransparentGreenLayer layer = new TransparentGreenLayer(event.getRenderer());
					event.getRenderer().addLayer(layer);
					flag = false;
				}
			}
		}
		else {
			data.disableFlag = false;
		}

	}

TransparentGreenLayer.java:

public class TransparentGreenLayer extends LayerRenderer<LivingEntity, EntityModel<LivingEntity>> {
	
	private final ResourceLocation transparentGreenTexture = new ResourceLocation(ElementalCombat.MOD_ID, "textures/models/transparent_green.png");
	
	public TransparentGreenLayer(IEntityRenderer<LivingEntity, EntityModel<LivingEntity>> p_i226040_1_) {
		super(p_i226040_1_);
	}

	@Override
	public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, LivingEntity entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
		if (!entitylivingbaseIn.isInvisible()) {
			renderCutoutModel(this.getEntityModel(), transparentGreenTexture, matrixStackIn, bufferIn, packedLightIn, entitylivingbaseIn, 1.0F, 1.0F, 1.0F);
		}
	}
}

Rest can be found here (https://github.com/Tavi007/ElementalCombat/tree/testingGreenFlash)

 

Currently the layer will be applied, but it's not transparent and once applied will stay permanently. Also it's applied to all entities (of the same type) simultaneously and some layers are applied after mine. The result looks like this:
 

image.png.8fa85914d4596f9f6685a357ac22e190.png


So can anyone help me please? :)

Link to comment
Share on other sites

Okay, which event would be better suited for adding the layer? And you mean, I need to add a check in TransparentGreenLayer#render ?

As for the red flash, I found the following.
From LivingRenderer:

public void render(T entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) {
      
		...
      
      if (rendertype != null) {
         IVertexBuilder ivertexbuilder = bufferIn.getBuffer(rendertype);
         int i = getPackedOverlay(entityIn, this.getOverlayProgress(entityIn, partialTicks));
         this.entityModel.render(matrixStackIn, ivertexbuilder, packedLightIn, i, 1.0F, 1.0F, 1.0F, flag1 ? 0.15F : 1.0F);
      }
   }

   public static int getPackedOverlay(LivingEntity livingEntityIn, float uIn) {
      return OverlayTexture.getPackedUV(OverlayTexture.getU(uIn), OverlayTexture.getV(livingEntityIn.hurtTime > 0 || livingEntityIn.deathTime > 0));
   }

	...
}

Following the stacktrace to IVertexBuilder I found this part:


   default IVertexBuilder overlay(int overlayUV) {
      return this.overlay(overlayUV & '\uffff', overlayUV >> 16 & '\uffff');
   }

The input in overla() is the same as the return value from getPackedOverlay(). I don't really understand, what the method from IVertexBuilder does here, nor do I not understand how I could use it to change the red color to a green one...

 

Link to comment
Share on other sites

21 hours ago, diesieben07 said:

At startup, so probably FMLClientSetupEvent with enqueueWork.

I'm a bit puzzled right now. Do I have to add the layer to every LivingEntityRenderer using a loop or are the 'base' classes MobRenderer and PlayerRenderer enough? In both cases I do not understand, how to do this exactly. All I know is Minecraft#getInstance().getRenderManager()...

I do get, that moving the logic to the render function will fix the problem with the infinite duration. But what about the semi transparent texture? Will that even work this way?

Besides what about the vanilla way. Reading through the minecraft code I didn't found a way to use the vanilla OverlayTexture directly. Or did you notice something?

Link to comment
Share on other sites

9 hours ago, diesieben07 said:

Loop through ForgeRegistries.ENTITIES to get all entities.

That didn't really help, because I don't know how I would get the renderer for each entity. I might have found an other solution. I added this to my FMLClientSetupEvent subscriber:

		Minecraft.getInstance().getRenderManager().renderers.forEach((entityType, entityRenderer) -> {
			if(entityRenderer instanceof LivingRenderer<?, ?>) {
				LivingRenderer<LivingEntity, EntityModel<LivingEntity>> livingRenderer = (LivingRenderer<LivingEntity, EntityModel<LivingEntity>>) entityRenderer;
				livingRenderer.addLayer(new TransparentGreenLayer(livingRenderer));
			}
		});

and it did add the layer to the vanilla mobs (I tested it with a drowned). However I got 2 warnings doing this ('resource' for Minecraft.getInstance() and 'unchecked' for the cast.) I fear, that this could lead to a crash at some point. Also I'm unsure, if the layer will be added to other modded livingEntities, since I'm not using a forgeRegistry. I would feel much safer, if I could get the same loop via ForgeRegistries.ENTITIES.

On another note. Currently the added layer isn't transparent, even though the texture is. If I change the texture to be completly transparent, it seems to be working, cause I couldn't see any layer, but the code was running (tested with a breakpoint). So are semi-transparent texture simply not working as a layer? That would be bad for my case and it would make my ultimate goal impossible (at least with a layer). @diesieben07 do you know someone, who has more insight on that matter?

Link to comment
Share on other sites

For Minecraft.getInstance(): Resource leak: '<unassigned Closeable value>' is not closed at this location
For the cast: Type safety: Unchecked cast from EntityRenderer<capture#2-of ?> to LivingRenderer<LivingEntity,EntityModel<LivingEntity>>

and I casted it, because the normal EntityRenderer does not have the addLayer method.

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

You casted it to something you cannot guarantee. You checked if its a LivingRenderer<?, ?>, but thats not what you casted it to.

LivingRenderer has the following definition:

public abstract class LivingRenderer<T extends LivingEntity, M extends EntityModel<T>> extends EntityRenderer<T> implements IEntityRenderer<T, M>
So I should be safe to cast it to LivingRenderer<LivingEntity, EntityModel<LivingEntity>> and will never crash, right?

Also what about my other questions? To summarize my open questions:
- Do semi-transparent texture work as a layer?
- Will the layer be added to all LivingEntities (vanilla and modded) using the current method? If not, how can I get the LivingRenderer from the LivingEntity?
- How can I make my layer be the outermost layer?

If you do not know the answere to some of these, it's not a problem. But maybe you know someone, who might know the solution.

Maybe a better solution would be to have another event hook added/move the .pre-event right before this.entityModel.render() is called in LivingRenderer#render. This way one could make last second changes to the rendering (and I could change the used OverlayTexture). Just to throw this idea in...

Link to comment
Share on other sites

I know that my question is a general java problem and that this forum should not be used as a java tutorial...

 

I thought I would be fine, since T extends LivingEntity and M extends EntityModel<LivingEntity>. So if my renderer is an instance of LivingRenderer, shouldn't be the types T and M at least be LivingEntity and EntityModel ?

Link to comment
Share on other sites

Well TIL.

Before I fix this problem, I would like to know, if my idea with the layer will even work. I've added this to my TextureLayer class:

	protected static <T extends LivingEntity> void renderCutoutModel(EntityModel<T> modelIn, ResourceLocation textureLocationIn, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn, T entityIn, float red, float green, float blue) {
		IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RenderType.getEntityCutoutNoCull(textureLocationIn));
		modelIn.render(matrixStackIn, ivertexbuilder, packedLightIn, LivingRenderer.getPackedOverlay(entityIn, 0.0F), red, green, blue, 0.01F);
	}

so i can change the alpha value and see if this will affect the tranparency of my layer. Sadly that didn't do much.

I've also read further into the vanilla render to see when exactly the color changes (and how). I don't really get how that packedOverlay integer changes the color. Normally it has the value 655360 and if hurttime>0 it has the value 196608. Adding this:

ResourceLocation texturLocation = event.getRenderer().getEntityTexture(entityIn);
RenderType rendertype = event.getRenderer().getEntityModel().getRenderType(texturLocation);
IVertexBuilder ivertexbuilder = event.getBuffers().getBuffer(rendertype);
event.getRenderer().getEntityModel().render(event.getMatrixStack(),
	ivertexbuilder, 
	event.getLight(), 
	655360,
	0.0F, 1.0F, 0.0F, 1.0F);

to my LvingRender hook I was able to play around with packedOverlay value a bit more (tho the actual entity looks messed up. But I was only interessted in the overlay color). I could create a white overlay if I set the value to 1655360, but not any other color. Again, I don't understand how these numbers are used while rendering. I could however make the entity look greenish, by reducing the red and blue color (currently both are set to 0).
Not that it matters, because I can't change them on the real model render anyway. :(

I'm losing hope, that this feature will work :/
Thank god, it isn't something fundamental, but I would have been really nice to have this included.
 

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

    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Slot Aster88 adalah bocoran slot rekomendasi gacor dari Aster88 yang bisa anda temukan di SLOT Aster88. Situs SLOT Aster88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Aster88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Aster88 merupakan SLOT Aster88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Aster88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Aster88 hari ini yang telah disediakan SLOT Aster88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Aster88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Aster88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Aster88 di link SLOT Aster88.
    • 🚀Link Daftar Klik Disini🚀 Tips Bermain Slot Bank Jago agar Meraih Maxwin dan Jackpot di MAXWINBET77 Bermain slot online Bank jago adalah cara yang seru dan mengasyikkan untuk mencari keuntungan besar di MAXWINBET77. Jika kamu ingin meningkatkan peluangmu untuk meraih maxwin dan jackpot secara terus-menerus, ada beberapa tips dan strategi yang bisa kamu terapkan. Berikut adalah panduan lengkapnya: Pilih Slot dengan RTP Tinggi: RTP (Return to Player) adalah persentase rata-rata dari total taruhan yang dikembalikan kepada pemain sebagai kemenangan. Pilihlah mesin slot Bank jago yang memiliki RTP tinggi, karena ini meningkatkan peluangmu untuk meraih kemenangan dalam jangka panjang. Kenali Fitur Bonus: Setiap slot Bank jago memiliki fitur bonus yang berbeda, seperti putaran gratis, simbol liar (wild), dan bonus game. Pelajari dengan baik fitur-fitur ini karena mereka dapat membantu meningkatkan peluang meraih kemenangan besar. Kelola Taruhan dengan Bijak: Tentukan batasan taruhan yang sesuai dengan budget dan jangan tergoda untuk bertaruh melebihi kemampuan finansialmu. Terapkan strategi taruhan yang bijak untuk memaksimalkan penggunaan saldo. Mainkan Slot Bank jago Progresif: Jika tujuanmu adalah meraih jackpot besar, coba mainkan slot Bank jago progresif di MAXWINBET77. Jackpot pada jenis slot Bank ini terus bertambah seiring dengan taruhan pemain lainnya, sehingga dapat mencapai jumlah yang sangat besar. Manfaatkan Promosi dan Bonus: MAXWINBET77 sering kali menawarkan promosi dan bonus kepada pemainnya. Manfaatkan bonus-bonus ini untuk meningkatkan peluangmu meraih kemenangan tanpa menggunakan modal tambahan. Berkonsentrasi dan Bersabar: Fokuslah saat bermain slot bank jago dan jangan terburu-buru. Bersabarlah meskipun tidak langsung mendapatkan hasil yang diharapkan. Kadang-kadang diperlukan waktu dan keberuntungan untuk mencapai maxwin atau jackpot. Baca Aturan Permainan: Sebelum bermain, pastikan untuk membaca aturan dan pembayaran pada slot Bank Jago yang dipilih. Mengetahui cara kerja mesin slot akan membantu mengoptimalkan strategi bermainmu. Dengan menerapkan tips-tips di atas dan tetap bermain secara bertanggung jawab, kamu dapat meningkatkan peluang meraih maxwin dan jackpot di Slot Bank Jago MAXWINBET77. Selamat bermain dan semoga sukses meraih kemenangan besar Anda Hari Ini.
  • Topics

×
×
  • Create New...

Important Information

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