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