diff --git a/patches/minecraft/net/minecraft/client/renderer/entity/EntityRenderer.java.patch b/patches/minecraft/net/minecraft/client/renderer/entity/EntityRenderer.java.patch new file mode 100644 index 000000000..fe0121446 --- /dev/null +++ b/patches/minecraft/net/minecraft/client/renderer/entity/EntityRenderer.java.patch @@ -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_); + } + } + diff --git a/src/main/java/net/minecraftforge/client/event/RenderLivingEvent.java b/src/main/java/net/minecraftforge/client/event/RenderLivingEvent.java index 8727f26c2..16d596ea5 100644 --- a/src/main/java/net/minecraftforge/client/event/RenderLivingEvent.java +++ b/src/main/java/net/minecraftforge/client/event/RenderLivingEvent.java @@ -28,6 +28,7 @@ import net.minecraft.entity.LivingEntity; public abstract class RenderLivingEvent> extends Event { + private final LivingEntity entity; private final LivingRenderer renderer; private final float partialRenderTick; @@ -51,24 +52,10 @@ public abstract class RenderLivingEvent renderer, float partialRenderTick, MatrixStack matrixStack){ super(entity, renderer, partialRenderTick, matrixStack); } } + public static class Post> extends RenderLivingEvent { public Post(LivingEntity entity, LivingRenderer 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> extends RenderLivingEvent - { - public Specials(LivingEntity entity, LivingRenderer renderer, MatrixStack matrixStack){ super(entity, renderer, 0, matrixStack); } - - @Cancelable - public static class Pre> extends Specials - { - public Pre(LivingEntity entity, LivingRenderer renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); } - } - public static class Post> extends Specials - { - public Post(LivingEntity entity, LivingRenderer renderer, MatrixStack matrixStack){ super(entity, renderer, matrixStack); } - } - } } diff --git a/src/main/java/net/minecraftforge/client/event/RenderNameplateEvent.java b/src/main/java/net/minecraftforge/client/event/RenderNameplateEvent.java new file mode 100644 index 000000000..c88d5fea9 --- /dev/null +++ b/src/main/java/net/minecraftforge/client/event/RenderNameplateEvent.java @@ -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. + *
+ * {@link #nameplateContent} contains the content being rendered on the name plate/tag. This can be changed by mods.
+ * {@link #originalContent} contains the original content being rendered on the name plate/tag. This cannot be + * changed by mods.
+ * {@link #matrixStack} contains the matrix stack instance involved in rendering the name plate/tag. This cannot + * be changed by mods.
+ * {@link #renderTypeBuffer} contains the render type buffer instance involved in rendering the name plate/tag. + * This cannot be changed by mods.
+ *
+ * This event has a result. {@link HasResult}.
+ * 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
+ *
+ * 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; + } +} \ No newline at end of file diff --git a/src/test/java/net/minecraftforge/debug/client/rendering/NameplateRenderingEventTest.java b/src/test/java/net/minecraftforge/debug/client/rendering/NameplateRenderingEventTest.java new file mode 100644 index 000000000..40b19d844 --- /dev/null +++ b/src/test/java/net/minecraftforge/debug/client/rendering/NameplateRenderingEventTest.java @@ -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()); + } + } +} diff --git a/src/test/resources/META-INF/mods.toml b/src/test/resources/META-INF/mods.toml index 1c192d758..3084f8b00 100644 --- a/src/test/resources/META-INF/mods.toml +++ b/src/test/resources/META-INF/mods.toml @@ -54,4 +54,6 @@ loaderVersion="[28,)" [[mods]] modId="forgedebugmultilayermodel" [[mods]] - modId="trsr_transformer_test" \ No newline at end of file + modId="trsr_transformer_test" +[[mods]] + modId="nameplate_render_test" \ No newline at end of file