    001package net.minecraft.crash;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.ArrayList;
    006import java.util.Iterator;
    007import java.util.List;
    008import java.util.concurrent.Callable;
    009import net.minecraft.util.MathHelper;
    010
    011public class CrashReportCategory
    012{
    013    private final CrashReport field_85078_a;
    014    private final String field_85076_b;
    015    private final List field_85077_c = new ArrayList();
    016    private StackTraceElement[] stackTrace = new StackTraceElement[0];
    017
    018    public CrashReportCategory(CrashReport par1CrashReport, String par2Str)
    019    {
    020        this.field_85078_a = par1CrashReport;
    021        this.field_85076_b = par2Str;
    022    }
    023
    024    @SideOnly(Side.CLIENT)
    025    public static String func_85074_a(double par0, double par2, double par4)
    026    {
    027        return String.format("%.2f,%.2f,%.2f - %s", new Object[] {Double.valueOf(par0), Double.valueOf(par2), Double.valueOf(par4), func_85071_a(MathHelper.floor_double(par0), MathHelper.floor_double(par2), MathHelper.floor_double(par4))});
    028    }
    029
    030    public static String func_85071_a(int par0, int par1, int par2)
    031    {
    032        StringBuilder var3 = new StringBuilder();
    033
    034        try
    035        {
    036            var3.append(String.format("World: (%d,%d,%d)", new Object[] {Integer.valueOf(par0), Integer.valueOf(par1), Integer.valueOf(par2)}));
    037        }
    038        catch (Throwable var16)
    039        {
    040            var3.append("(Error finding world loc)");
    041        }
    042
    043        var3.append(", ");
    044        int var4;
    045        int var5;
    046        int var6;
    047        int var7;
    048        int var8;
    049        int var9;
    050        int var10;
    051        int var11;
    052        int var12;
    053
    054        try
    055        {
    056            var4 = par0 >> 4;
    057            var5 = par2 >> 4;
    058            var6 = par0 & 15;
    059            var7 = par1 >> 4;
    060            var8 = par2 & 15;
    061            var9 = var4 << 4;
    062            var10 = var5 << 4;
    063            var11 = (var4 + 1 << 4) - 1;
    064            var12 = (var5 + 1 << 4) - 1;
    065            var3.append(String.format("Chunk: (at %d,%d,%d in %d,%d; contains blocks %d,0,%d to %d,255,%d)", new Object[] {Integer.valueOf(var6), Integer.valueOf(var7), Integer.valueOf(var8), Integer.valueOf(var4), Integer.valueOf(var5), Integer.valueOf(var9), Integer.valueOf(var10), Integer.valueOf(var11), Integer.valueOf(var12)}));
    066        }
    067        catch (Throwable var15)
    068        {
    069            var3.append("(Error finding chunk loc)");
    070        }
    071
    072        var3.append(", ");
    073
    074        try
    075        {
    076            var4 = par0 >> 9;
    077            var5 = par2 >> 9;
    078            var6 = var4 << 5;
    079            var7 = var5 << 5;
    080            var8 = (var4 + 1 << 5) - 1;
    081            var9 = (var5 + 1 << 5) - 1;
    082            var10 = var4 << 9;
    083            var11 = var5 << 9;
    084            var12 = (var4 + 1 << 9) - 1;
    085            int var13 = (var5 + 1 << 9) - 1;
    086            var3.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(var4), Integer.valueOf(var5), Integer.valueOf(var6), Integer.valueOf(var7), Integer.valueOf(var8), Integer.valueOf(var9), Integer.valueOf(var10), Integer.valueOf(var11), Integer.valueOf(var12), Integer.valueOf(var13)}));
    087        }
    088        catch (Throwable var14)
    089        {
    090            var3.append("(Error finding world loc)");
    091        }
    092
    093        return var3.toString();
    094    }
    095
    096    /**
    097     * Adds a Crashreport section with the given name with the value set to the result of the given Callable;
    098     */
    099    public void addCrashSectionCallable(String par1Str, Callable par2Callable)
    100    {
    101        try
    102        {
    103            this.addCrashSection(par1Str, par2Callable.call());
    104        }
    105        catch (Throwable var4)
    106        {
    107            this.addCrashSectionThrowable(par1Str, var4);
    108        }
    109    }
    110
    111    /**
    112     * Adds a Crashreport section with the given name with the given value (convered .toString())
    113     */
    114    public void addCrashSection(String par1Str, Object par2Obj)
    115    {
    116        this.field_85077_c.add(new CrashReportCategoryEntry(par1Str, par2Obj));
    117    }
    118
    119    /**
    120     * Adds a Crashreport section with the given name with the given Throwable
    121     */
    122    public void addCrashSectionThrowable(String par1Str, Throwable par2Throwable)
    123    {
    124        this.addCrashSection(par1Str, par2Throwable);
    125    }
    126
    127    public int func_85073_a(int par1)
    128    {
    129        StackTraceElement[] var2 = Thread.currentThread().getStackTrace();
    130        this.stackTrace = new StackTraceElement[var2.length - 3 - par1];
    131        System.arraycopy(var2, 3 + par1, this.stackTrace, 0, this.stackTrace.length);
    132        return this.stackTrace.length;
    133    }
    134
    135    public boolean func_85069_a(StackTraceElement par1StackTraceElement, StackTraceElement par2StackTraceElement)
    136    {
    137        if (this.stackTrace.length != 0 && par1StackTraceElement != null)
    138        {
    139            StackTraceElement var3 = this.stackTrace[0];
    140
    141            if (var3.isNativeMethod() == par1StackTraceElement.isNativeMethod() && var3.getClassName().equals(par1StackTraceElement.getClassName()) && var3.getFileName().equals(par1StackTraceElement.getFileName()) && var3.getMethodName().equals(par1StackTraceElement.getMethodName()))
    142            {
    143                if (par2StackTraceElement != null != this.stackTrace.length > 1)
    144                {
    145                    return false;
    146                }
    147                else if (par2StackTraceElement != null && !this.stackTrace[1].equals(par2StackTraceElement))
    148                {
    149                    return false;
    150                }
    151                else
    152                {
    153                    this.stackTrace[0] = par1StackTraceElement;
    154                    return true;
    155                }
    156            }
    157            else
    158            {
    159                return false;
    160            }
    161        }
    162        else
    163        {
    164            return false;
    165        }
    166    }
    167
    168    public void func_85070_b(int par1)
    169    {
    170        StackTraceElement[] var2 = new StackTraceElement[this.stackTrace.length - par1];
    171        System.arraycopy(this.stackTrace, 0, var2, 0, var2.length);
    172        this.stackTrace = var2;
    173    }
    174
    175    public void func_85072_a(StringBuilder par1StringBuilder)
    176    {
    177        par1StringBuilder.append("-- ").append(this.field_85076_b).append(" --\n");
    178        par1StringBuilder.append("Details:");
    179        Iterator var2 = this.field_85077_c.iterator();
    180
    181        while (var2.hasNext())
    182        {
    183            CrashReportCategoryEntry var3 = (CrashReportCategoryEntry)var2.next();
    184            par1StringBuilder.append("\n\t");
    185            par1StringBuilder.append(var3.func_85089_a());
    186            par1StringBuilder.append(": ");
    187            par1StringBuilder.append(var3.func_85090_b());
    188        }
    189
    190        if (this.stackTrace != null && this.stackTrace.length > 0)
    191        {
    192            par1StringBuilder.append("\nStacktrace:");
    193            StackTraceElement[] var6 = this.stackTrace;
    194            int var7 = var6.length;
    195
    196            for (int var4 = 0; var4 < var7; ++var4)
    197            {
    198                StackTraceElement var5 = var6[var4];
    199                par1StringBuilder.append("\n\tat ");
    200                par1StringBuilder.append(var5.toString());
    201            }
    202        }
    203    }
    204
    205    public static void func_85068_a(CrashReportCategory par0CrashReportCategory, int par1, int par2, int par3, int par4, int par5)
    206    {
    207        par0CrashReportCategory.addCrashSectionCallable("Block type", new CallableBlockType(par4));
    208        par0CrashReportCategory.addCrashSectionCallable("Block data value", new CallableBlockDataValue(par5));
    209        par0CrashReportCategory.addCrashSectionCallable("Block location", new CallableBlockLocation(par1, par2, par3));
    210    }
    211}