use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class EntityTravelToDimensionEventMixin_Forge method bridge$createSpongeEvent.
@Override
@Nullable
public Event bridge$createSpongeEvent() {
final Entity entity = ((EntityEvent) (Object) this).getEntity();
final ServerLevel toWorld = SpongeCommon.server().getLevel(this.dimension);
return SpongeEventFactory.createChangeEntityWorldEventPre(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.entity.Entity) entity, (org.spongepowered.api.world.server.ServerWorld) entity.getCommandSenderWorld(), (org.spongepowered.api.world.server.ServerWorld) toWorld, (org.spongepowered.api.world.server.ServerWorld) toWorld);
}
use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class UpdateOrCreateNewTileEntityPostPlacementEffect 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 LevelChunk chunk = pipeline.getAffectedChunk();
@Nullable final BlockEntity maybeNewTileEntity = chunk.getBlockEntity(oldState.pos, LevelChunk.EntityCreationType.CHECK);
if (((BlockStateBridge) newState).bridge$hasTileEntity()) {
if (maybeNewTileEntity == null) {
// tileentity1 = ((ITileEntityProvider)block).createNewTileEntity(this.world); // Vanilla
// tileentity1 = state.createTileEntity(this.world); // Forge
// We cast to our bridge for easy access
serverWorld.setBlockEntity(oldState.pos, ((BlockStateBridge) newState).bridge$createNewTileEntity(serverWorld));
} else {
maybeNewTileEntity.clearCache();
}
}
return EffectResult.NULL_PASS;
}
use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class ChunkPipeline method processChange.
@Nullable
public BlockState processChange(final PhaseContext<?> context, final BlockState currentState, final BlockState proposedState, final BlockPos pos, final int limit) {
if (this.chunkEffects.isEmpty()) {
return null;
}
final ServerLevel serverWorld = this.serverWorld.get();
final int oldOpacity = currentState.getLightBlock(serverWorld, pos);
final SpongeBlockChangeFlag flag = this.transaction.getBlockChangeFlag();
@Nullable final BlockEntity existing = this.chunkSupplier.get().getBlockEntity(pos, LevelChunk.EntityCreationType.CHECK);
PipelineCursor formerState = new PipelineCursor(currentState, oldOpacity, pos, existing, (Entity) null, limit);
for (final ResultingTransactionBySideEffect effect : this.chunkEffects) {
try (final EffectTransactor ignored = context.getTransactor().pushEffect(effect)) {
final EffectResult result = effect.effect.processSideEffect(this, formerState, proposedState, flag, limit);
if (result.hasResult) {
return result.resultingState;
}
if (formerState.drops.isEmpty() && !result.drops.isEmpty()) {
formerState = new PipelineCursor(currentState, oldOpacity, pos, existing, null, result.drops, limit);
}
}
}
// if we've gotten here, means something is wrong, we didn't build our effects right.
return null;
}
use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class UpdateLightSideEffect method processSideEffect.
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
if (!flag.updateLighting()) {
return EffectResult.NULL_PASS;
}
final int originalOpactiy = oldState.opacity;
final ServerLevel serverWorld = pipeline.getServerWorld();
final BlockState currentState = pipeline.getAffectedChunk().getBlockState(oldState.pos);
// ) {
if (oldState.state != currentState && (currentState.getLightBlock(serverWorld, oldState.pos) != originalOpactiy || currentState.getLightEmission() != oldState.state.getLightEmission() || currentState.useShapeForLightOcclusion() || oldState.state.useShapeForLightOcclusion())) {
// this.profiler.startSection("queueCheckLight");
serverWorld.getProfiler().push("queueCheckLight");
// this.getChunkProvider().getLightManager().checkBlock(pos);
serverWorld.getChunkSource().getLightEngine().checkBlock(oldState.pos);
// this.profiler.endSection();
serverWorld.getProfiler().pop();
}
return EffectResult.NULL_PASS;
}
use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.
the class ReplaceTileEntityInWorldEffect 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;
final BlockPos pos = oldState.pos;
if (tileEntity == null || tileEntity.isRemoved()) {
return EffectResult.NULL_RETURN;
}
pipeline.getAffectedChunk().setBlockEntity(pos, tileEntity);
serverWorld.addBlockEntity(tileEntity);
return EffectResult.NULL_RETURN;
}
Aggregations