Search in sources :

Example 11 with Rotation

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

the class HolidayTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    BlockPos pos = context.origin();
    Random rand = context.random();
    WorldGenLevel reader = context.level();
    Calendar calendar = Calendar.getInstance();
    if ((AetherConfig.COMMON.generate_holiday_tree_seasonally.get() && (calendar.get(Calendar.MONTH) == Calendar.DECEMBER || calendar.get(Calendar.MONTH) == Calendar.JANUARY)) || AetherConfig.COMMON.generate_holiday_tree_always.get()) {
        Rotation rotation = Rotation.getRandom(rand);
        StructureManager templatemanager = reader.getLevel().getServer().getStructureManager();
        StructureTemplate tree = templatemanager.getOrCreate(TREE);
        StructureTemplate decor = templatemanager.getOrCreate(DECORATION);
        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 size = tree.getSize(rotation);
        int rx = Math.floorDiv(size.getX(), 2);
        int rz = Math.floorDiv(size.getZ(), 2);
        int x = rand.nextInt(16 - size.getX());
        int z = rand.nextInt(16 - size.getZ());
        int y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + x + rx, pos.getZ() + z + rz);
        if (y <= 48)
            return true;
        pos = pos.offset(x, y, z);
        for (int i = -rx * 2; i < rx * 2 + 1; i++) {
            for (int j = -rz * 2; j < rz * 2 + 1; j++) {
                if (i * i + j * j <= 3.5 * rx * rx) {
                    y = reader.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, pos.getX() + rx + i, pos.getZ() + rz + j);
                    if (y <= 48)
                        continue;
                    BlockPos pos1 = new BlockPos(pos.getX() + rx + i, y, pos.getZ() + rz + j);
                    if (rand.nextInt(6) == 0) {
                        this.setBlock(reader, pos1, AetherBlocks.PRESENT.get().defaultBlockState());
                    } else {
                        this.setBlock(reader, pos1, Blocks.SNOW.defaultBlockState());
                    }
                }
            }
        }
        BlockPos blockpos1 = tree.getZeroPositionWithTransform(pos, Mirror.NONE, rotation);
        tree.placeInWorld(reader, blockpos1, blockpos1, placementsettings, rand, 4);
        BlockRotProcessor integrityprocessor = new BlockRotProcessor(0.2F);
        placementsettings.clearProcessors().addProcessor(integrityprocessor);
        decor.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) Calendar(java.util.Calendar) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) Rotation(net.minecraft.world.level.block.Rotation) Random(java.util.Random) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) 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) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 12 with Rotation

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

the class RadiantLandFloatingIslands method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    WorldGenLevel world = ctx.level();
    if (AVAILABLE_TO_SPAWN == null) {
        initList(world);
    }
    BlockPos pos = ctx.origin();
    Random random = ctx.random();
    Rotation rot = Rotation.getRandom(random);
    StructureManager manager = world.getLevel().getStructureManager();
    StructureTemplate templ = manager.getOrCreate(List.of(ISLAND1, ISLAND2, ISLAND3, ISLAND4).get(random.nextInt(4)));
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(0, 1, 0), Mirror.NONE, rot);
    templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
        setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
    });
    return true;
}
Also used : Random(java.util.Random) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 13 with Rotation

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

the class CrystallizedOreVeinFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    WorldGenLevel world = ctx.level();
    if (AVAILABLE_TO_SPAWN == null) {
        initList(world);
    }
    BlockPos pos = ctx.origin().below(13);
    Random random = ctx.random();
    Rotation rot = Rotation.getRandom(random);
    StructureManager manager = world.getLevel().getStructureManager();
    StructureTemplate templ = manager.getOrCreate(VEIN);
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(0, 1, 0), Mirror.NONE, rot);
    templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
        setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
    });
    return true;
}
Also used : Random(java.util.Random) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 14 with Rotation

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

the class CrystalCaveOreCrystal method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    WorldGenLevel world = ctx.level();
    if (AVAILABLE_TO_SPAWN == null) {
        initList(world);
    }
    BlockPos pos = ctx.origin();
    Random random = ctx.random();
    BlockState stateAtPos = world.getBlockState(pos);
    if (!(stateAtPos.isAir())) {
        return false;
    }
    Optional<Column> column = Column.scan(world, pos, 30, (state) -> state.is(Blocks.AIR) || state.is(Blocks.CAVE_AIR), (state) -> state.is(Blocks.STONE));
    if (column.isPresent() && column.get().getFloor().isPresent()) {
        Rotation rot = Rotation.getRandom(random);
        StructureManager manager = world.getLevel().getStructureManager();
        StructureTemplate templ = manager.getOrCreate(ORE_CRYSTAL);
        StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
        BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(-templ.getSize().getX() / 2, 0, -templ.getSize().getZ() / 2), Mirror.NONE, rot);
        blockpos1 = new BlockPos(blockpos1.getX(), column.get().getFloor().getAsInt() - 2, blockpos1.getZ());
        templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
        templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
            setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
        });
    } else {
        return false;
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Column(net.minecraft.world.level.levelgen.Column) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 15 with Rotation

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

the class ChargingStationStructure 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());
    ChargingStationPieces.start(ctx.structureManager(), blockpos, rotation, p_197089_, ctx.random());
}
Also used : BlockPos(net.minecraft.core.BlockPos) Rotation(net.minecraft.world.level.block.Rotation)

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