Search in sources :

Example 1 with BlockRotProcessor

use of net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor in project TerraFirmaCraft by TerraFirmaCraft.

the class OverlayTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<OverlayTreeConfig> context) {
    final WorldGenLevel worldIn = context.level();
    final BlockPos pos = context.origin();
    final Random random = context.random();
    final OverlayTreeConfig config = context.config();
    final ChunkPos chunkPos = new ChunkPos(pos);
    final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos().set(pos);
    final StructureManager manager = TreeHelpers.getStructureManager(worldIn);
    final StructurePlaceSettings settings = TreeHelpers.getPlacementSettings(worldIn, chunkPos, random);
    final StructureTemplate structureBase = manager.getOrCreate(config.base());
    final StructureTemplate structureOverlay = manager.getOrCreate(config.overlay());
    if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 3)) {
        return false;
    }
    config.trunk().ifPresent(trunk -> {
        final int height = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, trunk);
        mutablePos.move(0, height, 0);
    });
    TreeHelpers.placeTemplate(structureBase, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structureBase.getSize(), settings)));
    settings.addProcessor(new BlockRotProcessor(config.overlayIntegrity()));
    TreeHelpers.placeTemplate(structureOverlay, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structureOverlay.getSize(), settings)));
    return true;
}
Also used : BlockRotProcessor(net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor) Random(java.util.Random) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) ChunkPos(net.minecraft.world.level.ChunkPos) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 2 with BlockRotProcessor

use of net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor in project Mohist by MohistMC.

the class CraftStructure method place.

@Override
public void place(RegionAccessor regionAccessor, BlockVector location, boolean includeEntities, StructureRotation structureRotation, Mirror mirror, int palette, float integrity, Random random) {
    Validate.notNull(regionAccessor, "regionAccessor can not be null");
    location.checkFinite();
    if (integrity < 0F || integrity > 1F) {
        throw new IllegalArgumentException("Integrity must be between 0 and 1 inclusive. Was \"" + integrity + "\"");
    }
    StructurePlaceSettings definedstructureinfo = new StructurePlaceSettings().setMirror(net.minecraft.world.level.block.Mirror.valueOf(mirror.name())).setRotation(net.minecraft.world.level.block.Rotation.valueOf(structureRotation.name())).setIgnoreEntities(!includeEntities).addProcessor(new BlockRotProcessor(integrity)).setRandom(random);
    definedstructureinfo.palette = palette;
    BlockPos blockPosition = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    structure.placeInWorld(((CraftRegionAccessor) regionAccessor).getHandle(), blockPosition, blockPosition, definedstructureinfo, random, 2);
}
Also used : BlockRotProcessor(net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) BlockPos(net.minecraft.core.BlockPos)

Example 3 with BlockRotProcessor

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

Example 4 with BlockRotProcessor

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

Aggregations

BlockPos (net.minecraft.core.BlockPos)4 BlockRotProcessor (net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor)4 StructurePlaceSettings (net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)4 Random (java.util.Random)3 ChunkPos (net.minecraft.world.level.ChunkPos)3 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)3 StructureManager (net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager)3 StructureTemplate (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)3 Vec3i (net.minecraft.core.Vec3i)2 Rotation (net.minecraft.world.level.block.Rotation)2 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)2 Calendar (java.util.Calendar)1