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;
}
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;
}
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;
}
Aggregations