Search in sources :

Example 1 with PhaseTrackerCategory

use of org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory in project SpongeCommon by SpongePowered.

the class PhaseTracker method validateBlockForNeighborNotification.

public static Block validateBlockForNeighborNotification(final ServerLevel worldServer, final BlockPos pos, @Nullable Block blockIn, final BlockPos otherPos, final LevelChunk chunk) {
    if (blockIn == null) {
        // If the block is null, check with the PhaseState to see if it can perform a safe way
        final PhaseContext<?> currentContext = PhaseTracker.getInstance().getPhaseContext();
        final PhaseTrackerCategory trackerConfig = SpongeConfigs.getCommon().get().phaseTracker;
        if (currentContext.state == TickPhase.Tick.TILE_ENTITY) {
            // Try to save ourselves
            @Nullable final BlockEntity source = (BlockEntity) currentContext.getSource();
            @Nullable final BlockEntityType<?> type = Optional.ofNullable(source).map(BlockEntity::getType).orElse(null);
            if (type != null) {
                @Nullable ResourceLocation id = BlockEntityType.getKey(type);
                if (id == null) {
                    id = new ResourceLocation(source.getClass().getCanonicalName());
                }
                final Map<String, Boolean> autoFixedTiles = trackerConfig.autoFixNullSourceBlockProvidingBlockEntities;
                final boolean contained = autoFixedTiles.containsKey(type.toString());
                // based on whether the source is the same as the TileEntity.
                if (!contained) {
                    autoFixedTiles.put(id.toString(), pos.equals(source.getBlockPos()));
                }
                final boolean useTile = contained && autoFixedTiles.get(id.toString());
                if (useTile) {
                    blockIn = source.getBlockState().getBlock();
                } else {
                    blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
                }
                if (!contained && trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                    PhasePrinter.printNullSourceBlockWithTile(pos, blockIn, otherPos, id, useTile, new NullPointerException("Null Source Block For TileEntity Neighbor Notification"));
                }
            } else {
                blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
                if (trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                    PhasePrinter.printNullSourceBlockNeighborNotificationWithNoTileSource(pos, blockIn, otherPos, new NullPointerException("Null Source Block For Neighbor Notification"));
                }
            }
        } else {
            blockIn = (pos.getX() >> 4 == chunk.getPos().x && pos.getZ() >> 4 == chunk.getPos().z) ? chunk.getBlockState(pos).getBlock() : worldServer.getBlockState(pos).getBlock();
            if (trackerConfig.reportNullSourceBlocksOnNeighborNotifications) {
                PhasePrinter.printNullSourceForBlock(worldServer, pos, blockIn, otherPos, new NullPointerException("Null Source Block For Neighbor Notification"));
            }
        }
    }
    return blockIn;
}
Also used : PhaseTrackerCategory(org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory) ResourceLocation(net.minecraft.resources.ResourceLocation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with PhaseTrackerCategory

use of org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory in project SpongeCommon by SpongePowered.

the class PhasePrinter method checkMaxBlockProcessingDepth.

static boolean checkMaxBlockProcessingDepth(final IPhaseState<@NonNull ?> state, final PhaseContext<@NonNull ?> context, final int currentDepth) {
    final ConfigHandle<CommonConfig> globalConfigAdapter = SpongeConfigs.getCommon();
    final PhaseTrackerCategory trackerConfig = globalConfigAdapter.get().phaseTracker;
    int maxDepth = trackerConfig.maxBlockProcessingDepth;
    if (currentDepth < maxDepth) {
        return false;
    }
    if (!trackerConfig.verbose && PhasePrinter.printedExceptionForMaximumProcessDepth.contains(state)) {
        // We still want to abort processing even if we're not logigng an error
        return true;
    }
    PhasePrinter.printedExceptionForMaximumProcessDepth.add(state);
    final String message = String.format("Sponge is still trying to process captured blocks after %s iterations of depth-first processing." + " This is likely due to a mod doing something unusual.", currentDepth);
    PhasePrinter.printMessageWithCaughtException(PhasePrinter.EMPTY, "Maximum block processing depth exceeded!", message, state, context, null);
    return true;
}
Also used : PhaseTrackerCategory(org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory) CommonConfig(org.spongepowered.common.applaunch.config.common.CommonConfig)

Aggregations

PhaseTrackerCategory (org.spongepowered.common.applaunch.config.common.PhaseTrackerCategory)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 CommonConfig (org.spongepowered.common.applaunch.config.common.CommonConfig)1