Search in sources :

Example 11 with CrashReport

use of net.minecraft.crash.CrashReport in project OreSpawn by MinecraftModDevelopmentMods.

the class FeatureRegistry method writeFeatures.

public void writeFeatures(File file) {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonArray root = new JsonArray();
    registry.getEntries().stream().map(ent -> {
        JsonObject e = new JsonObject();
        e.addProperty("name", ent.getKey().getResourcePath());
        e.addProperty("class", ent.getValue().getClass().getName());
        return e;
    }).forEach(root::add);
    String json = gson.toJson(root);
    try {
        FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8);
    } catch (IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config " + file.getName());
        report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
        OreSpawn.LOGGER.info(report.getCompleteReport());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) OreSpawn(com.mcmoddev.orespawn.OreSpawn) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) JsonParser(com.google.gson.JsonParser) IFeature(com.mcmoddev.orespawn.api.IFeature) Constructor(java.lang.reflect.Constructor) IForgeRegistry(net.minecraftforge.registries.IForgeRegistry) File(java.io.File) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) CrashReport(net.minecraft.crash.CrashReport) JsonArray(com.google.gson.JsonArray) CharEncoding(org.apache.commons.codec.CharEncoding) Charset(java.nio.charset.Charset) TreeMap(java.util.TreeMap) Gson(com.google.gson.Gson) RegistryBuilder(net.minecraftforge.registries.RegistryBuilder) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) StringEscapeUtils(org.apache.commons.lang3.StringEscapeUtils) Collections(java.util.Collections) GsonBuilder(com.google.gson.GsonBuilder) CrashReport(net.minecraft.crash.CrashReport) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 12 with CrashReport

use of net.minecraft.crash.CrashReport in project OreSpawn by MinecraftModDevelopmentMods.

the class OreSpawnWriter method saveSingle.

private static void saveSingle(Path filePath, Gson gson) {
    JsonObject root = new JsonObject();
    root.addProperty(ConfigNames.FILE_VERSION, "2.0");
    JsonObject spawns = new JsonObject();
    String k = filePath.getFileName().toString();
    Path saveDir = Constants.CONFDIR.resolve("forced-saves");
    Path conf = saveDir.resolve(k);
    if (!saveDir.toFile().exists()) {
        saveDir.toFile().mkdirs();
    }
    try (BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) {
        OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> {
            JsonObject thisSpawn = new JsonObject();
            ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName);
            thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled());
            thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen());
            thisSpawn.addProperty(ConfigNames.FEATURE, spawnEntry.getFeature().getFeatureName());
            thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize());
            thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize());
            thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize());
            thisSpawn.add(ConfigNames.PARAMETERS, spawnEntry.getFeature().getFeatureParameters());
            spawns.add(spawnName, thisSpawn);
        });
        root.add(ConfigNames.SPAWNS, spawns);
        p.write(gson.toJson(root));
    } catch (IOException e) {
        CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config data " + conf.toString());
        report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION);
        OreSpawn.LOGGER.info(report.getCompleteReport());
    }
}
Also used : Path(java.nio.file.Path) ISpawnEntry(com.mcmoddev.orespawn.api.os3.ISpawnEntry) CrashReport(net.minecraft.crash.CrashReport) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 13 with CrashReport

use of net.minecraft.crash.CrashReport in project RFTools by McJty.

the class ElevatorTESR method renderBlock.

private static boolean renderBlock(BlockRendererDispatcher dispatcher, IBlockState state, BlockPos pos, IBlockAccess blockAccess, BufferBuilder worldRendererIn) {
    try {
        EnumBlockRenderType enumblockrendertype = state.getRenderType();
        if (enumblockrendertype == EnumBlockRenderType.INVISIBLE) {
            return false;
        } else {
            if (blockAccess.getWorldType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
                try {
                    state = state.getActualState(blockAccess, pos);
                } catch (Exception var8) {
                }
            }
            switch(enumblockrendertype) {
                case MODEL:
                    IBakedModel model = dispatcher.getModelForState(state);
                    state = state.getBlock().getExtendedState(state, blockAccess, pos);
                    return dispatcher.getBlockModelRenderer().renderModel(blockAccess, model, state, pos, worldRendererIn, false);
                case ENTITYBLOCK_ANIMATED:
                    return false;
                default:
                    return false;
            }
        }
    } catch (Throwable throwable) {
        CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Tesselating block in world");
        CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being tesselated");
        CrashReportCategory.addBlockInfo(crashreportcategory, pos, state.getBlock(), state.getBlock().getMetaFromState(state));
        throw new ReportedException(crashreport);
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ReportedException(net.minecraft.util.ReportedException) CrashReportCategory(net.minecraft.crash.CrashReportCategory) EnumBlockRenderType(net.minecraft.util.EnumBlockRenderType) ReportedException(net.minecraft.util.ReportedException)

Example 14 with CrashReport

use of net.minecraft.crash.CrashReport in project SpongeVanilla by SpongePowered.

the class MixinMinecraftServer method updateTimeLightAndEntities.

/**
 * @author Zidane
 * @reason Handles ticking the additional worlds loaded by Sponge.
 */
@Overwrite
public void updateTimeLightAndEntities() {
    this.profiler.startSection("jobs");
    synchronized (this.futureTaskQueue) {
        while (!this.futureTaskQueue.isEmpty()) {
            Util.runTask(this.futureTaskQueue.poll(), LOGGER);
        }
    }
    this.profiler.endStartSection("levels");
    // Sponge: Tick chunk loader
    tickChunkLoader();
    // Sponge start - Iterate over all our dimensions
    for (final ObjectIterator<Int2ObjectMap.Entry<WorldServer>> it = WorldManager.worldsIterator(); it.hasNext(); ) {
        Int2ObjectMap.Entry<WorldServer> entry = it.next();
        final WorldServer worldServer = entry.getValue();
        // Sponge end
        long i = System.nanoTime();
        if (entry.getIntKey() == 0 || this.getAllowNether()) {
            // Sponge start - copy from SpongeCommon MixinMinecraftServer
            IMixinWorldServer spongeWorld = (IMixinWorldServer) worldServer;
            if (spongeWorld.getChunkGCTickInterval() > 0) {
                spongeWorld.doChunkGC();
            }
            // Sponge end
            this.profiler.startSection(worldServer.getWorldInfo().getWorldName());
            if (this.tickCounter % 20 == 0) {
                this.profiler.startSection("timeSync");
                this.playerList.sendPacketToAllPlayersInDimension(new SPacketTimeUpdate(worldServer.getTotalWorldTime(), worldServer.getWorldTime(), worldServer.getGameRules().getBoolean("doDaylightCycle")), ((IMixinWorldServer) worldServer).getDimensionId());
                this.profiler.endSection();
            }
            this.profiler.startSection("tick");
            try {
                worldServer.tick();
            } catch (Throwable throwable1) {
                CrashReport crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world");
                worldServer.addWorldInfoToCrashReport(crashreport);
                throw new ReportedException(crashreport);
            }
            try {
                worldServer.updateEntities();
            } catch (Throwable throwable) {
                CrashReport crashreport1 = CrashReport.makeCrashReport(throwable, "Exception ticking world entities");
                worldServer.addWorldInfoToCrashReport(crashreport1);
                throw new ReportedException(crashreport1);
            }
            this.profiler.endSection();
            this.profiler.startSection("tracker");
            // Sponge start - copy from SpongeCommon MixinMinecraftServer
            if (spongeWorld.getChunkGCTickInterval() > 0) {
                worldServer.getChunkProvider().tick();
            }
            // Sponge end
            worldServer.getEntityTracker().tick();
            this.profiler.endSection();
            this.profiler.endSection();
        }
        // Sponge start - Write tick times to our custom map
        this.worldTickTimes.get(entry.getIntKey())[this.tickCounter % 100] = System.nanoTime() - i;
    // Sponge end
    }
    // Sponge start - Unload requested worlds
    this.profiler.endStartSection("dim_unloading");
    WorldManager.unloadQueuedWorlds();
    // Sponge end
    this.profiler.endStartSection("connection");
    this.getNetworkSystem().networkTick();
    this.profiler.endStartSection("players");
    this.playerList.onTick();
    this.profiler.endStartSection("tickables");
    for (int k = 0; k < this.tickables.size(); ++k) {
        this.tickables.get(k).update();
    }
    this.profiler.endSection();
}
Also used : SPacketTimeUpdate(net.minecraft.network.play.server.SPacketTimeUpdate) CrashReport(net.minecraft.crash.CrashReport) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) ReportedException(net.minecraft.util.ReportedException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 15 with CrashReport

use of net.minecraft.crash.CrashReport in project Wurst-MC-1.12 by Wurst-Imperium.

the class Mod method enableOnStartup.

public final void enableOnStartup() {
    enabled = true;
    active = enabled && !blocked;
    try {
        onToggle();
        onEnable();
    } catch (Throwable e) {
        CrashReport report = CrashReport.makeCrashReport(e, "Toggling Wurst mod");
        CrashReportCategory category = report.makeCategory("Affected mod");
        category.setDetail("Mod name", () -> name);
        category.setDetail("Attempted action", () -> "Enable on startup");
        throw new ReportedException(report);
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.util.ReportedException)

Aggregations

CrashReport (net.minecraft.crash.CrashReport)54 CrashReportCategory (net.minecraft.crash.CrashReportCategory)37 ReportedException (net.minecraft.util.ReportedException)36 IOException (java.io.IOException)15 BlockPos (net.minecraft.util.math.BlockPos)11 IBlockState (net.minecraft.block.state.IBlockState)7 Chunk (net.minecraft.world.chunk.Chunk)7 JsonArray (com.google.gson.JsonArray)6 JsonElement (com.google.gson.JsonElement)6 JsonObject (com.google.gson.JsonObject)6 JsonParser (com.google.gson.JsonParser)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 World (net.minecraft.world.World)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 Path (java.nio.file.Path)4 Block (net.minecraft.block.Block)4 BufferedWriter (java.io.BufferedWriter)3 JsonIOException (com.google.gson.JsonIOException)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2