Search in sources :

Example 1 with StructureTemplate

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate 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

Preconditions (com.google.common.base.Preconditions)1 List (java.util.List)1 WeakHashMap (java.util.WeakHashMap)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 LevelReader (net.minecraft.world.level.LevelReader)1 Blocks (net.minecraft.world.level.block.Blocks)1 JigsawBlock (net.minecraft.world.level.block.JigsawBlock)1 Heightmap (net.minecraft.world.level.levelgen.Heightmap)1 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)1 StructurePlaceSettings (net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)1 StructureTemplate (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)1 AABB (net.minecraft.world.phys.AABB)1 Vec3 (net.minecraft.world.phys.Vec3)1 Constants (net.tropicraft.Constants)1