use of net.minecraft.server.level.ServerLevel 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 net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class TrackingUtil method updateTickBlock.
@SuppressWarnings("rawtypes")
public static void updateTickBlock(final TrackedWorldBridge mixinWorld, final net.minecraft.world.level.block.state.BlockState block, final BlockPos pos, final Random random) {
final ServerLevel world = (ServerLevel) mixinWorld;
final org.spongepowered.api.world.server.ServerWorld apiWorld = (org.spongepowered.api.world.server.ServerWorld) world;
if (ShouldFire.TICK_BLOCK_EVENT) {
final BlockSnapshot snapshot = mixinWorld.bridge$createSnapshot(block, pos, BlockChangeFlags.NONE);
final TickBlockEvent event = SpongeEventFactory.createTickBlockEventScheduled(PhaseTracker.getCauseStackManager().currentCause(), snapshot);
SpongeCommon.post(event);
if (event.isCancelled()) {
return;
}
}
final LocatableBlock locatable = new SpongeLocatableBlockBuilder().world(apiWorld).position(pos.getX(), pos.getY(), pos.getZ()).state((BlockState) block).build();
final BlockTickContext phaseContext = TickPhase.Tick.BLOCK.createPhaseContext(PhaseTracker.SERVER).source(locatable);
// We have to associate any notifiers in case of scheduled block updates from other sources
final PhaseContext<@NonNull ?> currentContext = PhaseTracker.getInstance().getPhaseContext();
currentContext.appendNotifierPreBlockTick(world, pos, phaseContext);
try (final PhaseContext<@NonNull ?> context = phaseContext;
final Timing timing = ((TimingBridge) block.getBlock()).bridge$timings()) {
timing.startTiming();
context.buildAndSwitch();
PhaseTracker.LOGGER.trace(TrackingUtil.BLOCK_TICK, () -> "Wrapping Block Tick: " + block.toString());
block.tick(world, pos, random);
} catch (final Exception | NoClassDefFoundError e) {
PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, phaseContext);
}
}
use of net.minecraft.server.level.ServerLevel 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 net.minecraft.server.level.ServerLevel 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;
}
use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class NetherPortalType method findPortalInternal.
static Optional<BlockUtil.FoundRectangle> findPortalInternal(final ServerLocation location) {
final ServerLevel serverWorld = (ServerLevel) location.world();
final BlockPos position = VecHelper.toBlockPos(location.blockPosition());
return serverWorld.getPortalForcer().findPortalAround(position, serverWorld.dimension() == Level.NETHER);
}
Aggregations