Search in sources :

Example 1 with ReportedException

use of net.minecraft.crash.ReportedException in project Arclight by IzzelAliz.

the class MinecraftServerMixin method run.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void run() {
    try {
        if (this.init()) {
            ServerLifecycleHooks.handleServerStarted((MinecraftServer) (Object) this);
            this.serverTime = Util.milliTime();
            this.statusResponse.setServerDescription(new StringTextComponent(this.motd));
            this.statusResponse.setVersion(new ServerStatusResponse.Version(SharedConstants.getVersion().getName(), SharedConstants.getVersion().getProtocolVersion()));
            this.applyServerIconToResponse(this.statusResponse);
            Arrays.fill(recentTps, 20);
            long curTime, tickSection = Util.milliTime(), tickCount = 1;
            while (this.serverRunning) {
                long i = (curTime = Util.milliTime()) - this.serverTime;
                if (i > 5000L && this.serverTime - this.timeOfLastWarning >= 30000L) {
                    long j = i / 50L;
                    if (server.getWarnOnOverload()) {
                        LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
                    }
                    this.serverTime += j * 50L;
                    this.timeOfLastWarning = this.serverTime;
                }
                if (tickCount++ % SAMPLE_INTERVAL == 0) {
                    double currentTps = 1E3 / (curTime - tickSection) * SAMPLE_INTERVAL;
                    // 1/exp(5sec/1min)
                    recentTps[0] = calcTps(recentTps[0], 0.92, currentTps);
                    // 1/exp(5sec/5min)
                    recentTps[1] = calcTps(recentTps[1], 0.9835, currentTps);
                    // 1/exp(5sec/15min)
                    recentTps[2] = calcTps(recentTps[2], 0.9945, currentTps);
                    tickSection = curTime;
                }
                currentTick = (int) (System.currentTimeMillis() / 50);
                this.serverTime += 50L;
                if (this.startProfiling) {
                    this.startProfiling = false;
                    this.profiler.getFixedProfiler().enable();
                }
                this.profiler.startTick();
                this.profiler.startSection("tick");
                this.tick(this::isAheadOfTime);
                this.profiler.endStartSection("nextTickWait");
                this.isRunningScheduledTasks = true;
                this.runTasksUntil = Math.max(Util.milliTime() + 50L, this.serverTime);
                this.runScheduledTasks();
                this.profiler.endSection();
                this.profiler.endTick();
                this.serverIsRunning = true;
            }
            ServerLifecycleHooks.handleServerStopping((MinecraftServer) (Object) this);
            // has to come before finalTick to avoid race conditions
            ServerLifecycleHooks.expectServerStopped();
        } else {
            // has to come before finalTick to avoid race conditions
            ServerLifecycleHooks.expectServerStopped();
            this.finalTick(null);
        }
    } catch (StartupQuery.AbortedException e) {
        // ignore silently
        // has to come before finalTick to avoid race conditions
        ServerLifecycleHooks.expectServerStopped();
    } catch (Throwable throwable1) {
        LOGGER.error("Encountered an unexpected exception", throwable1);
        CrashReport crashreport;
        if (throwable1 instanceof ReportedException) {
            crashreport = this.addServerInfoToCrashReport(((ReportedException) throwable1).getCrashReport());
        } else {
            crashreport = this.addServerInfoToCrashReport(new CrashReport("Exception in server tick loop", throwable1));
        }
        File file1 = new File(new File(this.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
        if (crashreport.saveToFile(file1)) {
            LOGGER.error("This crash report has been saved to: {}", file1.getAbsolutePath());
        } else {
            LOGGER.error("We were unable to save this crash report to disk.");
        }
        // has to come before finalTick to avoid race conditions
        ServerLifecycleHooks.expectServerStopped();
        this.finalTick(crashreport);
    } finally {
        try {
            this.serverStopped = true;
            this.stopServer();
        } catch (Throwable throwable) {
            LOGGER.error("Exception stopping the server", throwable);
        } finally {
            ServerLifecycleHooks.handleServerStopped((MinecraftServer) (Object) this);
            this.systemExitNow();
        }
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) Date(java.util.Date) StartupQuery(net.minecraftforge.fml.StartupQuery) StringTextComponent(net.minecraft.util.text.StringTextComponent) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) ReportedException(net.minecraft.crash.ReportedException) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with ReportedException

use of net.minecraft.crash.ReportedException in project Arclight by IzzelAliz.

the class MinecraftServerMixin method initWorld.

public void initWorld(ServerWorld serverWorld, WorldInfo worldInfo, WorldSettings worldSettings) {
    serverWorld.getWorldBorder().copyFrom(worldInfo);
    if (((WorldBridge) serverWorld).bridge$getGenerator() != null) {
        ((WorldBridge) serverWorld).bridge$getWorld().getPopulators().addAll(((WorldBridge) serverWorld).bridge$getGenerator().getDefaultPopulators(((WorldBridge) serverWorld).bridge$getWorld()));
    }
    if (!worldInfo.isInitialized()) {
        try {
            serverWorld.createSpawnPosition(worldSettings);
            if (worldInfo.getGenerator() == WorldType.DEBUG_ALL_BLOCK_STATES) {
                this.applyDebugWorldInfo(worldInfo);
            }
            worldInfo.setInitialized(true);
        } catch (Throwable throwable) {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception initializing level");
            try {
                serverWorld.fillCrashReport(crashreport);
            } catch (Throwable ignored) {
            }
            throw new ReportedException(crashreport);
        }
        worldInfo.setInitialized(true);
    }
}
Also used : WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) CrashReport(net.minecraft.crash.CrashReport) ReportedException(net.minecraft.crash.ReportedException)

Example 3 with ReportedException

use of net.minecraft.crash.ReportedException in project Structurize by ldtteam.

the class BlueprintRenderer method init.

private void init() {
    clearVertexBuffers();
    entities = BlueprintUtils.instantiateEntities(blockAccess.getBlueprint(), blockAccess);
    tileEntities = BlueprintUtils.instantiateTileEntities(blockAccess.getBlueprint(), blockAccess);
    final BlockRendererDispatcher blockRendererDispatcher = Minecraft.getInstance().getBlockRenderer();
    final Random random = new Random();
    final MatrixStack matrixStack = new MatrixStack();
    final List<BlockInfo> blocks = blockAccess.getBlueprint().getBlockInfoAsList();
    final Map<RenderType, VertexBuffer> newVertexBuffers = blockVertexBuffersFactory.get();
    for (final RenderType renderType : RenderType.chunkBufferLayers()) {
        final BufferBuilder buffer = new BufferBuilder(renderType.bufferSize());
        buffer.begin(renderType.mode(), renderType.format());
        for (final BlockInfo blockInfo : blocks) {
            try {
                BlockState state = blockInfo.getState();
                if ((state.getBlock() == ModBlocks.blockSubstitution.get() && Settings.instance.renderLightPlaceholders()) || state.getBlock() == ModBlocks.blockTagSubstitution.get()) {
                    state = Blocks.AIR.defaultBlockState();
                }
                if (state.getBlock() == ModBlocks.blockFluidSubstitution.get()) {
                    state = Minecraft.getInstance().level != null ? BlockUtils.getFluidForDimension(Minecraft.getInstance().level) : Blocks.WATER.defaultBlockState();
                }
                final BlockPos blockPos = blockInfo.getPos();
                final FluidState fluidState = state.getFluidState();
                matrixStack.pushPose();
                matrixStack.translate(blockPos.getX(), blockPos.getY(), blockPos.getZ());
                if (state.getRenderShape() != BlockRenderType.INVISIBLE && RenderTypeLookup.canRenderInLayer(state, renderType)) {
                    blockRendererDispatcher.renderModel(state, blockPos, blockAccess, matrixStack, buffer, true, random, EmptyModelData.INSTANCE);
                }
                if (!fluidState.isEmpty() && RenderTypeLookup.canRenderInLayer(fluidState, renderType)) {
                    FluidRenderer.render(blockAccess, blockPos, buffer, fluidState);
                }
                matrixStack.popPose();
            } catch (final ReportedException e) {
                LOGGER.error("Error while trying to render structure part: " + e.getMessage(), e.getCause());
            }
        }
        buffer.end();
        OptifineCompat.getInstance().beforeBuilderUpload(buffer);
        newVertexBuffers.get(renderType).upload(buffer);
    }
    vertexBuffers = newVertexBuffers;
}
Also used : VertexBuffer(net.minecraft.client.renderer.vertex.VertexBuffer) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) BlockRenderType(net.minecraft.block.BlockRenderType) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockInfo(com.ldtteam.structurize.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState) ReportedException(net.minecraft.crash.ReportedException)

Example 4 with ReportedException

use of net.minecraft.crash.ReportedException in project SophisticatedBackpacks by P3pp3rF1y.

the class GuiHelper method tryRenderGuiItem.

public static void tryRenderGuiItem(ItemRenderer itemRenderer, TextureManager textureManager, @Nullable LivingEntity livingEntity, ItemStack stack, int x, int y, int rotation) {
    if (!stack.isEmpty()) {
        itemRenderer.blitOffset += 50.0F;
        try {
            renderGuiItem(itemRenderer, textureManager, stack, x, y, itemRenderer.getModel(stack, null, livingEntity), rotation);
        } catch (Throwable throwable) {
            CrashReport crashreport = CrashReport.forThrowable(throwable, "Rendering item");
            CrashReportCategory crashreportcategory = crashreport.addCategory("Item being rendered");
            crashreportcategory.setDetail("Item Type", () -> String.valueOf(stack.getItem()));
            crashreportcategory.setDetail("Registry Name", () -> String.valueOf(stack.getItem().getRegistryName()));
            crashreportcategory.setDetail("Item Damage", () -> String.valueOf(stack.getDamageValue()));
            crashreportcategory.setDetail("Item NBT", () -> String.valueOf(stack.getTag()));
            crashreportcategory.setDetail("Item Foil", () -> String.valueOf(stack.hasFoil()));
            throw new ReportedException(crashreport);
        }
        itemRenderer.blitOffset -= 50.0F;
    }
}
Also used : CrashReport(net.minecraft.crash.CrashReport) CrashReportCategory(net.minecraft.crash.CrashReportCategory) ReportedException(net.minecraft.crash.ReportedException)

Aggregations

ReportedException (net.minecraft.crash.ReportedException)4 CrashReport (net.minecraft.crash.CrashReport)3 BlockInfo (com.ldtteam.structurize.util.BlockInfo)1 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Random (java.util.Random)1 BlockRenderType (net.minecraft.block.BlockRenderType)1 BlockState (net.minecraft.block.BlockState)1 VertexBuffer (net.minecraft.client.renderer.vertex.VertexBuffer)1 CrashReportCategory (net.minecraft.crash.CrashReportCategory)1 FluidState (net.minecraft.fluid.FluidState)1 ServerStatusResponse (net.minecraft.network.ServerStatusResponse)1 BlockPos (net.minecraft.util.math.BlockPos)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 StartupQuery (net.minecraftforge.fml.StartupQuery)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1