Search in sources :

Example 1 with ChunkSource

use of net.minecraft.world.level.chunk.ChunkSource in project SpongeCommon by SpongePowered.

the class LevelMixin_API method loadChunk.

@Override
public Optional<WorldChunk> loadChunk(final int cx, final int cy, final int cz, final boolean shouldGenerate) {
    if (!SpongeChunkLayout.INSTANCE.isValidChunk(cx, cy, cz)) {
        return Optional.empty();
    }
    final ChunkSource chunkProvider = ((LevelAccessor) this).getChunkSource();
    // If we aren't generating, return the chunk
    final ChunkStatus status = shouldGenerate ? ChunkStatus.EMPTY : ChunkStatus.FULL;
    @Nullable final ChunkAccess chunkAccess = chunkProvider.getChunk(cx, cz, status, true);
    if (chunkAccess == null) {
        return Optional.empty();
    }
    if (chunkAccess instanceof ImposterProtoChunk) {
        return Optional.of((WorldChunk) ((ImposterProtoChunk) chunkAccess).getWrapped());
    }
    return Optional.of((WorldChunk) chunkAccess);
}
Also used : ChunkSource(net.minecraft.world.level.chunk.ChunkSource) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelAccessor(net.minecraft.world.level.LevelAccessor) ChunkStatus(net.minecraft.world.level.chunk.ChunkStatus) ImposterProtoChunk(net.minecraft.world.level.chunk.ImposterProtoChunk) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 2 with ChunkSource

use of net.minecraft.world.level.chunk.ChunkSource in project SpongeCommon by SpongePowered.

the class DamageEventUtil method findFirstMatchingBlock.

public static ServerLocation findFirstMatchingBlock(final Entity entity, final AABB bb, final Predicate<BlockState> predicate) {
    final int i = Mth.floor(bb.minX);
    final int j = Mth.floor(bb.maxX + 1.0D);
    final int k = Mth.floor(bb.minY);
    final int l = Mth.floor(bb.maxY + 1.0D);
    final int i1 = Mth.floor(bb.minZ);
    final int j1 = Mth.floor(bb.maxZ + 1.0D);
    final ChunkSource chunkSource = entity.level.getChunkSource();
    for (int k1 = i; k1 < j; ++k1) {
        for (int l1 = k; l1 < l; ++l1) {
            for (int i2 = i1; i2 < j1; ++i2) {
                final BlockPos blockPos = new BlockPos(k1, l1, i2);
                final LevelChunk chunk = chunkSource.getChunk(blockPos.getX() >> 4, blockPos.getZ() >> 4, false);
                if (chunk == null || chunk.isEmpty()) {
                    continue;
                }
                if (predicate.test(chunk.getBlockState(blockPos))) {
                    return ServerLocation.of((ServerWorld) entity.level, k1, l1, i2);
                }
            }
        }
    }
    // Entity is source of fire
    return ((org.spongepowered.api.entity.Entity) entity).serverLocation();
}
Also used : ChunkSource(net.minecraft.world.level.chunk.ChunkSource) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) BlockPos(net.minecraft.core.BlockPos)

Example 3 with ChunkSource

use of net.minecraft.world.level.chunk.ChunkSource in project SpongeCommon by SpongePowered.

the class LevelMixin_API method loadedChunks.

@Override
public Iterable<WorldChunk> loadedChunks() {
    final ChunkSource chunkProvider = ((LevelAccessor) this).getChunkSource();
    if (chunkProvider instanceof ServerChunkCache) {
        final ChunkMapAccessor chunkManager = (ChunkMapAccessor) ((ServerChunkCache) chunkProvider).chunkMap;
        final List<WorldChunk> chunks = new ArrayList<>();
        chunkManager.invoker$getChunks().forEach(holder -> {
            final WorldChunk chunk = (WorldChunk) holder.getTickingChunk();
            if (chunk != null) {
                chunks.add(chunk);
            }
        });
        return chunks;
    }
    return Collections.emptyList();
}
Also used : ChunkSource(net.minecraft.world.level.chunk.ChunkSource) LevelAccessor(net.minecraft.world.level.LevelAccessor) ChunkMapAccessor(org.spongepowered.common.accessor.server.level.ChunkMapAccessor) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) ArrayList(java.util.ArrayList) ServerChunkCache(net.minecraft.server.level.ServerChunkCache)

Aggregations

ChunkSource (net.minecraft.world.level.chunk.ChunkSource)3 LevelAccessor (net.minecraft.world.level.LevelAccessor)2 ArrayList (java.util.ArrayList)1 BlockPos (net.minecraft.core.BlockPos)1 ServerChunkCache (net.minecraft.server.level.ServerChunkCache)1 Entity (net.minecraft.world.entity.Entity)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 ChunkStatus (net.minecraft.world.level.chunk.ChunkStatus)1 ImposterProtoChunk (net.minecraft.world.level.chunk.ImposterProtoChunk)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 WorldChunk (org.spongepowered.api.world.chunk.WorldChunk)1 ChunkMapAccessor (org.spongepowered.common.accessor.server.level.ChunkMapAccessor)1