Search in sources :

Example 21 with Rotation

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

the class SchematicTransformation method toSettings.

public StructurePlaceSettings toSettings() {
    StructurePlaceSettings settings = new StructurePlaceSettings();
    int i = (int) rotation.getTarget();
    boolean mirrorlr = getScaleLR().getTarget() < 0;
    boolean mirrorfb = getScaleFB().getTarget() < 0;
    if (mirrorlr && mirrorfb) {
        mirrorlr = mirrorfb = false;
        i += 180;
    }
    i = i % 360;
    if (i < 0)
        i += 360;
    Rotation rotation = Rotation.NONE;
    switch(i) {
        case 90:
            rotation = Rotation.COUNTERCLOCKWISE_90;
            break;
        case 180:
            rotation = Rotation.CLOCKWISE_180;
            break;
        case 270:
            rotation = Rotation.CLOCKWISE_90;
            break;
        default:
    }
    settings.setRotation(rotation);
    if (mirrorfb)
        settings.setMirror(Mirror.FRONT_BACK);
    if (mirrorlr)
        settings.setMirror(Mirror.LEFT_RIGHT);
    return settings;
}
Also used : StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Rotation(net.minecraft.world.level.block.Rotation)

Example 22 with Rotation

use of net.minecraft.world.level.block.Rotation in project BCLib by paulevsGitch.

the class NBTStructureFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
    WorldGenLevel world = context.level();
    Random random = context.random();
    BlockPos center = context.origin();
    center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8);
    center = getGround(world, center);
    if (!canSpawn(world, center, random)) {
        return false;
    }
    int posY = center.getY() + 1;
    StructureTemplate structure = getStructure(world, center, random);
    Rotation rotation = getRotation(world, center, random);
    Mirror mirror = getMirror(world, center, random);
    BlockPos offset = StructureTemplate.transform(new BlockPos(structure.getSize()), mirror, rotation, BlockPos.ZERO);
    center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0);
    BoundingBox bounds = makeBox(center);
    StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
    addStructureData(placementData);
    center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
    structure.placeInWorld(world, center, center, placementData, random, 4);
    TerrainMerge merge = getTerrainMerge(world, center, random);
    int x1 = center.getX();
    int z1 = center.getZ();
    int x2 = x1 + offset.getX();
    int z2 = z1 + offset.getZ();
    if (merge != TerrainMerge.NONE) {
        MutableBlockPos mut = new MutableBlockPos();
        if (x2 < x1) {
            int a = x1;
            x1 = x2;
            x2 = a;
        }
        if (z2 < z1) {
            int a = z1;
            z1 = z2;
            z2 = a;
        }
        int surfMax = posY - 1;
        for (int x = x1; x <= x2; x++) {
            mut.setX(x);
            for (int z = z1; z <= z2; z++) {
                mut.setZ(z);
                mut.setY(surfMax);
                BlockState state = world.getBlockState(mut);
                if (!isTerrain(state) && state.isFaceSturdy(world, mut, Direction.DOWN)) {
                    for (int i = 0; i < 10; i++) {
                        mut.setY(mut.getY() - 1);
                        BlockState stateSt = world.getBlockState(mut);
                        if (!isTerrain(stateSt)) {
                            if (merge == TerrainMerge.SURFACE) {
                                boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
                                Biome b = world.getBiome(mut);
                                BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock);
                                BlocksHelper.setWithoutUpdate(world, mut, top);
                            } else {
                                BlocksHelper.setWithoutUpdate(world, mut, state);
                            }
                        } else {
                            if (isTerrain(state) && state.getMaterial().isSolidBlocking()) {
                                if (merge == TerrainMerge.SURFACE) {
                                    Biome b = world.getBiome(mut);
                                    BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock);
                                    BlocksHelper.setWithoutUpdate(world, mut, bottom);
                                } else {
                                    BlocksHelper.setWithoutUpdate(world, mut, state);
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Rotation(net.minecraft.world.level.block.Rotation) BlockState(net.minecraft.world.level.block.state.BlockState) Biome(net.minecraft.world.level.biome.Biome) Random(java.util.Random) BoundingBox(net.minecraft.world.level.levelgen.structure.BoundingBox) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) Mirror(net.minecraft.world.level.block.Mirror) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) 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