Search in sources :

Example 6 with Rotation

use of net.minecraft.world.level.block.Rotation in project SolarCraftRepository by FINDERFEED.

the class CrystalBossRoomStructure method generatePieces.

private static void generatePieces(StructurePiecesBuilder p_197089_, PieceGenerator.Context<NoneFeatureConfiguration> ctx) {
    int x = (ctx.chunkPos().x << 4) + 7;
    int z = (ctx.chunkPos().z << 4) + 7;
    int surfaceY = ctx.chunkGenerator().getBaseHeight(x, z, Heightmap.Types.WORLD_SURFACE_WG, ctx.heightAccessor());
    BlockPos blockpos = new BlockPos(x, surfaceY, z);
    Rotation rotation = Rotation.getRandom(ctx.random());
    CrystalBossRoomStructurePieces.start(ctx.structureManager(), blockpos, rotation, p_197089_, ctx.random());
}
Also used : BlockPos(net.minecraft.core.BlockPos) Rotation(net.minecraft.world.level.block.Rotation)

Example 7 with Rotation

use of net.minecraft.world.level.block.Rotation in project SolarCraftRepository by FINDERFEED.

the class DimensionalShardStructure method generatePieces.

private static void generatePieces(StructurePiecesBuilder p_197089_, PieceGenerator.Context<NoneFeatureConfiguration> ctx) {
    int x = (ctx.chunkPos().x << 4) + 7;
    int z = (ctx.chunkPos().z << 4) + 7;
    int surfaceY = ctx.chunkGenerator().getBaseHeight(x, z, Heightmap.Types.WORLD_SURFACE_WG, ctx.heightAccessor());
    BlockPos blockpos = new BlockPos(x, surfaceY, z);
    Rotation rotation = Rotation.NONE;
    DimStructPieces.start(ctx.structureManager(), blockpos, rotation, p_197089_, ctx.random());
}
Also used : BlockPos(net.minecraft.core.BlockPos) Rotation(net.minecraft.world.level.block.Rotation)

Example 8 with Rotation

use of net.minecraft.world.level.block.Rotation in project Brass_Amber_BattleTowers by BrassAmber-Mods.

the class BTLandJigsawPlacement method addPieces.

public static Optional<PieceGenerator<BTJigsawConfiguration>> addPieces(PieceGeneratorSupplier.Context<BTJigsawConfiguration> context, BTLandJigsawPlacement.PieceFactory pieceFactory, BlockPos placementPos, boolean boundaryAdjust, boolean useHeightMap, boolean water) {
    WorldgenRandom worldgenrandom = new WorldgenRandom(new LegacyRandomSource(0L));
    worldgenrandom.setLargeFeatureSeed(context.seed(), context.chunkPos().x, context.chunkPos().z);
    RegistryAccess registryaccess = context.registryAccess();
    BTJigsawConfiguration jigsawconfiguration = context.config();
    ChunkGenerator chunkgenerator = context.chunkGenerator();
    StructureManager structuremanager = context.structureManager();
    LevelHeightAccessor levelheightaccessor = context.heightAccessor();
    Predicate<Biome> predicate = context.validBiome();
    StructureFeature.bootstrap();
    Registry<StructureTemplatePool> registry = registryaccess.registryOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
    Rotation rotation = Rotation.getRandom(worldgenrandom);
    watered = water;
    StructureTemplatePool structuretemplatepool = jigsawconfiguration.startPool().get();
    StructurePoolElement structurepoolelement = structuretemplatepool.getRandomTemplate(worldgenrandom);
    if (structurepoolelement == EmptyPoolElement.INSTANCE) {
        return Optional.empty();
    } else {
        PoolElementStructurePiece poolelementstructurepiece = pieceFactory.create(structuremanager, structurepoolelement, placementPos, structurepoolelement.getGroundLevelDelta(), rotation, structurepoolelement.getBoundingBox(structuremanager, placementPos, rotation));
        BoundingBox boundingbox = poolelementstructurepiece.getBoundingBox();
        int bbX = (boundingbox.maxX() + boundingbox.minX()) / 2;
        int bbZ = (boundingbox.maxZ() + boundingbox.minZ()) / 2;
        int ppY;
        if (useHeightMap) {
            ppY = placementPos.getY() + chunkgenerator.getFirstFreeHeight(bbX, bbZ, Heightmap.Types.WORLD_SURFACE_WG, levelheightaccessor);
        } else {
            ppY = placementPos.getY();
        }
        if (watered) {
            poolelementstructurepiece.move(0, -5, 0);
        }
        if (!predicate.test(chunkgenerator.getNoiseBiome(QuartPos.fromBlock(bbX), QuartPos.fromBlock(ppY), QuartPos.fromBlock(bbZ)))) {
            return Optional.empty();
        } else {
            int pieceYlevel = boundingbox.minY() + poolelementstructurepiece.getGroundLevelDelta();
            poolelementstructurepiece.move(0, ppY - pieceYlevel, 0);
            return Optional.of((piecesBuilder, pieceGenContext) -> {
                List<PoolElementStructurePiece> list = Lists.newArrayList();
                list.add(poolelementstructurepiece);
                if (jigsawconfiguration.maxDepth() > 0) {
                    int sizeLimit = 120;
                    AABB aabb = new AABB(bbX - sizeLimit, ppY - sizeLimit, bbZ - sizeLimit, bbX + sizeLimit + 1, ppY + sizeLimit + 1, bbZ + sizeLimit + 1);
                    BTLandJigsawPlacement.Placer BTLandJigsawPlacement$placer = new BTLandJigsawPlacement.Placer(registry, jigsawconfiguration.maxDepth(), pieceFactory, chunkgenerator, structuremanager, list, worldgenrandom);
                    BTLandJigsawPlacement$placer.placing.addLast(new BTLandJigsawPlacement.PieceState(poolelementstructurepiece, new MutableObject<>(Shapes.join(Shapes.create(aabb), Shapes.create(AABB.of(boundingbox)), BooleanOp.ONLY_FIRST)), 0));
                    while (!BTLandJigsawPlacement$placer.placing.isEmpty()) {
                        BTLandJigsawPlacement.PieceState BTLandJigsawPlacement$piecestate = BTLandJigsawPlacement$placer.placing.removeFirst();
                        BTLandJigsawPlacement$placer.tryPlacingChildren(BTLandJigsawPlacement$piecestate.piece, BTLandJigsawPlacement$piecestate.free, BTLandJigsawPlacement$piecestate.depth, boundaryAdjust, levelheightaccessor);
                    }
                    list.forEach(piecesBuilder::addPiece);
                }
            });
        }
    }
}
Also used : PoolElementStructurePiece(net.minecraft.world.level.levelgen.structure.PoolElementStructurePiece) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) Rotation(net.minecraft.world.level.block.Rotation) LevelHeightAccessor(net.minecraft.world.level.LevelHeightAccessor) Biome(net.minecraft.world.level.biome.Biome) LegacyRandomSource(net.minecraft.world.level.levelgen.LegacyRandomSource) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) WorldgenRandom(net.minecraft.world.level.levelgen.WorldgenRandom) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) AABB(net.minecraft.world.phys.AABB) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 9 with Rotation

use of net.minecraft.world.level.block.Rotation in project Create by Creators-of-Create.

the class ControllerRailBlock method onWrenched.

@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
    Level world = context.getLevel();
    if (world.isClientSide)
        return InteractionResult.SUCCESS;
    BlockPos pos = context.getClickedPos();
    for (Rotation testRotation : new Rotation[] { Rotation.CLOCKWISE_90, Rotation.CLOCKWISE_180, Rotation.COUNTERCLOCKWISE_90 }) {
        BlockState testState = rotate(state, testRotation);
        if (isStableWith(testState, world, pos)) {
            placeAndNotify(testState, pos, world);
            return InteractionResult.SUCCESS;
        }
    }
    BlockState testState = state.setValue(BACKWARDS, !state.getValue(BACKWARDS));
    if (isStableWith(testState, world, pos))
        placeAndNotify(testState, pos, world);
    return InteractionResult.SUCCESS;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Rotation(net.minecraft.world.level.block.Rotation)

Example 10 with Rotation

use of net.minecraft.world.level.block.Rotation in project The-Aether by Gilded-Games.

the class CrystalTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    WorldGenLevel reader = context.level();
    BlockPos pos = context.origin();
    Random rand = context.random();
    Rotation rotation = Rotation.getRandom(rand);
    StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
    StructureTemplate tree = templatemanager.getOrCreate(TREE);
    StructureTemplate fruit = templatemanager.getOrCreate(FRUIT);
    ChunkPos chunkpos = new ChunkPos(pos);
    BoundingBox mutableboundingbox = new BoundingBox(chunkpos.getMinBlockX(), 0, chunkpos.getMinBlockZ(), chunkpos.getMaxBlockX(), 256, chunkpos.getMaxBlockZ());
    StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setBoundingBox(mutableboundingbox).setRandom(rand).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
    Vec3i vec3i = tree.getSize(rotation);
    int x = rand.nextInt(16 - vec3i.getX());
    int z = rand.nextInt(16 - vec3i.getZ());
    int y = Math.max(Math.min(reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x, pos.getZ() + z) + rand.nextInt(20) + 40, 200), 100);
    BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos.offset(x, y, z), Mirror.NONE, rotation);
    tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
    BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
    placementsettings.clearProcessors().addProcessor(integrityprocessor);
    fruit.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
    return true;
}
Also used : Vec3i(net.minecraft.core.Vec3i) BlockRotProcessor(net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor) Random(java.util.Random) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) ChunkPos(net.minecraft.world.level.ChunkPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Aggregations

Rotation (net.minecraft.world.level.block.Rotation)22 BlockPos (net.minecraft.core.BlockPos)19 StructurePlaceSettings (net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)11 StructureManager (net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager)10 StructureTemplate (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)10 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)9 Random (java.util.Random)8 BlockState (net.minecraft.world.level.block.state.BlockState)4 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)4 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Mirror (net.minecraft.world.level.block.Mirror)3 MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)2 Vec3i (net.minecraft.core.Vec3i)2 ChunkPos (net.minecraft.world.level.ChunkPos)2 Biome (net.minecraft.world.level.biome.Biome)2 BlockRotProcessor (net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor)2 TemplateAccessor (com.telepathicgrunt.repurposedstructures.mixin.structures.TemplateAccessor)1 Calendar (java.util.Calendar)1 Level (net.minecraft.world.level.Level)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1