Search in sources :

Example 16 with StructureManager

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

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

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

the class MinecartFeature method place.

@Override
public boolean place(FeaturePlaceContext<MinecartConfig> context) {
    // Check if below block is solid
    BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos().set(context.origin());
    if (!context.level().getBlockState(mutable.below()).canOcclude()) {
        return false;
    }
    // Check if spot allows for cart (liquid or non-liquid spot)
    BlockState worldBlock = context.level().getBlockState(mutable);
    if (context.config().waterBased ? !worldBlock.getFluidState().is(FluidTags.WATER) : !worldBlock.getFluidState().isEmpty()) {
        return false;
    }
    BlockPos.MutableBlockPos blockpos$Mutable = new BlockPos.MutableBlockPos();
    StructureManager templatemanager = context.level().getLevel().getServer().getStructureManager();
    Optional<StructureTemplate> template = templatemanager.get(context.config().nbtPath);
    if (template.isEmpty()) {
        RepurposedStructures.LOGGER.warn(context.config().nbtPath.toString() + " NTB does not exist!");
        return false;
    }
    BlockPos halfLengths = new BlockPos(template.get().getSize().getX() / 2, 0, template.get().getSize().getZ() / 2);
    structurePlaceSettings.setRotation(Rotation.getRandom(context.random())).setRotationPivot(halfLengths).setIgnoreEntities(false);
    blockpos$Mutable.set(context.origin());
    BlockPos offset = new BlockPos(-template.get().getSize().getX() / 2, 0, -template.get().getSize().getZ() / 2);
    template.get().placeInWorld(context.level(), blockpos$Mutable.offset(offset), blockpos$Mutable.offset(offset), structurePlaceSettings, context.random(), Block.UPDATE_CLIENTS);
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) StructureManager(net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager) BlockPos(net.minecraft.core.BlockPos) StructureTemplate(net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate)

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