TileEntityRendererDispatcher .java

net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher (class, 156 lines): members: getSpecialRendererByClass, mapSpecialRenderers, entityX.

net.minecraft.client.renderer.tileentityclass156 linesclient7.2 KB

API Surface (8)

<T extends TileEntity> TileEntitySpecialRenderer<T> getSpecialRendererByClass(Class <? extends TileEntity > teClass)
<T extends TileEntity> TileEntitySpecialRenderer<T> getSpecialRenderer(TileEntity tileEntityIn)
void cacheActiveRenderInfo(World worldIn, TextureManager textureManagerIn, FontRenderer fontrendererIn, Entity entityIn, float partialTicks)
void renderTileEntity(TileEntity tileentityIn, float partialTicks, int destroyStage)
void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks)
void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage)
void setWorld(World worldIn)
FontRenderer getFontRenderer()

Fields & Constants (14)

mapSpecialRenderers
instance
fontRenderer
staticPlayerX
staticPlayerY
staticPlayerZ
renderEngine
worldObj
entity
entityYaw
entityPitch
entityX
entityY
entityZ

String literals (2)

"Rendering Block Entity"
"Block Entity Details"

Full Source

TileEntityRendererDispatcher.java156 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.renderer.tileentity;
2
3
import com.google.common.collect.Maps;
4
import java.util.Map;
5
import net.minecraft.client.gui.FontRenderer;
6
import net.minecraft.client.renderer.GlStateManager;
7
import net.minecraft.client.renderer.OpenGlHelper;
8
import net.minecraft.client.renderer.texture.TextureManager;
9
import net.minecraft.crash.CrashReport;
10
import net.minecraft.crash.CrashReportCategory;
11
import net.minecraft.entity.Entity;
12
import net.minecraft.tileentity.TileEntity;
13
import net.minecraft.tileentity.TileEntityBanner;
14
import net.minecraft.tileentity.TileEntityBeacon;
15
import net.minecraft.tileentity.TileEntityChest;
16
import net.minecraft.tileentity.TileEntityEnchantmentTable;
17
import net.minecraft.tileentity.TileEntityEndPortal;
18
import net.minecraft.tileentity.TileEntityEnderChest;
19
import net.minecraft.tileentity.TileEntityMobSpawner;
20
import net.minecraft.tileentity.TileEntityPiston;
21
import net.minecraft.tileentity.TileEntitySign;
22
import net.minecraft.tileentity.TileEntitySkull;
23
import net.minecraft.util.BlockPos;
24
import net.minecraft.util.ReportedException;
25
import net.minecraft.world.World;
26
27
public class TileEntityRendererDispatcher
28
{
29
    private Map < Class <? extends TileEntity > , TileEntitySpecialRenderer <? extends TileEntity >> mapSpecialRenderers = Maps. < Class <? extends TileEntity > , TileEntitySpecialRenderer <? extends TileEntity >> newHashMap();
30
    public static TileEntityRendererDispatcher instance = new TileEntityRendererDispatcher();
31
    private FontRenderer fontRenderer;
32
33
    /** The player's current X position (same as playerX) */
34
    public static double staticPlayerX;
35
36
    /** The player's current Y position (same as playerY) */
37
    public static double staticPlayerY;
38
39
    /** The player's current Z position (same as playerZ) */
40
    public static double staticPlayerZ;
41
    public TextureManager renderEngine;
42
    public World worldObj;
43
    public Entity entity;
44
    public float entityYaw;
45
    public float entityPitch;
46
    public double entityX;
47
    public double entityY;
48
    public double entityZ;
49
50
    private TileEntityRendererDispatcher()
51
    {
52
        this.mapSpecialRenderers.put(TileEntitySign.class, new TileEntitySignRenderer());
53
        this.mapSpecialRenderers.put(TileEntityMobSpawner.class, new TileEntityMobSpawnerRenderer());
54
        this.mapSpecialRenderers.put(TileEntityPiston.class, new TileEntityPistonRenderer());
55
        this.mapSpecialRenderers.put(TileEntityChest.class, new TileEntityChestRenderer());
56
        this.mapSpecialRenderers.put(TileEntityEnderChest.class, new TileEntityEnderChestRenderer());
57
        this.mapSpecialRenderers.put(TileEntityEnchantmentTable.class, new TileEntityEnchantmentTableRenderer());
58
        this.mapSpecialRenderers.put(TileEntityEndPortal.class, new TileEntityEndPortalRenderer());
59
        this.mapSpecialRenderers.put(TileEntityBeacon.class, new TileEntityBeaconRenderer());
60
        this.mapSpecialRenderers.put(TileEntitySkull.class, new TileEntitySkullRenderer());
61
        this.mapSpecialRenderers.put(TileEntityBanner.class, new TileEntityBannerRenderer());
62
63
        for (TileEntitySpecialRenderer<?> tileentityspecialrenderer : this.mapSpecialRenderers.values())
64
        {
65
            tileentityspecialrenderer.setRendererDispatcher(this);
66
        }
67
    }
68
69
    public <T extends TileEntity> TileEntitySpecialRenderer<T> getSpecialRendererByClass(Class <? extends TileEntity > teClass)
70
    {
71
        TileEntitySpecialRenderer <? extends TileEntity > tileentityspecialrenderer = (TileEntitySpecialRenderer)this.mapSpecialRenderers.get(teClass);
72
73
        if (tileentityspecialrenderer == null && teClass != TileEntity.class)
74
        {
75
            tileentityspecialrenderer = this.<TileEntity>getSpecialRendererByClass((Class <? extends TileEntity >)teClass.getSuperclass());
76
            this.mapSpecialRenderers.put(teClass, tileentityspecialrenderer);
77
        }
78
79
        return (TileEntitySpecialRenderer<T>)tileentityspecialrenderer;
80
    }
81
82
    public <T extends TileEntity> TileEntitySpecialRenderer<T> getSpecialRenderer(TileEntity tileEntityIn)
83
    {
84
        return (TileEntitySpecialRenderer<T>)(tileEntityIn == null ? null : this.getSpecialRendererByClass(tileEntityIn.getClass()));
85
    }
86
87
    public void cacheActiveRenderInfo(World worldIn, TextureManager textureManagerIn, FontRenderer fontrendererIn, Entity entityIn, float partialTicks)
88
    {
89
        if (this.worldObj != worldIn)
90
        {
91
            this.setWorld(worldIn);
92
        }
93
94
        this.renderEngine = textureManagerIn;
95
        this.entity = entityIn;
96
        this.fontRenderer = fontrendererIn;
97
        this.entityYaw = entityIn.prevRotationYaw + (entityIn.rotationYaw - entityIn.prevRotationYaw) * partialTicks;
98
        this.entityPitch = entityIn.prevRotationPitch + (entityIn.rotationPitch - entityIn.prevRotationPitch) * partialTicks;
99
        this.entityX = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
100
        this.entityY = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
101
        this.entityZ = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
102
    }
103
104
    public void renderTileEntity(TileEntity tileentityIn, float partialTicks, int destroyStage)
105
    {
106
        if (tileentityIn.getDistanceSq(this.entityX, this.entityY, this.entityZ) < tileentityIn.getMaxRenderDistanceSquared())
107
        {
108
            int i = this.worldObj.getCombinedLight(tileentityIn.getPos(), 0);
109
            int j = i % 65536;
110
            int k = i / 65536;
111
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F);
112
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
113
            BlockPos blockpos = tileentityIn.getPos();
114
            this.renderTileEntityAt(tileentityIn, (double)blockpos.getX() - staticPlayerX, (double)blockpos.getY() - staticPlayerY, (double)blockpos.getZ() - staticPlayerZ, partialTicks, destroyStage);
115
        }
116
    }
117
118
    /**
119
     * Render this TileEntity at a given set of coordinates
120
     */
121
    public void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks)
122
    {
123
        this.renderTileEntityAt(tileEntityIn, x, y, z, partialTicks, -1);
124
    }
125
126
    public void renderTileEntityAt(TileEntity tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage)
127
    {
128
        TileEntitySpecialRenderer<TileEntity> tileentityspecialrenderer = this.<TileEntity>getSpecialRenderer(tileEntityIn);
129
130
        if (tileentityspecialrenderer != null)
131
        {
132
            try
133
            {
134
                tileentityspecialrenderer.renderTileEntityAt(tileEntityIn, x, y, z, partialTicks, destroyStage);
135
            }
136
            catch (Throwable throwable)
137
            {
138
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Rendering Block Entity");
139
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Block Entity Details");
140
                tileEntityIn.addInfoToCrashReport(crashreportcategory);
141
                throw new ReportedException(crashreport);
142
            }
143
        }
144
    }
145
146
    public void setWorld(World worldIn)
147
    {
148
        this.worldObj = worldIn;
149
    }
150
151
    public FontRenderer getFontRenderer()
152
    {
153
        return this.fontRenderer;
154
    }
155
}
156

Deobfuscated MCP 1.8.9 source of TileEntityRendererDispatcher from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher.java), stored verbatim.