Search in sources :

Example 71 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class AddBlockLootDropsEffect method processSideEffect.

@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final PhaseContext<@NonNull ?> phaseContext = PhaseTracker.getInstance().getPhaseContext();
    final ServerLevel world = pipeline.getServerWorld();
    @Nullable final BlockEntity existingTile = oldState.tileEntity;
    final BlockPos pos = oldState.pos;
    final LootContext.Builder lootBuilder = (new LootContext.Builder(world)).withRandom(world.random).withParameter(LootContextParams.ORIGIN, VecHelper.toVanillaVector3d(pos)).withParameter(LootContextParams.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParams.BLOCK_ENTITY, existingTile);
    phaseContext.populateLootContext(lootBuilder);
    return new EffectResult(newState, oldState.state.getDrops(lootBuilder), false);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LootContext(net.minecraft.world.level.storage.loot.LootContext) BlockPos(net.minecraft.core.BlockPos) Nullable(org.checkerframework.checker.nullness.qual.Nullable) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 72 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class AddTileEntityToTickableListEffect 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 (tileEntity instanceof TickableBlockEntity) {
        serverWorld.tickableBlockEntities.add(tileEntity);
    }
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 73 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class ExplodeBlockEffect method processSideEffect.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public EffectResult processSideEffect(final BlockPipeline pipeline, final PipelineCursor oldState, final BlockState newState, final SpongeBlockChangeFlag flag, final int limit) {
    final PhaseContext<@NonNull ?> phaseContext = PhaseTracker.getInstance().getPhaseContext();
    final ServerLevel world = pipeline.getServerWorld();
    final BlockPos pos = oldState.pos;
    if (phaseContext instanceof ExplosionContext) {
        oldState.state.getBlock().wasExploded(world, pos, ((ExplosionContext) phaseContext).getExplosion());
    }
    return EffectResult.NULL_PASS;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ExplosionContext(org.spongepowered.common.event.tracking.phase.general.ExplosionContext) BlockPos(net.minecraft.core.BlockPos)

Example 74 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class AddTileEntityToLoadedListInWorldEffect 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;
    }
    serverWorld.blockEntityList.add(tileEntity);
    return new EffectResult(oldState.state, false);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 75 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project SpongeCommon by SpongePowered.

the class SpawnEntityTransaction method restore.

@Override
public void restore(final PhaseContext<@NonNull ?> context, final SpawnEntityEvent event) {
    final ServerLevel serverWorld = this.worldSupplier.get();
    if (((ServerLevelAccessor) serverWorld).accessor$tickingEntities()) {
        // More than likely we could also be needing to remove the entity from both the entities to add
        // and the chunk.
        ((ServerLevelAccessor) serverWorld).accessor$toAddAfterTick().remove(this.entityToSpawn);
        ((ServerLevelAccessor) serverWorld).invoker$removeFromChunk(this.entityToSpawn);
    } else {
        serverWorld.despawn(this.entityToSpawn);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelAccessor(org.spongepowered.common.accessor.server.level.ServerLevelAccessor)

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