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