Jump to content

[1.16] Need help with LayerRenderer


Recommended Posts


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:

	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) {
				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());
					flag = false;
		else {
			data.disableFlag = false;



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_) {

	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:


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

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

    • Also why roosters don't spawn naturally Shouldn't this do the thing? // CommonModEvents @SubscribeEvent public static void registerSpawnPlacements(SpawnPlacementRegisterEvent e) { e.register(_Entities.ROOSTER.get(), ON_GROUND, WORLD_SURFACE, AbstractChicken::canSpawn, AND); }   public static boolean canSpawn(EntityType<? extends AbstractChicken> entityType, LevelAccessor level, MobSpawnType spawnType, BlockPos pos, RandomSource random) { return entityType != _Entities.CHICK.get() && Animal.checkAnimalSpawnRules(entityType, level, spawnType, pos, random); }      
    • Hey guys, I was playing on my mod pack (1.16.5) and recently got this error when I wanted to enter the game and I don't understand it. I updated the mod thinking that was the problem, but it didn't work either, could someone so nice help me? Thank you --- Minecraft Crash Report ---- // Don't be sad, have a hug! <3 Time: 5/12/23 9:01 Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.fml.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:71) [?:?] {re:classloading}     at net.minecraftforge.fml.client.ClientModLoader.completeModLoading(ClientModLoader.java:174) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$null$1(Minecraft.java:508) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$5349/73334840.run(Unknown Source) [?:?] {}     at net.minecraft.util.Util.func_215077_a(Util.java:430) [?:?] {re:classloading,xf:OptiFine:default}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:504) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft$$Lambda$5082/1010480754.accept(Unknown Source) [?:?] {}     at net.minecraft.client.gui.ResourceLoadProgressGui.func_230430_a_(ResourceLoadProgressGui.java:172) [?:?] {re:classloading,xf:OptiFine:default}     at net.minecraft.client.renderer.GameRenderer.func_195458_a(GameRenderer.java:802) [?:?] {re:classloading,pl:accesstransformer:B,xf:OptiFine:default}     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:977) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:184) [?:?] {re:classloading,pl:runtimedistcleaner:A}     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51] {}     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51] {}     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51] {}     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:37) [forge-1.16.5-36.2.39.jar:36.2] {}     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$532/615830852.call(Unknown Source) [forge-1.16.5-36.2.39.jar:36.2] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details:     Minecraft Version: 1.16.5     Minecraft Version ID: 1.16.5     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_51, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 1409376656 bytes (1344 MB) / 2046820352 bytes (1952 MB) up to 2097152000 bytes (2000 MB)     CPUs: 2     JVM Flags: 9 total; -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=16M -Xmx1992m -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -XX:+IgnoreUnrecognizedVMOptions     ModLauncher: 8.1.3+8.1.3+main-8.1.x.c94d18ec     ModLauncher launch target: fmlclient     ModLauncher naming: srg     ModLauncher services:          /mixin-0.8.4.jar mixin PLUGINSERVICE          /eventbus-4.0.0.jar eventbus PLUGINSERVICE          /forge-1.16.5-36.2.39.jar object_holder_definalize PLUGINSERVICE          /forge-1.16.5-36.2.39.jar runtime_enum_extender PLUGINSERVICE          /accesstransformers-3.0.1.jar accesstransformer PLUGINSERVICE          /forge-1.16.5-36.2.39.jar capability_inject_definalize PLUGINSERVICE          /forge-1.16.5-36.2.39.jar runtimedistcleaner PLUGINSERVICE          /mixin-0.8.4.jar mixin TRANSFORMATIONSERVICE          /OptiFine_1.16.5_HD_U_G8.jar OptiFine TRANSFORMATIONSERVICE          /forge-1.16.5-36.2.39.jar fml TRANSFORMATIONSERVICE      FML: 36.2     Forge: net.minecraftforge:36.2.39     FML Language Providers:          javafml@36.2         minecraft@1     Mod List:          forge-1.16.5-36.2.39-client.jar                   |Minecraft                     |minecraft                     |1.16.5              |CREATE_REG|Manifest: NOSIGNATURE         YungsExtras-Forge-1.16.4-1.0.jar                  |YUNG's Extras                 |yungsextras                   |Forge-1.16.4-1.0    |CREATE_REG|Manifest: NOSIGNATURE         YungsApi-1.16.4-Forge-13.jar                      |YUNG's API                    |yungsapi                      |1.16.4-Forge-13     |CREATE_REG|Manifest: NOSIGNATURE         mowziesmobs-1.5.27.jar                            |Mowzie's Mobs                 |mowziesmobs                   |1.5.27              |CREATE_REG|Manifest: NOSIGNATURE         BetterDungeons-1.16.4-1.2.1.jar                   |YUNG's Better Dungeons        |betterdungeons                |1.16.4-1.2.1        |CREATE_REG|Manifest: NOSIGNATURE         BetterStrongholds-1.16.4-1.2.1.jar                |YUNG's Better Strongholds     |betterstrongholds             |1.16.4-1.2.1        |CREATE_REG|Manifest: NOSIGNATURE         sophisticatedbackpacks-1.16.5-     |Sophisticated Backpacks       |sophisticatedbackpacks        |1.16.5-  |CREATE_REG|Manifest: NOSIGNATURE         jei-1.16.5-                         |Just Enough Items             |jei                           |          |CREATE_REG|Manifest: NOSIGNATURE         byg-1.3.6.jar                                     |Oh The Biomes You'll Go       |byg                           |1.3.4               |CREATE_REG|Manifest: NOSIGNATURE         betternether_reforged-1.2.jar                     |Better Nether Reforged        |betternether                  |1.2                 |CREATE_REG|Manifest: NOSIGNATURE         forge-1.16.5-36.2.39-universal.jar                |Forge                         |forge                         |36.2.39             |CREATE_REG|Manifest: 22:af:21:d8:19:82:7f:93:94:fe:2b:ac:b7:e4:41:57:68:39:87:b1:a7:5c:c6:44:f9:25:74:21:14:f5:0d:90         twilightforest-1.16.5-4.0.546-universal.jar       |The Twilight Forest           |twilightforest                |NONE                |CREATE_REG|Manifest: NOSIGNATURE         BetterMineshafts-Forge-1.16.4-2.0.4.jar           |YUNG's Better Mineshafts      |bettermineshafts              |1.16.4-2.0.4        |CREATE_REG|Manifest: NOSIGNATURE         BetterCaves-Forge-1.16.4-1.1.2.jar                |YUNG's Better Caves           |bettercaves                   |1.16.4-1.1.2        |CREATE_REG|Manifest: NOSIGNATURE         geckolib-forge-1.16.5-3.0.106.jar                 |GeckoLib                      |geckolib3                     |3.0.106             |CREATE_REG|Manifest: NOSIGNATURE         DynamicSurroundings-1.16.5-            |§3Dynamic Surroundings        |dsurround                     |             |CREATE_REG|Manifest: NOSIGNATURE         journeymap-1.16.5-5.8.3.jar                       |Journeymap                    |journeymap                    |5.8.3               |CREATE_REG|Manifest: NOSIGNATURE         DungeonsArise-1.16.5-2.1.49-beta.jar              |When Dungeons Arise           |dungeons_arise                |2.1.49              |CREATE_REG|Manifest: NOSIGNATURE         citadel-1.8.1-1.16.5.jar                          |Citadel                       |citadel                       |1.8.1               |CREATE_REG|Manifest: NOSIGNATURE         untamedwilds-1.16.5-1.5.8.jar                     |Untamed Wilds                 |untamedwilds                  |1.5.8               |ERROR     |Manifest: NOSIGNATURE         iceandfire-2.1.12-1.16.5-patch-1.jar              |Ice and Fire                  |iceandfire                    |2.1.12-1.16.5-patch-|CREATE_REG|Manifest: NOSIGNATURE     Crash Report UUID: 5cfb2f17-4508-427f-9ef7-055c47f08891     OptiFine Version: OptiFine_1.16.5_HD_U_G8     OptiFine Build: 20210515-161946     Render Distance Chunks: 8     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: null     OpenGlVersion: 4.0.0 - Build     OpenGlRenderer: Intel(R) HD Graphics     OpenGlVendor: Intel     CpuCount: 2
    • idk how to reply here but no im not coding any mod, all of them are downloaded but its only gfs computer, on mine its ok and i was looking all around the internet and never seen anything similiar atleast  
    • I changed it to public static void but I can't find anyway to get level from the event even if it isn't a listener parameter. @JimiIT92
    • I didn't yet see this happening on 1.20.2 forge, but sadly, I noticed that my mod is incompatible with this version because of this event handler: @SubscribeEvent public static void onPlayerRightClickItem(PlayerInteractEvent.RightClickItem e) { if (e.getItemStack().getItem() instanceof EggItem) { List<ThrownEgg> eggs = e.getLevel().getEntitiesOfClass(ThrownEgg.class, new AABB(e.getEntity().blockPosition().immutable() .below(5) .north(5) .west(5), e.getEntity().blockPosition().immutable() .above(10) .south(5) .east(5))); if (!eggs.isEmpty()) { eggs.forEach(ThrownEgg::discard); if (!e.getEntity().getAbilities().instabuild) e.getItemStack().grow(1); } if (!e.getEntity().level().isClientSide) { ((ServerPlayer) e.getEntity()).connection.send( new ClientboundStopSoundPacket(SoundEvents.EGG_THROW.getLocation(), SoundSource.PLAYERS)); // Minecraft Forge 1.20.2 crashes because of NoSuchMethodError here } e.setCancellationResult(InteractionResult.SUCCESS); e.setCanceled(true); } }  
  • Topics

  • Create New...

Important Information

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