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