    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 stringbuilder = new StringBuilder();
    033
    034        try
    035        {
    036            stringbuilder.append(String.format("World: (%d,%d,%d)", new Object[] {Integer.valueOf(par0), Integer.valueOf(par1), Integer.valueOf(par2)}));
    037        }
    038        catch (Throwable throwable)
    039        {
    040            stringbuilder.append("(Error finding world loc)");
    041        }
    042
    043        stringbuilder.append(", ");
    044        int l;
    045        int i1;
    046        int j1;
    047        int k1;
    048        int l1;
    049        int i2;
    050        int j2;
    051        int k2;
    052        int l2;
    053
    054        try
    055        {
    056            l = par0 >> 4;
    057            i1 = par2 >> 4;
    058            j1 = par0 & 15;
    059            k1 = par1 >> 4;
    060            l1 = par2 & 15;
    061            i2 = l << 4;
    062            j2 = i1 << 4;
    063            k2 = (l + 1 << 4) - 1;
    064            l2 = (i1 + 1 << 4) - 1;
    065            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)}));
    066        }
    067        catch (Throwable throwable1)
    068        {
    069            stringbuilder.append("(Error finding chunk loc)");
    070        }
    071
    072        stringbuilder.append(", ");
    073
    074        try
    075        {
    076            l = par0 >> 9;
    077            i1 = par2 >> 9;
    078            j1 = l << 5;
    079            k1 = i1 << 5;
    080            l1 = (l + 1 << 5) - 1;
    081            i2 = (i1 + 1 << 5) - 1;
    082            j2 = l << 9;
    083            k2 = i1 << 9;
    084            l2 = (l + 1 << 9) - 1;
    085            int i3 = (i1 + 1 << 9) - 1;
    086            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(l), Integer.valueOf(i1), Integer.valueOf(j1), Integer.valueOf(k1), Integer.valueOf(l1), Integer.valueOf(i2), Integer.valueOf(j2), Integer.valueOf(k2), Integer.valueOf(l2), Integer.valueOf(i3)}));
    087        }
    088        catch (Throwable throwable2)
    089        {
    090            stringbuilder.append("(Error finding world loc)");
    091        }
    092
    093        return stringbuilder.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 throwable)
    106        {
    107            this.addCrashSectionThrowable(par1Str, throwable);
    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[] astacktraceelement = Thread.currentThread().getStackTrace();
    130        this.stackTrace = new StackTraceElement[astacktraceelement.length - 3 - par1];
    131        System.arraycopy(astacktraceelement, 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 stacktraceelement2 = this.stackTrace[0];
    140
    141            if (stacktraceelement2.isNativeMethod() == par1StackTraceElement.isNativeMethod() && stacktraceelement2.getClassName().equals(par1StackTraceElement.getClassName()) && stacktraceelement2.getFileName().equals(par1StackTraceElement.getFileName()) && stacktraceelement2.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[] astacktraceelement = new StackTraceElement[this.stackTrace.length - par1];
    171        System.arraycopy(this.stackTrace, 0, astacktraceelement, 0, astacktraceelement.length);
    172        this.stackTrace = astacktraceelement;
    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 iterator = this.field_85077_c.iterator();
    180
    181        while (iterator.hasNext())
    182        {
    183            CrashReportCategoryEntry crashreportcategoryentry = (CrashReportCategoryEntry)iterator.next();
    184            par1StringBuilder.append("\n\t");
    185            par1StringBuilder.append(crashreportcategoryentry.func_85089_a());
    186            par1StringBuilder.append(": ");
    187            par1StringBuilder.append(crashreportcategoryentry.func_85090_b());
    188        }
    189
    190        if (this.stackTrace != null && this.stackTrace.length > 0)
    191        {
    192            par1StringBuilder.append("\nStacktrace:");
    193            StackTraceElement[] astacktraceelement = this.stackTrace;
    194            int i = astacktraceelement.length;
    195
    196            for (int j = 0; j < i; ++j)
    197            {
    198                StackTraceElement stacktraceelement = astacktraceelement[j];
    199                par1StringBuilder.append("\n\tat ");
    200                par1StringBuilder.append(stacktraceelement.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}