Search in sources :

Example 1 with ImposterProtoChunk

use of net.minecraft.world.level.chunk.ImposterProtoChunk 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 ImposterProtoChunk

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

the class ChunkMapMixin method impl$onLoad.

@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/chunk/LevelChunk;setLoaded(Z)V"), slice = @Slice(from = @At(value = "INVOKE", remap = false, target = "Lit/unimi/dsi/fastutil/longs/LongSet;add(J)Z"), to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;addAllPendingBlockEntities(Ljava/util/Collection;)V")))
private void impl$onLoad(final LevelChunk levelChunk, final boolean loaded) {
    levelChunk.setLoaded(true);
    final Vector3i chunkPos = new Vector3i(levelChunk.getPos().x, 0, levelChunk.getPos().z);
    if (ShouldFire.CHUNK_EVENT_LOAD) {
        final ChunkEvent.Load loadEvent = SpongeEventFactory.createChunkEventLoad(PhaseTracker.getInstance().currentCause(), ((WorldChunk) levelChunk), chunkPos, (ResourceKey) (Object) this.level.dimension().location());
        SpongeCommon.post(loadEvent);
    }
    for (final Direction dir : Constants.Chunk.CARDINAL_DIRECTIONS) {
        final Vector3i neighborPos = chunkPos.add(dir.asBlockOffset());
        ChunkAccess neighbor = this.level.getChunk(neighborPos.x(), neighborPos.z(), ChunkStatus.EMPTY, false);
        if (neighbor instanceof ImposterProtoChunk) {
            neighbor = ((ImposterProtoChunk) neighbor).getWrapped();
        }
        if (neighbor instanceof LevelChunk) {
            final int index = DirectionUtil.directionToIndex(dir);
            final int oppositeIndex = DirectionUtil.directionToIndex(dir.opposite());
            ((LevelChunkBridge) levelChunk).bridge$setNeighborChunk(index, (LevelChunk) neighbor);
            ((LevelChunkBridge) neighbor).bridge$setNeighborChunk(oppositeIndex, levelChunk);
        }
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Vector3i(org.spongepowered.math.vector.Vector3i) ImposterProtoChunk(net.minecraft.world.level.chunk.ImposterProtoChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) ChunkEvent(org.spongepowered.api.event.world.chunk.ChunkEvent) Direction(org.spongepowered.api.util.Direction) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)2 ImposterProtoChunk (net.minecraft.world.level.chunk.ImposterProtoChunk)2 LevelAccessor (net.minecraft.world.level.LevelAccessor)1 ChunkSource (net.minecraft.world.level.chunk.ChunkSource)1 ChunkStatus (net.minecraft.world.level.chunk.ChunkStatus)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 ChunkEvent (org.spongepowered.api.event.world.chunk.ChunkEvent)1 Direction (org.spongepowered.api.util.Direction)1 WorldChunk (org.spongepowered.api.world.chunk.WorldChunk)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 LevelChunkBridge (org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)1 Vector3i (org.spongepowered.math.vector.Vector3i)1