GuiOverlayDebug .java

net.minecraft.client.gui.GuiOverlayDebug (class): members: renderDebugInfoRight, renderDebugInfoLeft, getDebugInfoRight, renderDebugInfo, call, mc.

net.minecraft.client.guiclass285 linesclientextends Gui13.6 KB

API Surface (5)

void renderDebugInfo(ScaledResolution scaledResolutionIn)
void renderDebugInfoLeft()
void renderDebugInfoRight(ScaledResolution scaledRes)
List<String> call()
List<String> getDebugInfoRight()

Fields & Constants (2)

mc
fontRenderer

String literals (13)

"incomplete-switch"
"Minecraft 1.8.9 ("
"Invalid"
"Towards negative Z"
"Towards positive Z"
"Towards negative X"
"Towards positive X"
"Biome: "
"Light: "
" sky, "
" block)"
"Shader: "
"java.version"

Full Source

GuiOverlayDebug.java285 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.base.Strings;
4
import com.google.common.collect.Lists;
5
import java.util.List;
6
import java.util.Map.Entry;
7
import net.minecraft.block.Block;
8
import net.minecraft.block.properties.IProperty;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.client.ClientBrandRetriever;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.client.renderer.GlStateManager;
13
import net.minecraft.client.renderer.OpenGlHelper;
14
import net.minecraft.entity.Entity;
15
import net.minecraft.entity.player.EntityPlayerMP;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumChatFormatting;
18
import net.minecraft.util.EnumFacing;
19
import net.minecraft.util.FrameTimer;
20
import net.minecraft.util.MathHelper;
21
import net.minecraft.util.MovingObjectPosition;
22
import net.minecraft.world.DifficultyInstance;
23
import net.minecraft.world.EnumSkyBlock;
24
import net.minecraft.world.WorldType;
25
import net.minecraft.world.chunk.Chunk;
26
import org.lwjgl.opengl.Display;
27
import org.lwjgl.opengl.GL11;
28
29
public class GuiOverlayDebug extends Gui
30
{
31
    private final Minecraft mc;
32
    private final FontRenderer fontRenderer;
33
34
    public GuiOverlayDebug(Minecraft mc)
35
    {
36
        this.mc = mc;
37
        this.fontRenderer = mc.fontRendererObj;
38
    }
39
40
    public void renderDebugInfo(ScaledResolution scaledResolutionIn)
41
    {
42
        this.mc.mcProfiler.startSection("debug");
43
        GlStateManager.pushMatrix();
44
        this.renderDebugInfoLeft();
45
        this.renderDebugInfoRight(scaledResolutionIn);
46
        GlStateManager.popMatrix();
47
48
        if (this.mc.gameSettings.showLagometer)
49
        {
50
            this.renderLagometer();
51
        }
52
53
        this.mc.mcProfiler.endSection();
54
    }
55
56
    private boolean isReducedDebug()
57
    {
58
        return this.mc.thePlayer.hasReducedDebug() || this.mc.gameSettings.reducedDebugInfo;
59
    }
60
61
    protected void renderDebugInfoLeft()
62
    {
63
        List<String> list = this.call();
64
65
        for (int i = 0; i < list.size(); ++i)
66
        {
67
            String s = (String)list.get(i);
68
69
            if (!Strings.isNullOrEmpty(s))
70
            {
71
                int j = this.fontRenderer.FONT_HEIGHT;
72
                int k = this.fontRenderer.getStringWidth(s);
73
                int l = 2;
74
                int i1 = 2 + j * i;
75
                drawRect(1, i1 - 1, 2 + k + 1, i1 + j - 1, -1873784752);
76
                this.fontRenderer.drawString(s, 2, i1, 14737632);
77
            }
78
        }
79
    }
80
81
    protected void renderDebugInfoRight(ScaledResolution scaledRes)
82
    {
83
        List<String> list = this.getDebugInfoRight();
84
85
        for (int i = 0; i < list.size(); ++i)
86
        {
87
            String s = (String)list.get(i);
88
89
            if (!Strings.isNullOrEmpty(s))
90
            {
91
                int j = this.fontRenderer.FONT_HEIGHT;
92
                int k = this.fontRenderer.getStringWidth(s);
93
                int l = scaledRes.getScaledWidth() - 2 - k;
94
                int i1 = 2 + j * i;
95
                drawRect(l - 1, i1 - 1, l + k + 1, i1 + j - 1, -1873784752);
96
                this.fontRenderer.drawString(s, l, i1, 14737632);
97
            }
98
        }
99
    }
100
101
    @SuppressWarnings("incomplete-switch")
102
    protected List<String> call()
103
    {
104
        BlockPos blockpos = new BlockPos(this.mc.getRenderViewEntity().posX, this.mc.getRenderViewEntity().getEntityBoundingBox().minY, this.mc.getRenderViewEntity().posZ);
105
106
        if (this.isReducedDebug())
107
        {
108
            return Lists.newArrayList(new String[] {"Minecraft 1.8.9 (" + this.mc.getVersion() + "/" + ClientBrandRetriever.getClientModName() + ")", this.mc.debug, this.mc.renderGlobal.getDebugInfoRenders(), this.mc.renderGlobal.getDebugInfoEntities(), "P: " + this.mc.effectRenderer.getStatistics() + ". T: " + this.mc.theWorld.getDebugLoadedEntities(), this.mc.theWorld.getProviderName(), "", String.format("Chunk-relative: %d %d %d", new Object[]{Integer.valueOf(blockpos.getX() & 15), Integer.valueOf(blockpos.getY() & 15), Integer.valueOf(blockpos.getZ() & 15)})});
109
        }
110
        else
111
        {
112
            Entity entity = this.mc.getRenderViewEntity();
113
            EnumFacing enumfacing = entity.getHorizontalFacing();
114
            String s = "Invalid";
115
116
            switch (enumfacing)
117
            {
118
                case NORTH:
119
                    s = "Towards negative Z";
120
                    break;
121
122
                case SOUTH:
123
                    s = "Towards positive Z";
124
                    break;
125
126
                case WEST:
127
                    s = "Towards negative X";
128
                    break;
129
130
                case EAST:
131
                    s = "Towards positive X";
132
            }
133
134
            List<String> list = Lists.newArrayList(new String[] {"Minecraft 1.8.9 (" + this.mc.getVersion() + "/" + ClientBrandRetriever.getClientModName() + ")", this.mc.debug, this.mc.renderGlobal.getDebugInfoRenders(), this.mc.renderGlobal.getDebugInfoEntities(), "P: " + this.mc.effectRenderer.getStatistics() + ". T: " + this.mc.theWorld.getDebugLoadedEntities(), this.mc.theWorld.getProviderName(), "", String.format("XYZ: %.3f / %.5f / %.3f", new Object[]{Double.valueOf(this.mc.getRenderViewEntity().posX), Double.valueOf(this.mc.getRenderViewEntity().getEntityBoundingBox().minY), Double.valueOf(this.mc.getRenderViewEntity().posZ)}), String.format("Block: %d %d %d", new Object[]{Integer.valueOf(blockpos.getX()), Integer.valueOf(blockpos.getY()), Integer.valueOf(blockpos.getZ())}), String.format("Chunk: %d %d %d in %d %d %d", new Object[]{Integer.valueOf(blockpos.getX() & 15), Integer.valueOf(blockpos.getY() & 15), Integer.valueOf(blockpos.getZ() & 15), Integer.valueOf(blockpos.getX() >> 4), Integer.valueOf(blockpos.getY() >> 4), Integer.valueOf(blockpos.getZ() >> 4)}), String.format("Facing: %s (%s) (%.1f / %.1f)", new Object[]{enumfacing, s, Float.valueOf(MathHelper.wrapAngleTo180_float(entity.rotationYaw)), Float.valueOf(MathHelper.wrapAngleTo180_float(entity.rotationPitch))})});
135
136
            if (this.mc.theWorld != null && this.mc.theWorld.isBlockLoaded(blockpos))
137
            {
138
                Chunk chunk = this.mc.theWorld.getChunkFromBlockCoords(blockpos);
139
                list.add("Biome: " + chunk.getBiome(blockpos, this.mc.theWorld.getWorldChunkManager()).biomeName);
140
                list.add("Light: " + chunk.getLightSubtracted(blockpos, 0) + " (" + chunk.getLightFor(EnumSkyBlock.SKY, blockpos) + " sky, " + chunk.getLightFor(EnumSkyBlock.BLOCK, blockpos) + " block)");
141
                DifficultyInstance difficultyinstance = this.mc.theWorld.getDifficultyForLocation(blockpos);
142
143
                if (this.mc.isIntegratedServerRunning() && this.mc.getIntegratedServer() != null)
144
                {
145
                    EntityPlayerMP entityplayermp = this.mc.getIntegratedServer().getConfigurationManager().getPlayerByUUID(this.mc.thePlayer.getUniqueID());
146
147
                    if (entityplayermp != null)
148
                    {
149
                        difficultyinstance = entityplayermp.worldObj.getDifficultyForLocation(new BlockPos(entityplayermp));
150
                    }
151
                }
152
153
                list.add(String.format("Local Difficulty: %.2f (Day %d)", new Object[] {Float.valueOf(difficultyinstance.getAdditionalDifficulty()), Long.valueOf(this.mc.theWorld.getWorldTime() / 24000L)}));
154
            }
155
156
            if (this.mc.entityRenderer != null && this.mc.entityRenderer.isShaderActive())
157
            {
158
                list.add("Shader: " + this.mc.entityRenderer.getShaderGroup().getShaderGroupName());
159
            }
160
161
            if (this.mc.objectMouseOver != null && this.mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.mc.objectMouseOver.getBlockPos() != null)
162
            {
163
                BlockPos blockpos1 = this.mc.objectMouseOver.getBlockPos();
164
                list.add(String.format("Looking at: %d %d %d", new Object[] {Integer.valueOf(blockpos1.getX()), Integer.valueOf(blockpos1.getY()), Integer.valueOf(blockpos1.getZ())}));
165
            }
166
167
            return list;
168
        }
169
    }
170
171
    protected List<String> getDebugInfoRight()
172
    {
173
        long i = Runtime.getRuntime().maxMemory();
174
        long j = Runtime.getRuntime().totalMemory();
175
        long k = Runtime.getRuntime().freeMemory();
176
        long l = j - k;
177
        List<String> list = Lists.newArrayList(new String[] {String.format("Java: %s %dbit", new Object[]{System.getProperty("java.version"), Integer.valueOf(this.mc.isJava64bit() ? 64 : 32)}), String.format("Mem: % 2d%% %03d/%03dMB", new Object[]{Long.valueOf(l * 100L / i), Long.valueOf(bytesToMb(l)), Long.valueOf(bytesToMb(i))}), String.format("Allocated: % 2d%% %03dMB", new Object[]{Long.valueOf(j * 100L / i), Long.valueOf(bytesToMb(j))}), "", String.format("CPU: %s", new Object[]{OpenGlHelper.getCpu()}), "", String.format("Display: %dx%d (%s)", new Object[]{Integer.valueOf(Display.getWidth()), Integer.valueOf(Display.getHeight()), GL11.glGetString(GL11.GL_VENDOR)}), GL11.glGetString(GL11.GL_RENDERER), GL11.glGetString(GL11.GL_VERSION)});
178
179
        if (this.isReducedDebug())
180
        {
181
            return list;
182
        }
183
        else
184
        {
185
            if (this.mc.objectMouseOver != null && this.mc.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.mc.objectMouseOver.getBlockPos() != null)
186
            {
187
                BlockPos blockpos = this.mc.objectMouseOver.getBlockPos();
188
                IBlockState iblockstate = this.mc.theWorld.getBlockState(blockpos);
189
190
                if (this.mc.theWorld.getWorldType() != WorldType.DEBUG_WORLD)
191
                {
192
                    iblockstate = iblockstate.getBlock().getActualState(iblockstate, this.mc.theWorld, blockpos);
193
                }
194
195
                list.add("");
196
                list.add(String.valueOf(Block.blockRegistry.getNameForObject(iblockstate.getBlock())));
197
198
                for (Entry<IProperty, Comparable> entry : iblockstate.getProperties().entrySet())
199
                {
200
                    String s = ((Comparable)entry.getValue()).toString();
201
202
                    if (entry.getValue() == Boolean.TRUE)
203
                    {
204
                        s = EnumChatFormatting.GREEN + s;
205
                    }
206
                    else if (entry.getValue() == Boolean.FALSE)
207
                    {
208
                        s = EnumChatFormatting.RED + s;
209
                    }
210
211
                    list.add(((IProperty)entry.getKey()).getName() + ": " + s);
212
                }
213
            }
214
215
            return list;
216
        }
217
    }
218
219
    private void renderLagometer()
220
    {
221
        GlStateManager.disableDepth();
222
        FrameTimer frametimer = this.mc.getFrameTimer();
223
        int i = frametimer.getLastIndex();
224
        int j = frametimer.getIndex();
225
        long[] along = frametimer.getFrames();
226
        ScaledResolution scaledresolution = new ScaledResolution(this.mc);
227
        int k = i;
228
        int l = 0;
229
        drawRect(0, scaledresolution.getScaledHeight() - 60, 240, scaledresolution.getScaledHeight(), -1873784752);
230
231
        while (k != j)
232
        {
233
            int i1 = frametimer.getLagometerValue(along[k], 30);
234
            int j1 = this.getFrameColor(MathHelper.clamp_int(i1, 0, 60), 0, 30, 60);
235
            this.drawVerticalLine(l, scaledresolution.getScaledHeight(), scaledresolution.getScaledHeight() - i1, j1);
236
            ++l;
237
            k = frametimer.parseIndex(k + 1);
238
        }
239
240
        drawRect(1, scaledresolution.getScaledHeight() - 30 + 1, 14, scaledresolution.getScaledHeight() - 30 + 10, -1873784752);
241
        this.fontRenderer.drawString("60", 2, scaledresolution.getScaledHeight() - 30 + 2, 14737632);
242
        this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 30, -1);
243
        drawRect(1, scaledresolution.getScaledHeight() - 60 + 1, 14, scaledresolution.getScaledHeight() - 60 + 10, -1873784752);
244
        this.fontRenderer.drawString("30", 2, scaledresolution.getScaledHeight() - 60 + 2, 14737632);
245
        this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 60, -1);
246
        this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 1, -1);
247
        this.drawVerticalLine(0, scaledresolution.getScaledHeight() - 60, scaledresolution.getScaledHeight(), -1);
248
        this.drawVerticalLine(239, scaledresolution.getScaledHeight() - 60, scaledresolution.getScaledHeight(), -1);
249
250
        if (this.mc.gameSettings.limitFramerate <= 120)
251
        {
252
            this.drawHorizontalLine(0, 239, scaledresolution.getScaledHeight() - 60 + this.mc.gameSettings.limitFramerate / 2, -16711681);
253
        }
254
255
        GlStateManager.enableDepth();
256
    }
257
258
    private int getFrameColor(int p_181552_1_, int p_181552_2_, int p_181552_3_, int p_181552_4_)
259
    {
260
        return p_181552_1_ < p_181552_3_ ? this.blendColors(-16711936, -256, (float)p_181552_1_ / (float)p_181552_3_) : this.blendColors(-256, -65536, (float)(p_181552_1_ - p_181552_3_) / (float)(p_181552_4_ - p_181552_3_));
261
    }
262
263
    private int blendColors(int p_181553_1_, int p_181553_2_, float p_181553_3_)
264
    {
265
        int i = p_181553_1_ >> 24 & 255;
266
        int j = p_181553_1_ >> 16 & 255;
267
        int k = p_181553_1_ >> 8 & 255;
268
        int l = p_181553_1_ & 255;
269
        int i1 = p_181553_2_ >> 24 & 255;
270
        int j1 = p_181553_2_ >> 16 & 255;
271
        int k1 = p_181553_2_ >> 8 & 255;
272
        int l1 = p_181553_2_ & 255;
273
        int i2 = MathHelper.clamp_int((int)((float)i + (float)(i1 - i) * p_181553_3_), 0, 255);
274
        int j2 = MathHelper.clamp_int((int)((float)j + (float)(j1 - j) * p_181553_3_), 0, 255);
275
        int k2 = MathHelper.clamp_int((int)((float)k + (float)(k1 - k) * p_181553_3_), 0, 255);
276
        int l2 = MathHelper.clamp_int((int)((float)l + (float)(l1 - l) * p_181553_3_), 0, 255);
277
        return i2 << 24 | j2 << 16 | k2 << 8 | l2;
278
    }
279
280
    private static long bytesToMb(long bytes)
281
    {
282
        return bytes / 1024L / 1024L;
283
    }
284
}
285

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