Search in sources :

Example 1 with LevelAccessor

use of org.spongepowered.common.accessor.world.level.LevelAccessor in project SpongeCommon by SpongePowered.

the class AddTileEntityToWorldWhileProcessingEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final ServerLevel serverWorld = pipeline.getServerWorld();
    final BlockEntity tileEntity = oldState.tileEntity;
    if (tileEntity == null) {
        return EffectResult.NULL_RETURN;
    }
    if (((LevelAccessor) serverWorld).accessor$updatingBlockEntities()) {
        ServerLevelAccessor.accessor$LOGGER().error("Adding block entity while ticking: {} @ {}", () -> Registry.BLOCK_ENTITY_TYPE.getKey(tileEntity.getType()), tileEntity::getBlockPos);
        final boolean add = ((LevelAccessor) serverWorld).accessor$pendingBlockEntities().add(tileEntity);
        if (add) {
            return new EffectResult(oldState.state, true);
        } else {
            return EffectResult.NULL_RETURN;
        }
    }
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelAccessor(org.spongepowered.common.accessor.server.level.ServerLevelAccessor) LevelAccessor(org.spongepowered.common.accessor.world.level.LevelAccessor) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 2 with LevelAccessor

use of org.spongepowered.common.accessor.world.level.LevelAccessor in project SpongeCommon by SpongePowered.

the class RemoveProposedTileEntitiesDuringSetIfWorldProcessingEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final ServerLevel serverWorld = pipeline.getServerWorld();
    @Nullable final BlockEntity tileEntity = oldState.tileEntity;
    final BlockPos pos = oldState.pos;
    if (tileEntity == null || tileEntity.isRemoved()) {
        return EffectResult.NULL_RETURN;
    }
    if (((LevelAccessor) serverWorld).accessor$updatingBlockEntities()) {
        final Iterator<BlockEntity> iterator = ((LevelAccessor) serverWorld).accessor$pendingBlockEntities().iterator();
        while (iterator.hasNext()) {
            final BlockEntity tileentity = iterator.next();
            if (tileentity.getBlockPos().equals(pos)) {
                tileentity.setRemoved();
                iterator.remove();
            }
        }
        serverWorld.blockEntityList.add(tileEntity);
        return EffectResult.NULL_RETURN;
    }
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelAccessor(org.spongepowered.common.accessor.world.level.LevelAccessor) BlockPos(net.minecraft.core.BlockPos) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with LevelAccessor

use of org.spongepowered.common.accessor.world.level.LevelAccessor in project SpongeCommon by SpongePowered.

the class RemoveTileEntityFromWorldEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    @Nullable final BlockEntity tileEntity = oldState.tileEntity;
    if (tileEntity == null) {
        return EffectResult.NULL_RETURN;
    }
    final ServerLevel serverWorld = pipeline.getServerWorld();
    final LevelAccessor worldAccessor = (LevelAccessor) serverWorld;
    if (worldAccessor.accessor$updatingBlockEntities()) {
        tileEntity.setRemoved();
        worldAccessor.accessor$pendingBlockEntities().remove(tileEntity);
        return EffectResult.NULL_RETURN;
    }
    worldAccessor.accessor$pendingBlockEntities().remove(tileEntity);
    serverWorld.blockEntityList.remove(tileEntity);
    serverWorld.tickableBlockEntities.remove(tileEntity);
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelAccessor(org.spongepowered.common.accessor.world.level.LevelAccessor) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)3 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)3 LevelAccessor (org.spongepowered.common.accessor.world.level.LevelAccessor)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 BlockPos (net.minecraft.core.BlockPos)1 ServerLevelAccessor (org.spongepowered.common.accessor.server.level.ServerLevelAccessor)1