|
| 1 | +package net.irisshaders.iris.mixin.entity_render_context; |
| 2 | + |
| 3 | +import com.mojang.blaze3d.vertex.PoseStack; |
| 4 | +import it.unimi.dsi.fastutil.objects.Object2IntFunction; |
| 5 | +import net.irisshaders.iris.shaderpack.materialmap.NamespacedId; |
| 6 | +import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; |
| 7 | +import net.irisshaders.iris.uniforms.CapturedRenderingState; |
| 8 | +import net.minecraft.client.renderer.MultiBufferSource; |
| 9 | +import net.minecraft.client.renderer.entity.EntityRenderer; |
| 10 | +import net.minecraft.network.chat.Component; |
| 11 | +import net.minecraft.world.entity.Entity; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Unique; |
| 14 | +import org.spongepowered.asm.mixin.injection.At; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 17 | + |
| 18 | +@Mixin(EntityRenderer.class) |
| 19 | +public class MixinEntityRenderer<T extends Entity> { |
| 20 | + @Unique |
| 21 | + private static final NamespacedId NAME_TAG_ID = new NamespacedId("minecraft", "name_tag"); |
| 22 | + |
| 23 | + @Unique |
| 24 | + private int lastId = -100; |
| 25 | + |
| 26 | + @Inject(method = "renderNameTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;getViewYRot(F)F")) |
| 27 | + private void setNameTagId(T entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, float f, CallbackInfo ci) { |
| 28 | + Object2IntFunction<NamespacedId> entityIds = WorldRenderingSettings.INSTANCE.getEntityIds(); |
| 29 | + |
| 30 | + if (entityIds == null) { |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + this.lastId = CapturedRenderingState.INSTANCE.getCurrentRenderedEntity(); |
| 35 | + |
| 36 | + int intId = entityIds.applyAsInt(NAME_TAG_ID); |
| 37 | + |
| 38 | + CapturedRenderingState.INSTANCE.setCurrentEntity(intId); |
| 39 | + } |
| 40 | + |
| 41 | + @Inject(method = "renderNameTag", at = @At("RETURN")) |
| 42 | + private void resetId(T entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, float f, CallbackInfo ci) { |
| 43 | + if (lastId != -100) { |
| 44 | + CapturedRenderingState.INSTANCE.setCurrentEntity(lastId); |
| 45 | + lastId = -100 ; |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments