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