Search in sources :

Example 1 with Rotation

use of net.minecraft.world.level.block.Rotation in project BYG by AOCAWOL.

the class BYGAbstractTreeFeature method place.

public boolean place(WorldGenLevel worldIn, ChunkGenerator generator, Random rand, BlockPos pos, TFC config) {
    if (worldIn.getLevel().dimension() == Level.OVERWORLD && !BYG.ENABLE_OVERWORLD_TREES) {
        return false;
    }
    Rotation rotation = Rotation.values()[rand.nextInt(Rotation.values().length)];
    Mirror mirror = Mirror.values()[rand.nextInt(Mirror.values().length)];
    config.setRotationAndMirror(rotation, mirror);
    return placeTree(worldIn, rand, pos, config);
}
Also used : Rotation(net.minecraft.world.level.block.Rotation) Mirror(net.minecraft.world.level.block.Mirror)

Example 2 with Rotation

use of net.minecraft.world.level.block.Rotation in project RepurposedStructures by TelepathicGrunt.

the class NbtDungeon method place.

@Override
public boolean place(FeaturePlaceContext<NbtDungeonConfig> context) {
    if (GeneralUtils.isBlacklistedForWorld(context.level(), context.config().cfID))
        return false;
    BlockPos position = context.origin().above(-1);
    ResourceLocation nbtRL = GeneralUtils.getRandomEntry(context.config().nbtResourcelocationsAndWeights, context.random());
    StructureManager structureManager = context.level().getLevel().getStructureManager();
    Optional<StructureTemplate> template = structureManager.get(nbtRL);
    if (template.isEmpty()) {
        RepurposedStructures.LOGGER.error("Identifier to the specified nbt file was not found! : {}", nbtRL);
        return false;
    }
    Rotation rotation = Rotation.getRandom(context.random());
    BlockPos size = new BlockPos(template.get().getSize());
    // For proper offsetting the dungeon so it rotate properly around position parameter.
    BlockPos halfLengths = new BlockPos(size.getX() / 2, size.getY() / 2, size.getZ() / 2);
    // Rotated blockpos for the nbt's sizes to be used later.
    BlockPos fullLengths = new BlockPos(Math.abs(size.rotate(rotation).getX()), Math.abs(size.rotate(rotation).getY()), Math.abs(size.rotate(rotation).getZ()));
    // For post processing spawners and chests for rotated dungeon.
    BlockPos halfLengthsRotated = new BlockPos(fullLengths.getX() / 2, fullLengths.getY() / 2, fullLengths.getZ() / 2);
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(position);
    ChunkAccess cachedChunk = context.level().getChunk(mutable);
    int xMin = -halfLengthsRotated.getX();
    int xMax = halfLengthsRotated.getX();
    int zMin = -halfLengthsRotated.getZ();
    int zMax = halfLengthsRotated.getZ();
    int wallOpenings = 0;
    int ceilingOpenings = 0;
    int ceiling = size.getY();
    for (int x = xMin; x <= xMax; x++) {
        for (int z = zMin; z <= zMax; z++) {
            for (int y = 0; y <= ceiling; y++) {
                mutable.set(position).move(x, y, z);
                if (mutable.getX() >> 4 != cachedChunk.getPos().x || mutable.getZ() >> 4 != cachedChunk.getPos().z)
                    cachedChunk = context.level().getChunk(mutable);
                BlockState state = cachedChunk.getBlockState(mutable);
                // Dungeons cannot touch fluids if set to air mode and reverse if opposite
                if (context.config().airRequirementIsNowWater ? state.isAir() || state.getFluidState().is(FluidTags.LAVA) : !state.getFluidState().isEmpty()) {
                    return false;
                } else // Floor must be complete
                if (!GeneralUtils.isFullCube(context.level(), mutable, state)) {
                    if (y == 0 && !state.getMaterial().isSolid()) {
                        return false;
                    } else if (state.is(BlockTags.LEAVES)) {
                        // ignore leaves
                        continue;
                    } else if (y == ceiling) {
                        ceilingOpenings++;
                    }
                }
                // Check only along wall bottoms for openings
                if ((x == xMin || x == xMax || z == zMin || z == zMax) && y == 1 && isValidNonSolidBlock(context.config(), state)) {
                    BlockState aboveState = cachedChunk.getBlockState(mutable);
                    if (context.config().airRequirementIsNowWater ? !aboveState.getFluidState().isEmpty() : aboveState.isAir()) {
                        wallOpenings++;
                    }
                }
                // Too much open space. Quit
                if (wallOpenings > context.config().maxAirSpace || ceilingOpenings > context.config().maxAirSpace) {
                    return false;
                }
            }
        }
    }
    // Check if we meet minimum for open space.
    if (wallOpenings >= context.config().minAirSpace) {
        // offset the dungeon such as ocean dungeons down 1
        position = position.above(context.config().structureYOffset);
        // RepurposedStructures.LOGGER.log(Level.INFO, nbtRL + " at X: "+position.getX() +", "+position.getY()+", "+position.getZ());
        StructurePlaceSettings placementsettings = (new StructurePlaceSettings()).setRotation(rotation).setRotationPivot(halfLengths).setIgnoreEntities(false);
        Optional<StructureProcessorList> processor = context.level().getLevel().getServer().registryAccess().registryOrThrow(Registry.PROCESSOR_LIST_REGISTRY).getOptional(context.config().processor);
        // add all processors
        processor.orElse(ProcessorLists.EMPTY.value()).list().forEach(placementsettings::addProcessor);
        BlockPos finalPos = mutable.set(position).move(-halfLengths.getX(), 0, -halfLengths.getZ());
        template.get().placeInWorld(context.level(), finalPos, finalPos, placementsettings, context.random(), Block.UPDATE_CLIENTS);
        // Post-processors
        // For all processors that are sensitive to neighboring blocks such as vines.
        // Post processors will place the blocks themselves so we will not do anything with the return of Structure.process
        placementsettings.clearProcessors();
        Optional<StructureProcessorList> postProcessor = context.level().getLevel().getServer().registryAccess().registryOrThrow(Registry.PROCESSOR_LIST_REGISTRY).getOptional(context.config().postProcessor);
        // add all post processors
        postProcessor.orElse(ProcessorLists.EMPTY.value()).list().forEach(placementsettings::addProcessor);
        List<StructureTemplate.StructureBlockInfo> list = placementsettings.getRandomPalette(((TemplateAccessor) template.get()).repurposedstructures_getPalettes(), mutable).blocks();
        StructureTemplate.processBlockInfos(context.level(), mutable, mutable, placementsettings, list, template.get());
        spawnLootBlocks(context.level(), context.random(), position, context.config(), fullLengths, halfLengthsRotated, mutable);
        return true;
    }
    return false;
}
Also used : StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) Rotation(net.minecraft.world.level.block.Rotation) ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(net.minecraft.world.level.block.state.BlockState) ResourceLocation(net.minecraft.resources.ResourceLocation) StructureProcessorList(net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate) StructurePlaceSettings(net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings) TemplateAccessor(com.telepathicgrunt.repurposedstructures.mixin.structures.TemplateAccessor)

Example 3 with Rotation

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

the class MoltenForestAmbience method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    BlockPos pos = ctx.origin();
    WorldGenLevel world = ctx.level();
    Random random = ctx.random();
    Rotation rot = Rotation.getRandom(random);
    StructureManager manager = world.getLevel().getStructureManager();
    List<ResourceLocation> list = new ArrayList<>();
    list.add(TREE);
    list.add(TREE2);
    StructureTemplate templ = manager.getOrCreate(list.get(random.nextInt(2)));
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos pos1 = findFlatChunkPosition(world, pos, 4, Blocks.GRASS_BLOCK);
    if (!pos1.equals(Helpers.NULL_POS)) {
        BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos1.offset(0, 1, 0), Mirror.NONE, rot);
        templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    }
    return true;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) 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 4 with Rotation

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

the class EnergyPylonFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    WorldGenLevel world = ctx.level();
    Random random = ctx.random();
    BlockPos pos = ctx.origin();
    Rotation rot = Rotation.NONE;
    StructureManager manager = world.getLevel().getStructureManager();
    StructureTemplate templ = manager.getOrCreate(LOCATIONS[world.getRandom().nextInt(LOCATIONS.length)]);
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos pos1 = findFlatChunkPosition(world, pos, 5);
    if (!pos1.equals(Helpers.NULL_POS)) {
        BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos1.offset(0, 1, 0), Mirror.NONE, rot);
        templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    }
    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 5 with Rotation

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

the class MoltenForestRuins method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
    BlockPos pos = ctx.origin();
    WorldGenLevel world = ctx.level();
    Random random = ctx.random();
    Rotation rot = Rotation.getRandom(random);
    StructureManager manager = world.getLevel().getStructureManager();
    ResourceLocation[] LOC = { RUINS1, RUINS2, RUINS3 };
    StructureTemplate templ = manager.getOrCreate(LOC[random.nextInt(3)]);
    StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
    BlockPos pos1 = findFlatChunkPosition(world, pos, 4, Blocks.GRASS_BLOCK);
    if (!pos1.equals(Helpers.NULL_POS)) {
        BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos1.offset(0, 1, 0), Mirror.NONE, rot);
        templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
    }
    return true;
}
Also used : Random(java.util.Random) ResourceLocation(net.minecraft.resources.ResourceLocation) 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)

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