[1.15.x] Added entity nameplate rendering event hook (#6416)
This commit is contained in:
parent
380366e25f
commit
345387645e
5 changed files with 142 additions and 16 deletions
|
@ -0,0 +1,15 @@
|
|||
--- a/net/minecraft/client/renderer/entity/EntityRenderer.java
|
||||
+++ b/net/minecraft/client/renderer/entity/EntityRenderer.java
|
||||
@@ -54,8 +54,10 @@
|
||||
}
|
||||
|
||||
public void func_225623_a_(T p_225623_1_, float p_225623_2_, float p_225623_3_, MatrixStack p_225623_4_, IRenderTypeBuffer p_225623_5_, int p_225623_6_) {
|
||||
- if (this.func_177070_b(p_225623_1_)) {
|
||||
- this.func_225629_a_(p_225623_1_, p_225623_1_.func_145748_c_().func_150254_d(), p_225623_4_, p_225623_5_, p_225623_6_);
|
||||
+ net.minecraftforge.client.event.RenderNameplateEvent renderNameplateEvent = new net.minecraftforge.client.event.RenderNameplateEvent(p_225623_1_,p_225623_1_.func_145748_c_().func_150254_d(), p_225623_4_, p_225623_5_);
|
||||
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(renderNameplateEvent);
|
||||
+ if (renderNameplateEvent.getResult() != net.minecraftforge.eventbus.api.Event.Result.DENY && (renderNameplateEvent.getResult() == net.minecraftforge.eventbus.api.Event.Result.ALLOW || this.func_177070_b(p_225623_1_))) {
|
||||
+ this.func_225629_a_(p_225623_1_, renderNameplateEvent.getContent(), p_225623_4_, p_225623_5_, p_225623_6_);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
|
||||
public abstract class RenderLivingEvent<T extends LivingEntity, M extends EntityModel<T>> extends Event
|
||||
{
|
||||
|
||||
private final LivingEntity entity;
|
||||
private final LivingRenderer<T, M> renderer;
|
||||
private final float partialRenderTick;
|
||||
|
@ -51,24 +52,10 @@ public abstract class RenderLivingEvent<T extends LivingEntity, M extends Entity
|
|||
{
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, MatrixStack matrixStack){ super(entity, renderer, partialRenderTick, matrixStack); }
|
||||
}
|
||||
|
||||
public static class Post<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, float partialRenderTick, MatrixStack matrixStack){ super(entity, renderer, partialRenderTick, matrixStack); }
|
||||
}
|
||||
|
||||
// TODO: 1.15 moved all name rendering to EntityRenderer, such that there's not a Living-specific feature anymore
|
||||
public abstract static class Specials<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
public Specials(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, 0, matrixStack); }
|
||||
|
||||
@Cancelable
|
||||
public static class Pre<T extends LivingEntity, M extends EntityModel<T>> extends Specials<T, M>
|
||||
{
|
||||
public Pre(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); }
|
||||
}
|
||||
public static class Post<T extends LivingEntity, M extends EntityModel<T>> extends Specials<T, M>
|
||||
{
|
||||
public Post(LivingEntity entity, LivingRenderer<T, M> renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* RenderNameplateEvent is fired whenever the entity renderer attempts to render a name plate/tag of an entity.
|
||||
* <br>
|
||||
* {@link #nameplateContent} contains the content being rendered on the name plate/tag. This can be changed by mods.<br>
|
||||
* {@link #originalContent} contains the original content being rendered on the name plate/tag. This cannot be
|
||||
* changed by mods.<br>
|
||||
* {@link #matrixStack} contains the matrix stack instance involved in rendering the name plate/tag. This cannot
|
||||
* be changed by mods.<br>
|
||||
* {@link #renderTypeBuffer} contains the render type buffer instance involved in rendering the name plate/tag.
|
||||
* This cannot be changed by mods.<br>
|
||||
* <br>
|
||||
* This event has a result. {@link HasResult}. <br>
|
||||
* ALLOW will force-render name plate/tag, DEFAULT will ignore the hook and continue using the vanilla check
|
||||
* & DENY will prevent name plate/tag from rendering<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
@Event.HasResult
|
||||
public class RenderNameplateEvent extends EntityEvent
|
||||
{
|
||||
|
||||
private String nameplateContent;
|
||||
private final String originalContent;
|
||||
private final MatrixStack matrixStack;
|
||||
private final IRenderTypeBuffer renderTypeBuffer;
|
||||
|
||||
public RenderNameplateEvent(Entity entity, String content, MatrixStack matrixStack, IRenderTypeBuffer renderTypeBuffer)
|
||||
{
|
||||
super(entity);
|
||||
this.originalContent = content;
|
||||
this.setContent(this.originalContent);
|
||||
this.matrixStack = matrixStack;
|
||||
this.renderTypeBuffer = renderTypeBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content that is to be rendered on the name plate/tag
|
||||
*/
|
||||
public void setContent(String contents)
|
||||
{
|
||||
this.nameplateContent = contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* The content being rendered on the name plate/tag
|
||||
*/
|
||||
public String getContent()
|
||||
{
|
||||
return this.nameplateContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original content being rendered on the name plate/tag
|
||||
*/
|
||||
public String getOriginalContent()
|
||||
{
|
||||
return this.originalContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The matrix stack used during the rendering of the name plate/tag
|
||||
*/
|
||||
public MatrixStack getMatrixStack()
|
||||
{
|
||||
return this.matrixStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* The render type buffer used during the rendering of the name plate/tag
|
||||
*/
|
||||
public IRenderTypeBuffer getRenderTypeBuffer()
|
||||
{
|
||||
return this.renderTypeBuffer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package net.minecraftforge.debug.client.rendering;
|
||||
|
||||
import net.minecraft.entity.passive.CowEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.client.event.RenderNameplateEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod("nameplate_render_test")
|
||||
@Mod.EventBusSubscriber
|
||||
public class NameplateRenderingEventTest
|
||||
{
|
||||
|
||||
static final boolean ENABLED = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onNameplateRender(RenderNameplateEvent event)
|
||||
{
|
||||
|
||||
if(!ENABLED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.getEntity() instanceof CowEntity)
|
||||
{
|
||||
event.setContent(TextFormatting.RED + "Evil Cow");
|
||||
event.setResult(Event.Result.ALLOW);
|
||||
}
|
||||
|
||||
if(event.getEntity() instanceof PlayerEntity)
|
||||
{
|
||||
event.setContent(TextFormatting.GOLD + "" + (event.getEntity()).getDisplayName().getString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,4 +54,6 @@ loaderVersion="[28,)"
|
|||
[[mods]]
|
||||
modId="forgedebugmultilayermodel"
|
||||
[[mods]]
|
||||
modId="trsr_transformer_test"
|
||||
modId="trsr_transformer_test"
|
||||
[[mods]]
|
||||
modId="nameplate_render_test"
|
Loading…
Reference in a new issue