Search in sources :

Example 6 with StructureManager

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

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

Example 8 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager in project Ecologics by samedifferent.

the class DesertRuinFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> pContext) {
    WorldGenLevel level = pContext.level();
    BlockPos origin = pContext.origin();
    Random random = pContext.random();
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(origin);
    for (mutable.move(Direction.UP); level.isEmptyBlock(mutable) && mutable.getY() > 2; ) {
        mutable.move(Direction.DOWN);
    }
    if (!level.getBlockState(mutable).isAir() && !level.isEmptyBlock(mutable.below()) && !level.isEmptyBlock(mutable.below(2))) {
        mutable.move(Direction.DOWN);
    } else {
        return false;
    }
    BlockPos.MutableBlockPos blockpos$Mutable = new BlockPos.MutableBlockPos();
    StructureManager templatemanager = level.getLevel().getServer().getStructureManager();
    ResourceLocation nbtRL = pieces[random.nextInt(pieces.length)];
    Optional<StructureTemplate> template = templatemanager.get(nbtRL);
    if (template.isEmpty()) {
        Ecologics.LOGGER.warn(nbtRL + " NTB does not exist!");
        return false;
    }
    for (int x = 0; x < template.get().getSize().getX(); x++) {
        for (int z = 0; z < template.get().getSize().getZ(); z++) {
            blockpos$Mutable.set(origin.below()).move(x, 0, z);
            if (!level.getBlockState(blockpos$Mutable).is(BlockTags.SAND)) {
                return false;
            }
        }
    }
    int radius = template.get().getSize().getX() / 2;
    for (int x = -radius; x <= radius; x++) {
        for (int z = -radius; z <= radius; z++) {
            if ((x * x) + (z * z) < radius * radius + 1) {
                blockpos$Mutable.set(origin).move(x, 0, z);
                if (!level.getFluidState(blockpos$Mutable).isEmpty()) {
                    return false;
                } else if (level.getBlockState(blockpos$Mutable.move(Direction.UP)).canOcclude() || !level.getBlockState(blockpos$Mutable.move(Direction.DOWN, 3)).canOcclude()) {
                    return false;
                } else if (!level.getBlockState(blockpos$Mutable).is(BlockTags.SAND)) {
                    return false;
                }
            }
        }
    }
    BlockPos halfLengths = new BlockPos(template.get().getSize().getX() / 2, 0, template.get().getSize().getZ() / 2);
    placementsettings.setRotation(Rotation.getRandom(random)).setRotationPivot(halfLengths).setIgnoreEntities(false);
    blockpos$Mutable.set(origin);
    BlockPos offset = new BlockPos(-template.get().getSize().getX() / 2, nbtRL.getPath().contains("pit") ? -2 : 0, -template.get().getSize().getZ() / 2);
    template.get().placeInWorld(level, blockpos$Mutable.offset(offset), blockpos$Mutable.offset(offset), placementsettings, random, Block.UPDATE_CLIENTS);
    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) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 9 with StructureManager

use of net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager 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 10 with StructureManager

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

the class RandomTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<RandomTreeConfig> context) {
    final WorldGenLevel worldIn = context.level();
    final BlockPos pos = context.origin();
    final Random random = context.random();
    final RandomTreeConfig 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 ResourceLocation structureId = config.structureNames().get(random.nextInt(config.structureNames().size()));
    final StructureTemplate structure = manager.getOrCreate(structureId);
    if (!isValidLocation(worldIn, mutablePos) || !isAreaClear(worldIn, mutablePos, config.radius(), 2)) {
        return false;
    }
    config.trunk().ifPresent(trunk -> {
        final int height = TreeHelpers.placeTrunk(worldIn, mutablePos, random, settings, trunk);
        mutablePos.move(0, height, 0);
    });
    TreeHelpers.placeTemplate(structure, settings, worldIn, mutablePos.subtract(TreeHelpers.transformCenter(structure.getSize(), settings)));
    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) 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)

Aggregations

StructureManager (net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager)18 BlockPos (net.minecraft.core.BlockPos)17 StructureTemplate (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)17 StructurePlaceSettings (net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings)14 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)13 Random (java.util.Random)11 Rotation (net.minecraft.world.level.block.Rotation)10 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ChunkPos (net.minecraft.world.level.ChunkPos)5 BlockState (net.minecraft.world.level.block.state.BlockState)4 BoundingBox (net.minecraft.world.level.levelgen.structure.BoundingBox)3 BlockRotProcessor (net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor)3 Vec3i (net.minecraft.core.Vec3i)2 TemplateAccessor (com.telepathicgrunt.repurposedstructures.mixin.structures.TemplateAccessor)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 LevelHeightAccessor (net.minecraft.world.level.LevelHeightAccessor)1 Biome (net.minecraft.world.level.biome.Biome)1 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)1 ChunkGenerator (net.minecraft.world.level.chunk.ChunkGenerator)1