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