Search in sources :

Example 1 with ChunkBiomeContainerAccessor

use of org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor in project SpongeCommon by SpongePowered.

the class LevelAccessorMixin_API method setBiome.

// @formatter:on
// MutableBiomeVolume
@SuppressWarnings({ "ConstantConditions" })
default boolean setBiome(final int x, final int y, final int z, final org.spongepowered.api.world.biome.Biome biome) {
    Objects.requireNonNull(biome, "biome");
    final ChunkAccess iChunk = ((LevelReader) this).getChunk(new BlockPos(x, y, z));
    if (iChunk == null) {
        return false;
    }
    return VolumeStreamUtils.setBiomeOnNativeChunk(x, y, z, biome, () -> ((ChunkBiomeContainerAccessor) iChunk.getBiomes()), () -> iChunk.setUnsaved(true));
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) ChunkBiomeContainerAccessor(org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor) BlockPos(net.minecraft.core.BlockPos) LevelReader(net.minecraft.world.level.LevelReader)

Example 2 with ChunkBiomeContainerAccessor

use of org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor in project SpongeCommon by SpongePowered.

the class VolumeStreamUtils method setBiomeOnNativeChunk.

public static boolean setBiomeOnNativeChunk(final int x, final int y, final int z, final org.spongepowered.api.world.biome.Biome biome, final Supplier<@Nullable ChunkBiomeContainerAccessor> accessor, final Runnable finalizer) {
    @Nullable final ChunkBiomeContainerAccessor chunkBiomeContainerAccessor = accessor.get();
    if (chunkBiomeContainerAccessor == null) {
        return false;
    }
    final int maskedX = x & ChunkBiomeContainer.HORIZONTAL_MASK;
    final int maskedY = Mth.clamp(y, 0, ChunkBiomeContainer.VERTICAL_MASK);
    final int maskedZ = z & ChunkBiomeContainer.HORIZONTAL_MASK;
    final int WIDTH_BITS = ChunkBiomeContainerAccessor.accessor$WIDTH_BITS();
    final int posKey = maskedY << WIDTH_BITS + WIDTH_BITS | maskedZ << WIDTH_BITS | maskedX;
    final Biome[] biomes = chunkBiomeContainerAccessor.accessor$biomes();
    biomes[posKey] = (net.minecraft.world.level.biome.Biome) (Object) biome;
    finalizer.run();
    return true;
}
Also used : ChunkBiomeContainerAccessor(org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor) Biome(net.minecraft.world.level.biome.Biome) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

ChunkBiomeContainerAccessor (org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor)2 BlockPos (net.minecraft.core.BlockPos)1 LevelReader (net.minecraft.world.level.LevelReader)1 Biome (net.minecraft.world.level.biome.Biome)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1