base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,408 @@
package net.minecraft.crash;
import com.google.common.collect.Lists;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import net.minecraft.util.ReportedException;
import net.minecraft.world.gen.layer.IntCache;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CrashReport
{
private static final Logger LOGGER = LogManager.getLogger();
/** Description of the crash report. */
private final String description;
/** The Throwable that is the "cause" for this crash and Crash Report. */
private final Throwable cause;
/** Category of crash */
private final CrashReportCategory systemDetailsCategory = new CrashReportCategory(this, "System Details");
/** Holds the keys and values of all crash report sections. */
private final List<CrashReportCategory> crashReportSections = Lists.<CrashReportCategory>newArrayList();
/** File of crash report. */
private File crashReportFile;
/** Is true when the current category is the first in the crash report */
private boolean firstCategoryInCrashReport = true;
private StackTraceElement[] stacktrace = new StackTraceElement[0];
public CrashReport(String descriptionIn, Throwable causeThrowable)
{
this.description = descriptionIn;
this.cause = causeThrowable;
this.populateEnvironment();
}
/**
* Populates this crash report with initial information about the running server and operating system / java
* environment
*/
private void populateEnvironment()
{
this.systemDetailsCategory.addDetail("Minecraft Version", new ICrashReportDetail<String>()
{
public String call()
{
return "1.12.2";
}
});
this.systemDetailsCategory.addDetail("Operating System", new ICrashReportDetail<String>()
{
public String call()
{
return System.getProperty("os.name") + " (" + System.getProperty("os.arch") + ") version " + System.getProperty("os.version");
}
});
this.systemDetailsCategory.addDetail("Java Version", new ICrashReportDetail<String>()
{
public String call()
{
return System.getProperty("java.version") + ", " + System.getProperty("java.vendor");
}
});
this.systemDetailsCategory.addDetail("Java VM Version", new ICrashReportDetail<String>()
{
public String call()
{
return System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor");
}
});
this.systemDetailsCategory.addDetail("Memory", new ICrashReportDetail<String>()
{
public String call()
{
Runtime runtime = Runtime.getRuntime();
long i = runtime.maxMemory();
long j = runtime.totalMemory();
long k = runtime.freeMemory();
long l = i / 1024L / 1024L;
long i1 = j / 1024L / 1024L;
long j1 = k / 1024L / 1024L;
return k + " bytes (" + j1 + " MB) / " + j + " bytes (" + i1 + " MB) up to " + i + " bytes (" + l + " MB)";
}
});
this.systemDetailsCategory.addDetail("JVM Flags", new ICrashReportDetail<String>()
{
public String call()
{
RuntimeMXBean runtimemxbean = ManagementFactory.getRuntimeMXBean();
List<String> list = runtimemxbean.getInputArguments();
int i = 0;
StringBuilder stringbuilder = new StringBuilder();
for (String s : list)
{
if (s.startsWith("-X"))
{
if (i++ > 0)
{
stringbuilder.append(" ");
}
stringbuilder.append(s);
}
}
return String.format("%d total; %s", i, stringbuilder.toString());
}
});
this.systemDetailsCategory.addDetail("IntCache", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return IntCache.getCacheSizes();
}
});
net.minecraftforge.fml.common.FMLCommonHandler.instance().enhanceCrashReport(this, this.systemDetailsCategory);
}
/**
* Returns the description of the Crash Report.
*/
public String getDescription()
{
return this.description;
}
/**
* Returns the Throwable object that is the cause for the crash and Crash Report.
*/
public Throwable getCrashCause()
{
return this.cause;
}
/**
* Gets the various sections of the crash report into the given StringBuilder
*/
public void getSectionsInStringBuilder(StringBuilder builder)
{
if ((this.stacktrace == null || this.stacktrace.length <= 0) && !this.crashReportSections.isEmpty())
{
this.stacktrace = (StackTraceElement[])ArrayUtils.subarray(((CrashReportCategory)this.crashReportSections.get(0)).getStackTrace(), 0, 1);
}
if (this.stacktrace != null && this.stacktrace.length > 0)
{
builder.append("-- Head --\n");
builder.append("Thread: ").append(Thread.currentThread().getName()).append("\n");
builder.append("Stacktrace:\n");
for (StackTraceElement stacktraceelement : this.stacktrace)
{
builder.append("\t").append("at ").append((Object)stacktraceelement);
builder.append("\n");
}
builder.append("\n");
}
for (CrashReportCategory crashreportcategory : this.crashReportSections)
{
crashreportcategory.appendToStringBuilder(builder);
builder.append("\n\n");
}
this.systemDetailsCategory.appendToStringBuilder(builder);
}
/**
* Gets the stack trace of the Throwable that caused this crash report, or if that fails, the cause .toString().
*/
public String getCauseStackTraceOrString()
{
StringWriter stringwriter = null;
PrintWriter printwriter = null;
Throwable throwable = this.cause;
if (throwable.getMessage() == null)
{
if (throwable instanceof NullPointerException)
{
throwable = new NullPointerException(this.description);
}
else if (throwable instanceof StackOverflowError)
{
throwable = new StackOverflowError(this.description);
}
else if (throwable instanceof OutOfMemoryError)
{
throwable = new OutOfMemoryError(this.description);
}
throwable.setStackTrace(this.cause.getStackTrace());
}
String s = throwable.toString();
try
{
stringwriter = new StringWriter();
printwriter = new PrintWriter(stringwriter);
throwable.printStackTrace(printwriter);
s = stringwriter.toString();
}
finally
{
IOUtils.closeQuietly((Writer)stringwriter);
IOUtils.closeQuietly((Writer)printwriter);
}
return s;
}
/**
* Gets the complete report with headers, stack trace, and different sections as a string.
*/
public String getCompleteReport()
{
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append("---- Minecraft Crash Report ----\n");
net.minecraftforge.fml.common.asm.transformers.BlamingTransformer.onCrash(stringbuilder);
net.minecraftforge.fml.relauncher.CoreModManager.onCrash(stringbuilder);
stringbuilder.append("// ");
stringbuilder.append(getWittyComment());
stringbuilder.append("\n\n");
stringbuilder.append("Time: ");
stringbuilder.append((new SimpleDateFormat()).format(new Date()));
stringbuilder.append("\n");
stringbuilder.append("Description: ");
stringbuilder.append(this.description);
stringbuilder.append("\n\n");
stringbuilder.append(this.getCauseStackTraceOrString());
stringbuilder.append("\n\nA detailed walkthrough of the error, its code path and all known details is as follows:\n");
for (int i = 0; i < 87; ++i)
{
stringbuilder.append("-");
}
stringbuilder.append("\n\n");
this.getSectionsInStringBuilder(stringbuilder);
return stringbuilder.toString();
}
/**
* Gets the file this crash report is saved into.
*/
@SideOnly(Side.CLIENT)
public File getFile()
{
return this.crashReportFile;
}
/**
* Saves this CrashReport to the given file and returns a value indicating whether we were successful at doing so.
*/
public boolean saveToFile(File toFile)
{
if (this.crashReportFile != null)
{
return false;
}
else
{
if (toFile.getParentFile() != null)
{
toFile.getParentFile().mkdirs();
}
Writer writer = null;
boolean flag1;
try
{
writer = new OutputStreamWriter(new FileOutputStream(toFile), StandardCharsets.UTF_8);
writer.write(this.getCompleteReport());
this.crashReportFile = toFile;
boolean lvt_3_1_ = true;
return lvt_3_1_;
}
catch (Throwable throwable)
{
LOGGER.error("Could not save crash report to {}", toFile, throwable);
flag1 = false;
}
finally
{
IOUtils.closeQuietly(writer);
}
return flag1;
}
}
public CrashReportCategory getCategory()
{
return this.systemDetailsCategory;
}
/**
* Creates a CrashReportCategory
*/
public CrashReportCategory makeCategory(String name)
{
return this.makeCategoryDepth(name, 1);
}
/**
* Creates a CrashReportCategory for the given stack trace depth
*/
public CrashReportCategory makeCategoryDepth(String categoryName, int stacktraceLength)
{
CrashReportCategory crashreportcategory = new CrashReportCategory(this, categoryName);
if (this.firstCategoryInCrashReport)
{
int i = crashreportcategory.getPrunedStackTrace(stacktraceLength);
StackTraceElement[] astacktraceelement = this.cause.getStackTrace();
StackTraceElement stacktraceelement = null;
StackTraceElement stacktraceelement1 = null;
int j = astacktraceelement.length - i;
if (j < 0)
{
System.out.println("Negative index in crash report handler (" + astacktraceelement.length + "/" + i + ")");
}
if (astacktraceelement != null && 0 <= j && j < astacktraceelement.length)
{
stacktraceelement = astacktraceelement[j];
if (astacktraceelement.length + 1 - i < astacktraceelement.length)
{
stacktraceelement1 = astacktraceelement[astacktraceelement.length + 1 - i];
}
}
this.firstCategoryInCrashReport = crashreportcategory.firstTwoElementsOfStackTraceMatch(stacktraceelement, stacktraceelement1);
if (i > 0 && !this.crashReportSections.isEmpty())
{
CrashReportCategory crashreportcategory1 = this.crashReportSections.get(this.crashReportSections.size() - 1);
crashreportcategory1.trimStackTraceEntriesFromBottom(i);
}
else if (astacktraceelement != null && astacktraceelement.length >= i && 0 <= j && j < astacktraceelement.length)
{
this.stacktrace = new StackTraceElement[j];
System.arraycopy(astacktraceelement, 0, this.stacktrace, 0, this.stacktrace.length);
}
else
{
this.firstCategoryInCrashReport = false;
}
}
this.crashReportSections.add(crashreportcategory);
return crashreportcategory;
}
/**
* Gets a random witty comment for inclusion in this CrashReport
*/
private static String getWittyComment()
{
String[] astring = new String[] {"Who set us up the TNT?", "Everything's going to plan. No, really, that was supposed to happen.", "Uh... Did I do that?", "Oops.", "Why did you do that?", "I feel sad now :(", "My bad.", "I'm sorry, Dave.", "I let you down. Sorry :(", "On the bright side, I bought you a teddy bear!", "Daisy, daisy...", "Oh - I know what I did wrong!", "Hey, that tickles! Hehehe!", "I blame Dinnerbone.", "You should try our sister game, Minceraft!", "Don't be sad. I'll do better next time, I promise!", "Don't be sad, have a hug! <3", "I just don't know what went wrong :(", "Shall we play a game?", "Quite honestly, I wouldn't worry myself about that.", "I bet Cylons wouldn't have this problem.", "Sorry :(", "Surprise! Haha. Well, this is awkward.", "Would you like a cupcake?", "Hi. I'm Minecraft, and I'm a crashaholic.", "Ooh. Shiny.", "This doesn't make any sense!", "Why is it breaking :(", "Don't do that.", "Ouch. That hurt :(", "You're mean.", "This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]", "There are four lights!", "But it works on my machine."};
try
{
return astring[(int)(System.nanoTime() % (long)astring.length)];
}
catch (Throwable var2)
{
return "Witty comment unavailable :(";
}
}
/**
* Creates a crash report for the exception
*/
public static CrashReport makeCrashReport(Throwable causeIn, String descriptionIn)
{
CrashReport crashreport;
if (causeIn instanceof ReportedException)
{
crashreport = ((ReportedException)causeIn).getCrashReport();
}
else
{
crashreport = new CrashReport(descriptionIn, causeIn);
}
return crashreport;
}
}

View File

@@ -0,0 +1,317 @@
package net.minecraft.crash;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class CrashReportCategory
{
private final CrashReport crashReport;
private final String name;
private final List<CrashReportCategory.Entry> children = Lists.<CrashReportCategory.Entry>newArrayList();
private StackTraceElement[] stackTrace = new StackTraceElement[0];
public CrashReportCategory(CrashReport report, String name)
{
this.crashReport = report;
this.name = name;
}
@SideOnly(Side.CLIENT)
public static String getCoordinateInfo(double x, double y, double z)
{
return String.format("%.2f,%.2f,%.2f - %s", x, y, z, getCoordinateInfo(new BlockPos(x, y, z)));
}
public static String getCoordinateInfo(BlockPos pos)
{
return getCoordinateInfo(pos.getX(), pos.getY(), pos.getZ());
}
public static String getCoordinateInfo(int x, int y, int z)
{
StringBuilder stringbuilder = new StringBuilder();
try
{
stringbuilder.append(String.format("World: (%d,%d,%d)", x, y, z));
}
catch (Throwable var16)
{
stringbuilder.append("(Error finding world loc)");
}
stringbuilder.append(", ");
try
{
int i = x >> 4;
int j = z >> 4;
int k = x & 15;
int l = y >> 4;
int i1 = z & 15;
int j1 = i << 4;
int k1 = j << 4;
int l1 = (i + 1 << 4) - 1;
int i2 = (j + 1 << 4) - 1;
stringbuilder.append(String.format("Chunk: (at %d,%d,%d in %d,%d; contains blocks %d,0,%d to %d,255,%d)", k, l, i1, i, j, j1, k1, l1, i2));
}
catch (Throwable var15)
{
stringbuilder.append("(Error finding chunk loc)");
}
stringbuilder.append(", ");
try
{
int k2 = x >> 9;
int l2 = z >> 9;
int i3 = k2 << 5;
int j3 = l2 << 5;
int k3 = (k2 + 1 << 5) - 1;
int l3 = (l2 + 1 << 5) - 1;
int i4 = k2 << 9;
int j4 = l2 << 9;
int k4 = (k2 + 1 << 9) - 1;
int j2 = (l2 + 1 << 9) - 1;
stringbuilder.append(String.format("Region: (%d,%d; contains chunks %d,%d to %d,%d, blocks %d,0,%d to %d,255,%d)", k2, l2, i3, j3, k3, l3, i4, j4, k4, j2));
}
catch (Throwable var14)
{
stringbuilder.append("(Error finding world loc)");
}
return stringbuilder.toString();
}
/**
* Adds an additional section to this crash report category, resolved by calling the given callable.
*
* If the given callable throws an exception, a detail containing that exception will be created instead.
*/
public void addDetail(String nameIn, ICrashReportDetail<String> detail)
{
try
{
this.addCrashSection(nameIn, detail.call());
}
catch (Throwable throwable)
{
this.addCrashSectionThrowable(nameIn, throwable);
}
}
/**
* Adds a Crashreport section with the given name with the given value (convered .toString())
*/
public void addCrashSection(String sectionName, Object value)
{
this.children.add(new CrashReportCategory.Entry(sectionName, value));
}
/**
* Adds a Crashreport section with the given name with the given Throwable
*/
public void addCrashSectionThrowable(String sectionName, Throwable throwable)
{
this.addCrashSection(sectionName, throwable);
}
/**
* Resets our stack trace according to the current trace, pruning the deepest 3 entries. The parameter indicates
* how many additional deepest entries to prune. Returns the number of entries in the resulting pruned stack trace.
*/
public int getPrunedStackTrace(int size)
{
StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace();
if (astacktraceelement.length <= 0)
{
return 0;
}
else
{
int len = astacktraceelement.length - 3 - size;
// Really Mojang, Still, god damn...
if (len <= 0) len = astacktraceelement.length;
this.stackTrace = new StackTraceElement[len];
System.arraycopy(astacktraceelement, astacktraceelement.length - len, this.stackTrace, 0, this.stackTrace.length);
return this.stackTrace.length;
}
}
/**
* Do the deepest two elements of our saved stack trace match the given elements, in order from the deepest?
*/
public boolean firstTwoElementsOfStackTraceMatch(StackTraceElement s1, StackTraceElement s2)
{
if (this.stackTrace.length != 0 && s1 != null)
{
StackTraceElement stacktraceelement = this.stackTrace[0];
if (stacktraceelement.isNativeMethod() == s1.isNativeMethod() && stacktraceelement.getClassName().equals(s1.getClassName()) && stacktraceelement.getFileName().equals(s1.getFileName()) && stacktraceelement.getMethodName().equals(s1.getMethodName()))
{
if (s2 != null != this.stackTrace.length > 1)
{
return false;
}
else if (s2 != null && !this.stackTrace[1].equals(s2))
{
return false;
}
else
{
this.stackTrace[0] = s1;
return true;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* Removes the given number entries from the bottom of the stack trace.
*/
public void trimStackTraceEntriesFromBottom(int amount)
{
StackTraceElement[] astacktraceelement = new StackTraceElement[this.stackTrace.length - amount];
System.arraycopy(this.stackTrace, 0, astacktraceelement, 0, astacktraceelement.length);
this.stackTrace = astacktraceelement;
}
public void appendToStringBuilder(StringBuilder builder)
{
builder.append("-- ").append(this.name).append(" --\n");
builder.append("Details:");
for (CrashReportCategory.Entry crashreportcategory$entry : this.children)
{
builder.append("\n\t");
builder.append(crashreportcategory$entry.getKey());
builder.append(": ");
builder.append(crashreportcategory$entry.getValue());
}
if (this.stackTrace != null && this.stackTrace.length > 0)
{
builder.append("\nStacktrace:");
for (StackTraceElement stacktraceelement : this.stackTrace)
{
builder.append("\n\tat ");
builder.append((Object)stacktraceelement);
}
}
}
public StackTraceElement[] getStackTrace()
{
return this.stackTrace;
}
public static void addBlockInfo(CrashReportCategory category, final BlockPos pos, final Block blockIn, final int blockData)
{
final int i = Block.getIdFromBlock(blockIn);
category.addDetail("Block type", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
try
{
return String.format("ID #%d (%s // %s // %s)", i, blockIn.getUnlocalizedName(), blockIn.getClass().getName(), blockIn.getRegistryName());
}
catch (Throwable var2)
{
return "ID #" + i;
}
}
});
category.addDetail("Block data value", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
if (blockData < 0)
{
return "Unknown? (Got " + blockData + ")";
}
else
{
String s = String.format("%4s", Integer.toBinaryString(blockData)).replace(" ", "0");
return String.format("%1$d / 0x%1$X / 0b%2$s", blockData, s);
}
}
});
category.addDetail("Block location", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return CrashReportCategory.getCoordinateInfo(pos);
}
});
}
public static void addBlockInfo(CrashReportCategory category, final BlockPos pos, final IBlockState state)
{
category.addDetail("Block", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return state.toString();
}
});
category.addDetail("Block location", new ICrashReportDetail<String>()
{
public String call() throws Exception
{
return CrashReportCategory.getCoordinateInfo(pos);
}
});
}
static class Entry
{
private final String key;
private final String value;
public Entry(String key, Object value)
{
this.key = key;
if (value == null)
{
this.value = "~~NULL~~";
}
else if (value instanceof Throwable)
{
Throwable throwable = (Throwable)value;
this.value = "~~ERROR~~ " + throwable.getClass().getSimpleName() + ": " + throwable.getMessage();
}
else
{
this.value = value.toString();
}
}
public String getKey()
{
return this.key;
}
public String getValue()
{
return this.value;
}
}
}

View File

@@ -0,0 +1,7 @@
package net.minecraft.crash;
import java.util.concurrent.Callable;
public interface ICrashReportDetail<V> extends Callable<V>
{
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.crash;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;