CrashReportCategory .java

net.minecraft.crash.CrashReportCategory (class, 309 lines): members: firstTwoElementsOfStackTraceMatch, trimStackTraceEntriesFromBottom, getCoordinateInfo.

net.minecraft.crashclass309 linescommon10.1 KB

API Surface (19)

String getCoordinateInfo(double x, double y, double z)
String getCoordinateInfo(BlockPos pos)
void addCrashSectionCallable(String sectionName, Callable<String> callable)
void addCrashSection(String sectionName, Object value)
void addCrashSectionThrowable(String sectionName, Throwable throwable)
int getPrunedStackTrace(int size)
boolean firstTwoElementsOfStackTraceMatch(StackTraceElement s1, StackTraceElement s2)
void trimStackTraceEntriesFromBottom(int amount)
void appendToStringBuilder(StringBuilder builder)
StackTraceElement[] getStackTrace()
void addBlockInfo(CrashReportCategory category, final BlockPos pos, final Block blockIn, final int blockData)
String call()
String call()
String call()
void addBlockInfo(CrashReportCategory category, final BlockPos pos, final IBlockState state)
String call()
String call()
String getKey()
String getValue()

Fields & Constants (4)

crashReport
name
children
stackTrace

String literals (12)

"(Error finding world loc)"
"(Error finding chunk loc)"
"Details:"
"\nStacktrace:"
"\n\tat "
"Block type"
"Block data value"
"Unknown? (Got "
"Block location"
"Block"
"~~NULL~~"
"~~ERROR~~ "

Same Package (1)

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CrashReportCategory.java309 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.crash;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import java.util.concurrent.Callable;
6
import net.minecraft.block.Block;
7
import net.minecraft.block.state.IBlockState;
8
import net.minecraft.util.BlockPos;
9
10
public class CrashReportCategory
11
{
12
    private final CrashReport crashReport;
13
    private final String name;
14
    private final List<CrashReportCategory.Entry> children = Lists.<CrashReportCategory.Entry>newArrayList();
15
    private StackTraceElement[] stackTrace = new StackTraceElement[0];
16
17
    public CrashReportCategory(CrashReport report, String name)
18
    {
19
        this.crashReport = report;
20
        this.name = name;
21
    }
22
23
    public static String getCoordinateInfo(double x, double y, double z)
24
    {
25
        return String.format("%.2f,%.2f,%.2f - %s", new Object[] {Double.valueOf(x), Double.valueOf(y), Double.valueOf(z), getCoordinateInfo(new BlockPos(x, y, z))});
26
    }
27
28
    public static String getCoordinateInfo(BlockPos pos)
29
    {
30
        int i = pos.getX();
31
        int j = pos.getY();
32
        int k = pos.getZ();
33
        StringBuilder stringbuilder = new StringBuilder();
34
35
        try
36
        {
37
            stringbuilder.append(String.format("World: (%d,%d,%d)", new Object[] {Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(k)}));
38
        }
39
        catch (Throwable var17)
40
        {
41
            stringbuilder.append("(Error finding world loc)");
42
        }
43
44
        stringbuilder.append(", ");
45
46
        try
47
        {
48
            int l = i >> 4;
49
            int i1 = k >> 4;
50
            int j1 = i & 15;
51
            int k1 = j >> 4;
52
            int l1 = k & 15;
53
            int i2 = l << 4;
54
            int j2 = i1 << 4;
55
            int k2 = (l + 1 << 4) - 1;
56
            int l2 = (i1 + 1 << 4) - 1;
57
            stringbuilder.append(String.format("Chunk: (at %d,%d,%d in %d,%d; contains blocks %d,0,%d to %d,255,%d)", new Object[] {Integer.valueOf(j1), Integer.valueOf(k1), Integer.valueOf(l1), Integer.valueOf(l), Integer.valueOf(i1), Integer.valueOf(i2), Integer.valueOf(j2), Integer.valueOf(k2), Integer.valueOf(l2)}));
58
        }
59
        catch (Throwable var16)
60
        {
61
            stringbuilder.append("(Error finding chunk loc)");
62
        }
63
64
        stringbuilder.append(", ");
65
66
        try
67
        {
68
            int j3 = i >> 9;
69
            int k3 = k >> 9;
70
            int l3 = j3 << 5;
71
            int i4 = k3 << 5;
72
            int j4 = (j3 + 1 << 5) - 1;
73
            int k4 = (k3 + 1 << 5) - 1;
74
            int l4 = j3 << 9;
75
            int i5 = k3 << 9;
76
            int j5 = (j3 + 1 << 9) - 1;
77
            int i3 = (k3 + 1 << 9) - 1;
78
            stringbuilder.append(String.format("Region: (%d,%d; contains chunks %d,%d to %d,%d, blocks %d,0,%d to %d,255,%d)", new Object[] {Integer.valueOf(j3), Integer.valueOf(k3), Integer.valueOf(l3), Integer.valueOf(i4), Integer.valueOf(j4), Integer.valueOf(k4), Integer.valueOf(l4), Integer.valueOf(i5), Integer.valueOf(j5), Integer.valueOf(i3)}));
79
        }
80
        catch (Throwable var15)
81
        {
82
            stringbuilder.append("(Error finding world loc)");
83
        }
84
85
        return stringbuilder.toString();
86
    }
87
88
    /**
89
     * Adds a Crashreport section with the given name with the value set to the result of the given Callable;
90
     */
91
    public void addCrashSectionCallable(String sectionName, Callable<String> callable)
92
    {
93
        try
94
        {
95
            this.addCrashSection(sectionName, callable.call());
96
        }
97
        catch (Throwable throwable)
98
        {
99
            this.addCrashSectionThrowable(sectionName, throwable);
100
        }
101
    }
102
103
    /**
104
     * Adds a Crashreport section with the given name with the given value (convered .toString())
105
     */
106
    public void addCrashSection(String sectionName, Object value)
107
    {
108
        this.children.add(new CrashReportCategory.Entry(sectionName, value));
109
    }
110
111
    /**
112
     * Adds a Crashreport section with the given name with the given Throwable
113
     */
114
    public void addCrashSectionThrowable(String sectionName, Throwable throwable)
115
    {
116
        this.addCrashSection(sectionName, throwable);
117
    }
118
119
    /**
120
     * Resets our stack trace according to the current trace, pruning the deepest 3 entries.  The parameter indicates
121
     * how many additional deepest entries to prune.  Returns the number of entries in the resulting pruned stack trace.
122
     */
123
    public int getPrunedStackTrace(int size)
124
    {
125
        StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace();
126
127
        if (astacktraceelement.length <= 0)
128
        {
129
            return 0;
130
        }
131
        else
132
        {
133
            this.stackTrace = new StackTraceElement[astacktraceelement.length - 3 - size];
134
            System.arraycopy(astacktraceelement, 3 + size, this.stackTrace, 0, this.stackTrace.length);
135
            return this.stackTrace.length;
136
        }
137
    }
138
139
    /**
140
     * Do the deepest two elements of our saved stack trace match the given elements, in order from the deepest?
141
     */
142
    public boolean firstTwoElementsOfStackTraceMatch(StackTraceElement s1, StackTraceElement s2)
143
    {
144
        if (this.stackTrace.length != 0 && s1 != null)
145
        {
146
            StackTraceElement stacktraceelement = this.stackTrace[0];
147
148
            if (stacktraceelement.isNativeMethod() == s1.isNativeMethod() && stacktraceelement.getClassName().equals(s1.getClassName()) && stacktraceelement.getFileName().equals(s1.getFileName()) && stacktraceelement.getMethodName().equals(s1.getMethodName()))
149
            {
150
                if (s2 != null != this.stackTrace.length > 1)
151
                {
152
                    return false;
153
                }
154
                else if (s2 != null && !this.stackTrace[1].equals(s2))
155
                {
156
                    return false;
157
                }
158
                else
159
                {
160
                    this.stackTrace[0] = s1;
161
                    return true;
162
                }
163
            }
164
            else
165
            {
166
                return false;
167
            }
168
        }
169
        else
170
        {
171
            return false;
172
        }
173
    }
174
175
    /**
176
     * Removes the given number entries from the bottom of the stack trace.
177
     */
178
    public void trimStackTraceEntriesFromBottom(int amount)
179
    {
180
        StackTraceElement[] astacktraceelement = new StackTraceElement[this.stackTrace.length - amount];
181
        System.arraycopy(this.stackTrace, 0, astacktraceelement, 0, astacktraceelement.length);
182
        this.stackTrace = astacktraceelement;
183
    }
184
185
    public void appendToStringBuilder(StringBuilder builder)
186
    {
187
        builder.append("-- ").append(this.name).append(" --\n");
188
        builder.append("Details:");
189
190
        for (CrashReportCategory.Entry crashreportcategory$entry : this.children)
191
        {
192
            builder.append("\n\t");
193
            builder.append(crashreportcategory$entry.getKey());
194
            builder.append(": ");
195
            builder.append(crashreportcategory$entry.getValue());
196
        }
197
198
        if (this.stackTrace != null && this.stackTrace.length > 0)
199
        {
200
            builder.append("\nStacktrace:");
201
202
            for (StackTraceElement stacktraceelement : this.stackTrace)
203
            {
204
                builder.append("\n\tat ");
205
                builder.append(stacktraceelement.toString());
206
            }
207
        }
208
    }
209
210
    public StackTraceElement[] getStackTrace()
211
    {
212
        return this.stackTrace;
213
    }
214
215
    public static void addBlockInfo(CrashReportCategory category, final BlockPos pos, final Block blockIn, final int blockData)
216
    {
217
        final int i = Block.getIdFromBlock(blockIn);
218
        category.addCrashSectionCallable("Block type", new Callable<String>()
219
        {
220
            public String call() throws Exception
221
            {
222
                try
223
                {
224
                    return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(i), blockIn.getUnlocalizedName(), blockIn.getClass().getCanonicalName()});
225
                }
226
                catch (Throwable var2)
227
                {
228
                    return "ID #" + i;
229
                }
230
            }
231
        });
232
        category.addCrashSectionCallable("Block data value", new Callable<String>()
233
        {
234
            public String call() throws Exception
235
            {
236
                if (blockData < 0)
237
                {
238
                    return "Unknown? (Got " + blockData + ")";
239
                }
240
                else
241
                {
242
                    String s = String.format("%4s", new Object[] {Integer.toBinaryString(blockData)}).replace(" ", "0");
243
                    return String.format("%1$d / 0x%1$X / 0b%2$s", new Object[] {Integer.valueOf(blockData), s});
244
                }
245
            }
246
        });
247
        category.addCrashSectionCallable("Block location", new Callable<String>()
248
        {
249
            public String call() throws Exception
250
            {
251
                return CrashReportCategory.getCoordinateInfo(pos);
252
            }
253
        });
254
    }
255
256
    public static void addBlockInfo(CrashReportCategory category, final BlockPos pos, final IBlockState state)
257
    {
258
        category.addCrashSectionCallable("Block", new Callable<String>()
259
        {
260
            public String call() throws Exception
261
            {
262
                return state.toString();
263
            }
264
        });
265
        category.addCrashSectionCallable("Block location", new Callable<String>()
266
        {
267
            public String call() throws Exception
268
            {
269
                return CrashReportCategory.getCoordinateInfo(pos);
270
            }
271
        });
272
    }
273
274
    static class Entry
275
    {
276
        private final String key;
277
        private final String value;
278
279
        public Entry(String key, Object value)
280
        {
281
            this.key = key;
282
283
            if (value == null)
284
            {
285
                this.value = "~~NULL~~";
286
            }
287
            else if (value instanceof Throwable)
288
            {
289
                Throwable throwable = (Throwable)value;
290
                this.value = "~~ERROR~~ " + throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
291
            }
292
            else
293
            {
294
                this.value = value.toString();
295
            }
296
        }
297
298
        public String getKey()
299
        {
300
            return this.key;
301
        }
302
303
        public String getValue()
304
        {
305
            return this.value;
306
        }
307
    }
308
}
309

Deobfuscated MCP 1.8.9 source of CrashReportCategory from Marcelektro/MavenMCP-1.8.9 (net/minecraft/crash/CrashReportCategory.java), stored verbatim.