Search in sources :

Example 41 with ServerLevel

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);
}
Also used : Entity(net.minecraft.world.entity.Entity) ServerLevel(net.minecraft.server.level.ServerLevel) EntityEvent(net.minecraftforge.event.entity.EntityEvent) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 42 with ServerLevel

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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) BlockStateBridge(org.spongepowered.common.bridge.world.level.block.state.BlockStateBridge)

Example 43 with ServerLevel

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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeBlockChangeFlag(org.spongepowered.common.world.SpongeBlockChangeFlag) EffectResult(org.spongepowered.common.event.tracking.context.transaction.effect.EffectResult) ResultingTransactionBySideEffect(org.spongepowered.common.event.tracking.context.transaction.ResultingTransactionBySideEffect) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 44 with ServerLevel

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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState)

Example 45 with ServerLevel

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;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)115 BlockPos (net.minecraft.core.BlockPos)30 Nullable (org.checkerframework.checker.nullness.qual.Nullable)21 Level (net.minecraft.world.level.Level)20 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)16 Entity (net.minecraft.world.entity.Entity)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)11 ItemStack (net.minecraft.world.item.ItemStack)10 SpongeBlockSnapshot (org.spongepowered.common.block.SpongeBlockSnapshot)10 IOException (java.io.IOException)9 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)9 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)9 ArrayList (java.util.ArrayList)8 BlockState (net.minecraft.world.level.block.state.BlockState)8 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Vec3 (net.minecraft.world.phys.Vec3)7 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)7 Cause (org.spongepowered.api.event.Cause)7