Search in sources :

Example 1 with LevelReader

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

the class LevelChunkMixin_API method biomeStream.

@Override
public VolumeStream<WorldChunk, Biome> biomeStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
    final boolean shouldCarbonCopy = options.carbonCopy();
    final Vector3i size = max.sub(min).add(1, 1, 1);
    @MonotonicNonNull final ObjectArrayMutableBiomeBuffer backingVolume;
    if (shouldCarbonCopy) {
        final Registry<net.minecraft.world.level.biome.Biome> biomeRegistry = this.level.registryAccess().registry(Registry.BIOME_REGISTRY).map(wr -> ((Registry<net.minecraft.world.level.biome.Biome>) wr)).orElse(BuiltinRegistries.BIOME);
        backingVolume = new ObjectArrayMutableBiomeBuffer(min, size, VolumeStreamUtils.nativeToSpongeRegistry(biomeRegistry));
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<WorldChunk, Biome, net.minecraft.world.level.biome.Biome, ChunkAccess, BlockPos>generateStream(options, // Ref
    (WorldChunk) this, (LevelChunk) (Object) this, // Entity Accessor
    VolumeStreamUtils.getBiomesForChunkByPos((LevelReader) (Object) this, min, max), // IdentityFunction
    (pos, biome) -> {
        if (shouldCarbonCopy) {
            backingVolume.setBiome(pos, biome);
        }
    }, // Biome by block position
    (key, biome) -> key, // Filtered Position Entity Accessor
    (blockPos, world) -> {
        final net.minecraft.world.level.biome.Biome biome = shouldCarbonCopy ? backingVolume.getNativeBiome(blockPos.getX(), blockPos.getY(), blockPos.getZ()) : ((LevelReader) world.world()).getBiome(blockPos);
        return new Tuple<>(blockPos, biome);
    });
}
Also used : Arrays(java.util.Arrays) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Registry(net.minecraft.core.Registry) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Biome(org.spongepowered.api.world.biome.Biome) Mixin(org.spongepowered.asm.mixin.Mixin) ChunkBiomeContainerAccessor(org.spongepowered.common.accessor.world.level.chunk.ChunkBiomeContainerAccessor) Map(java.util.Map) DifficultyInstance(net.minecraft.world.DifficultyInstance) BuiltinRegistries(net.minecraft.data.BuiltinRegistries) ObjectArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ObjectArrayMutableBiomeBuffer) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StreamOptions(org.spongepowered.api.world.volume.stream.StreamOptions) Remap(org.spongepowered.asm.mixin.Interface.Remap) UUID(java.util.UUID) LevelReader(net.minecraft.world.level.LevelReader) Final(org.spongepowered.asm.mixin.Final) Collectors(java.util.stream.Collectors) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) EntityUtil(org.spongepowered.common.entity.EntityUtil) BlockState(org.spongepowered.api.block.BlockState) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) BlockPos(net.minecraft.core.BlockPos) ChunkBiomeContainer(net.minecraft.world.level.chunk.ChunkBiomeContainer) VolumeStreamUtils(org.spongepowered.common.world.volume.VolumeStreamUtils) HeightTypes(org.spongepowered.api.world.HeightTypes) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Level(net.minecraft.world.level.Level) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) NonNull(org.checkerframework.checker.nullness.qual.NonNull) DataContainer(org.spongepowered.api.data.persistence.DataContainer) ArrayMutableBlockBuffer(org.spongepowered.common.world.volume.buffer.block.ArrayMutableBlockBuffer) AABB(org.spongepowered.api.util.AABB) ClassInstanceMultiMap(net.minecraft.util.ClassInstanceMultiMap) ArrayList(java.util.ArrayList) BlockChangeFlag(org.spongepowered.api.world.BlockChangeFlag) ImmutableList(com.google.common.collect.ImmutableList) ObjectArrayMutableBlockEntityBuffer(org.spongepowered.common.world.volume.buffer.blockentity.ObjectArrayMutableBlockEntityBuffer) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Ticks(org.spongepowered.api.util.Ticks) VolumeStream(org.spongepowered.api.world.volume.stream.VolumeStream) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Tuple(net.minecraft.util.Tuple) Entity(org.spongepowered.api.entity.Entity) WorldLike(org.spongepowered.api.world.WorldLike) ChunkPos(net.minecraft.world.level.ChunkPos) Implements(org.spongepowered.asm.mixin.Implements) SpongeChunkLayout(org.spongepowered.common.world.storage.SpongeChunkLayout) Vector3d(org.spongepowered.math.vector.Vector3d) Heightmap(net.minecraft.world.level.levelgen.Heightmap) VecHelper(org.spongepowered.common.util.VecHelper) EntityType(org.spongepowered.api.entity.EntityType) SpongeTicks(org.spongepowered.common.util.SpongeTicks) Collections(java.util.Collections) Interface(org.spongepowered.asm.mixin.Interface) Intrinsic(org.spongepowered.asm.mixin.Intrinsic) Vector3i(org.spongepowered.math.vector.Vector3i) ObjectArrayMutableBiomeBuffer(org.spongepowered.common.world.volume.buffer.biome.ObjectArrayMutableBiomeBuffer) LevelReader(net.minecraft.world.level.LevelReader) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) Biome(org.spongepowered.api.world.biome.Biome) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) WorldChunk(org.spongepowered.api.world.chunk.WorldChunk) Vector3i(org.spongepowered.math.vector.Vector3i) BlockPos(net.minecraft.core.BlockPos) Tuple(net.minecraft.util.Tuple)

Example 2 with LevelReader

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

the class LevelMixin_API method entityStream.

@SuppressWarnings("unchecked")
@Override
public VolumeStream<W, Entity> entityStream(final Vector3i min, final Vector3i max, final StreamOptions options) {
    VolumeStreamUtils.validateStreamArgs(Objects.requireNonNull(min, "min"), Objects.requireNonNull(max, "max"), Objects.requireNonNull(options, "options"));
    final boolean shouldCarbonCopy = options.carbonCopy();
    final Vector3i size = max.sub(min).add(1, 1, 1);
    @MonotonicNonNull final ObjectArrayMutableEntityBuffer backingVolume;
    if (shouldCarbonCopy) {
        backingVolume = new ObjectArrayMutableEntityBuffer(min, size);
    } else {
        backingVolume = null;
    }
    return VolumeStreamUtils.<W, Entity, net.minecraft.world.entity.Entity, ChunkAccess, UUID>generateStream(min, max, options, // Ref
    (W) this, // IdentityFunction
    VolumeStreamUtils.getOrCloneEntityWithVolume(shouldCarbonCopy, backingVolume, (Level) (Object) this), // ChunkAccessor
    VolumeStreamUtils.getChunkAccessorByStatus((LevelReader) (Object) this, options.loadingStyle().generateArea()), // Entity -> UniqueID
    (key, entity) -> entity.getUUID(), // Entity Accessor
    (chunk) -> chunk instanceof LevelChunk ? VolumeStreamUtils.getEntitiesFromChunk(min, max, (LevelChunk) chunk) : Stream.empty(), // Filtered Position Entity Accessor
    (entityUuid, world) -> {
        final net.minecraft.world.entity.@Nullable Entity entity = shouldCarbonCopy ? (net.minecraft.world.entity.Entity) backingVolume.entity(entityUuid).orElse(null) : (net.minecraft.world.entity.Entity) ((WorldLike) world).entity(entityUuid).orElse(null);
        if (entity == null) {
            return null;
        }
        return new Tuple<>(entity.blockPosition(), entity);
    });
}
Also used : HumanEntity(org.spongepowered.common.entity.living.human.HumanEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity) Entity(org.spongepowered.api.entity.Entity) LevelReader(net.minecraft.world.level.LevelReader) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) Vector3i(org.spongepowered.math.vector.Vector3i) ObjectArrayMutableEntityBuffer(org.spongepowered.common.world.volume.buffer.entity.ObjectArrayMutableEntityBuffer) Level(net.minecraft.world.level.Level) UUID(java.util.UUID) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Tuple(net.minecraft.util.Tuple)

Example 3 with LevelReader

use of net.minecraft.world.level.LevelReader 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 4 with LevelReader

use of net.minecraft.world.level.LevelReader in project Tropicraft by Tropicraft.

the class PathStructureProcessor method getPathDirection.

@Nullable
protected Direction.Axis getPathDirection(LevelReader level, BlockPos seedPos, StructureTemplate.StructureBlockInfo current, StructurePlaceSettings settings, StructureTemplate template) {
    /*
         *  Use special marker jigsaw blocks to represent "vectors" of paths.
         *
         *  Each jigsaw with attachment type "tropicraft:path_center" is a different vector,
         *  with the facing representing the direction of the vector. A vector extends from
         *  the jigsaw block to the end of the structure in that direction, and 1 block to
         *  either side.
         */
    final StructurePlaceSettings infiniteBounds = settings.copy();
    infiniteBounds.setBoundingBox(BoundingBox.infinite());
    return VECTOR_CACHE.computeIfAbsent(settings, s -> // Find all jigsaw blocks
    template.filterBlocks(seedPos, infiniteBounds, Blocks.JIGSAW, true).stream().filter(// Filter for vector markers
    b -> b.nbt.getString("target").equals(Constants.MODID + ":path_center")).map(// Convert pos to structure local, extract facing
    bi -> new PathVector(level.getHeightmapPos(Heightmap.Types.WORLD_SURFACE_WG, bi.pos).subtract(seedPos), JigsawBlock.getFrontFacing(bi.state))).collect(Collectors.toList())).stream().filter(// Find vectors that contain this block
    pv -> pv.contains(current.pos.subtract(seedPos), settings)).findFirst().map(pv -> pv.dir.getAxis()).orElse(null);
}
Also used : AABB(net.minecraft.world.phys.AABB) Direction(net.minecraft.core.Direction) JigsawBlock(net.minecraft.world.level.block.JigsawBlock) LevelReader(net.minecraft.world.level.LevelReader) Collectors(java.util.stream.Collectors) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Blocks(net.minecraft.world.level.block.Blocks) List(java.util.List) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) Heightmap(net.minecraft.world.level.levelgen.Heightmap) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) Constants(net.tropicraft.Constants) Preconditions(com.google.common.base.Preconditions) Nullable(javax.annotation.Nullable) WeakHashMap(java.util.WeakHashMap) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Nullable(javax.annotation.Nullable)

Aggregations

LevelReader (net.minecraft.world.level.LevelReader)4 BlockPos (net.minecraft.core.BlockPos)3 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)3 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Tuple (net.minecraft.util.Tuple)2 Level (net.minecraft.world.level.Level)2 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)2 Heightmap (net.minecraft.world.level.levelgen.Heightmap)2 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)2 Entity (org.spongepowered.api.entity.Entity)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1