Search in sources :

Example 6 with StructureWorldAccess

use of net.minecraft.world.StructureWorldAccess in project artifality by PinkGoosik.

the class CrystalFeature method generate.

@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
    boolean generated = false;
    var pack = CrystalClusterPacks.getRandomPack();
    for (int i = 0; i < 16; i++) {
        int x = context.getOrigin().getX() + context.getRandom().nextInt(6);
        int z = context.getOrigin().getZ() + context.getRandom().nextInt(6);
        int y = context.getRandom().nextInt(8) + 16;
        BlockPos pos = new BlockPos(x, y, z);
        StructureWorldAccess world = context.getWorld();
        if (world.isAir(pos)) {
            if (isStone(world.getBlockState(pos.down()))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState();
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.down(), pack.geode.getDefaultState());
                generated = true;
            } else if (isStone(world.getBlockState(pos.add(0, 0, -1)))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.SOUTH);
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.add(0, 0, -1), pack.geode.getDefaultState());
                generated = true;
            } else if (isStone(world.getBlockState(pos.add(0, 0, 1)))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.NORTH);
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.add(0, 0, 1), pack.geode.getDefaultState());
                generated = true;
            } else if (isStone(world.getBlockState(pos.add(-1, 0, 0)))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.EAST);
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.add(-1, 0, 0), pack.geode.getDefaultState());
                generated = true;
            } else if (isStone(world.getBlockState(pos.add(1, 0, 0)))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.WEST);
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.add(1, 0, 0), pack.geode.getDefaultState());
                generated = true;
            } else if (isStone(world.getBlockState(pos.up()))) {
                BlockState cluster = pack.getRandomCluster().getDefaultState().with(Properties.FACING, Direction.DOWN);
                setBlockState(world, pos, cluster);
                setBlockState(world, pos.up(), pack.geode.getDefaultState());
                generated = true;
            }
        }
    }
    return generated;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Example 7 with StructureWorldAccess

use of net.minecraft.world.StructureWorldAccess in project SpoornPink by spoorn.

the class AbstractSPTree method generate.

@Override
public boolean generate(FeatureContext<FC> context) {
    Set<BlockPos> changedTrunkBlocks = Sets.newHashSet();
    Set<BlockPos> changedLeafBlocks = Sets.newHashSet();
    StructureWorldAccess world = context.getWorld();
    boolean generated = generate(changedTrunkBlocks, changedLeafBlocks, world, context.getRandom(), context.getOrigin(), context.getConfig());
    if (!generated || changedTrunkBlocks.isEmpty() && changedLeafBlocks.isEmpty()) {
        return false;
    }
    /**
     * Copy vanilla's from {@link TreeFeature}.
     */
    return BlockBox.encompassPositions(Iterables.concat(changedTrunkBlocks, changedLeafBlocks)).map(box -> {
        VoxelSet voxelSet = placeLogsAndLeaves(world, box, changedTrunkBlocks);
        Structure.updateCorner(world, Block.NOTIFY_ALL, voxelSet, box.getMinX(), box.getMinY(), box.getMinZ());
        return true;
    }).orElse(false);
}
Also used : Iterables(com.google.common.collect.Iterables) Random(java.util.Random) Feature(net.minecraft.world.gen.feature.Feature) ModifiableWorld(net.minecraft.world.ModifiableWorld) ArrayList(java.util.ArrayList) Direction(net.minecraft.util.math.Direction) Properties(net.minecraft.state.property.Properties) Lists(com.google.common.collect.Lists) Vec3i(net.minecraft.util.math.Vec3i) Block(net.minecraft.block.Block) TreeFeature(net.minecraft.world.gen.feature.TreeFeature) BlockState(net.minecraft.block.BlockState) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) FeatureContext(net.minecraft.world.gen.feature.util.FeatureContext) VoxelSet(net.minecraft.util.shape.VoxelSet) Structure(net.minecraft.structure.Structure) WorldAccess(net.minecraft.world.WorldAccess) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Blocks(net.minecraft.block.Blocks) StructureWorldAccess(net.minecraft.world.StructureWorldAccess) SPTreeConfig(org.spoorn.spoornpink.world.gen.feature.config.SPTreeConfig) Codec(com.mojang.serialization.Codec) BlockBox(net.minecraft.util.math.BlockBox) TestableWorld(net.minecraft.world.TestableWorld) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) VoxelSet(net.minecraft.util.shape.VoxelSet) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Example 8 with StructureWorldAccess

use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.

the class CommonActivatorFeature method generate.

@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
    StructureWorldAccess world = context.getWorld();
    BlockPos pos = context.getOrigin();
    if (blockTagsInSphere(context.getOrigin(), 2, SculkTags.COMMON_ACTIVATORS, context.getWorld()).isEmpty() && world.getBlockState(context.getOrigin()).getBlock() == sculk.getBlock()) {
        if (context.getWorld().getBlockEntity(context.getOrigin()) == null) {
            ;
            BlockState activator = SculkTags.COMMON_ACTIVATORS.getRandom(new Random(context.getWorld().getSeed())).getDefaultState();
            if (SculkTags.GROUND_ACTIVATORS.contains(activator.getBlock())) {
                world.setBlockState(pos, activator, 0);
            } else {
                BlockState stateUp = world.getBlockState(pos.up());
                if (stateUp == water && activator.contains(waterLogged)) {
                    world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
                } else if (stateUp.getBlock() != waterBlock) {
                    if (stateUp == vein.with(waterLogged, true) && activator.contains(waterLogged)) {
                        world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
                    } else {
                        world.setBlockState(pos.up(), activator, 0);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Example 9 with StructureWorldAccess

use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.

the class LargeSculkPatchFeature method placePatch.

public void placePatch(FeatureContext<DefaultFeatureConfig> context, BlockPos pos, int r, double min, double max, double average) {
    StructureWorldAccess world = context.getWorld();
    // Place Sculk Around Catalyst
    int timesFailed = 0;
    int groupsFailed = 1;
    int loop = (int) (8 * Math.cos(((average) * Math.PI) / 24) + 24);
    for (int l = 0; l < loop; ) {
        double a = random() * 2 * PI;
        double rad = sqrt(2 + (groupsFailed - 1)) * sqrt(random());
        boolean succeed = placeSculk(pos.add((int) (rad * sin(a)), 0, (int) (rad * cos(a))), world);
        // Determine If Sculk Placement Was Successful And If Radius Should Be Increased
        if (!succeed) {
            ++timesFailed;
        } else {
            ++l;
            if (timesFailed > 0) {
                --timesFailed;
            }
        }
        if (timesFailed >= 10) {
            timesFailed = 0;
            groupsFailed = groupsFailed + 1;
        }
        if (sqrt(2 + (groupsFailed - 1)) > 10) {
            break;
        }
    }
    // Place Sculk
    for (BlockPos blockpos : blockTagsInSphere(pos, r, SculkTags.BLOCK_REPLACEABLE, world)) {
        double distance = pos.getSquaredDistance(blockpos, false);
        double maxA = max;
        double minA = min;
        double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
        if (r - 3 <= distance) {
            // Semi-Fade On Edges
            double equation = 0.15 * (Math.sin((r - distance * PI) / 6));
            maxA = maxA - equation;
            minA = minA + equation;
        }
        double dist = Math.max(r, distance * 1.8);
        if (isWall(world, blockpos)) {
            double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
            double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
            maxA = maxA - maxEq;
            minA = minA + minEq;
        }
        if (isCeiling(world, blockpos)) {
            double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
            double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
            maxA = maxA - maxEq;
            minA = minA + minEq;
        }
        if (sampled > minA && sampled < maxA) {
            placeSculkOptim(blockpos, world);
        }
    }
    // Place Veins
    for (BlockPos blockpos : solidInSphere(pos, r, world)) {
        double minA = min;
        double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
        double distance = pos.getSquaredDistance(blockpos, false);
        if (r - 3 <= distance) {
            // Semi-Fade On Edges
            double equation = 0.15 * (Math.sin((distance * PI) / 6));
            minA = minA + equation;
        }
        double dist = Math.max(r, distance * 1.8);
        if (isWall(world, blockpos)) {
            double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
            minA = minA + minEq;
        }
        if (isCeiling(world, blockpos)) {
            double minEq = (minA) * (Math.sin((dist * PI) / r * 2));
            minA = minA + minEq;
        }
        if (sampled < minA && sampled > minA - 0.16) {
            veins(blockpos, world);
        }
    }
    for (BlockPos blockpos : solidInSphere(pos, r, world)) {
        double distance = pos.getSquaredDistance(blockpos, false);
        double maxA = max;
        double sampled = sample.sample(blockpos.getX() * multiplier, blockpos.getY() * multiplier, blockpos.getZ() * multiplier);
        if (r - 3 <= distance) {
            // Semi-Fade On Edges
            double equation = 0.15 * (Math.sin((distance * PI) / 6));
            maxA = maxA - equation;
        }
        double dist = Math.max(r, distance * 1.8);
        if (isWall(world, blockpos)) {
            double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
            maxA = maxA - maxEq;
        }
        if (isCeiling(world, blockpos)) {
            double maxEq = (maxA) * (Math.sin((dist * PI) / r * 2));
            maxA = maxA - maxEq;
        }
        if (sampled > maxA && sampled < maxA + 0.16) {
            veins(blockpos, world);
        }
    }
    for (BlockPos blockpos : hollowedSphere(pos, r + 1, world)) {
        veins(blockpos, world);
    }
    // Place Activators
    for (BlockPos blockpos : blocksInSphere(pos, r, RegisterBlocks.SCULK, world)) {
        double sampled = sample.sample(blockpos.getX() * 1.5, blockpos.getY() * 1.5, blockpos.getZ() * 1.5);
        if (SculkTags.SCULK_VEIN_REPLACEABLE.contains(world.getBlockState(blockpos.up()).getBlock())) {
            Block activator = null;
            if (sampled < 0.55 && sampled > 0.41 && blockTagsInSphere(context.getOrigin(), 3, SculkTags.COMMON_ACTIVATORS, context.getWorld()).isEmpty()) {
                activator = SculkTags.COMMON_ACTIVATORS.getRandom(random);
            }
            if (sampled < 1 && sampled > 0.57 && blockTagsInSphere(context.getOrigin(), 6, SculkTags.RARE_ACTIVATORS, context.getWorld()).isEmpty()) {
                activator = SculkTags.RARE_ACTIVATORS.getRandom(random);
            }
            if (activator != null) {
                if (SculkTags.GROUND_ACTIVATORS.contains(activator)) {
                    world.setBlockState(blockpos.up(), activator.getDefaultState(), 0);
                } else {
                    if ((world.getBlockState(blockpos.up()).contains(waterLogged) && world.getBlockState(blockpos.up()).get(waterLogged)) || world.getBlockState(blockpos.up()) == water) {
                        world.setBlockState(blockpos.up(), activator.getDefaultState().with(waterLogged, true), 0);
                    } else {
                        world.setBlockState(blockpos.up(), activator.getDefaultState(), 0);
                    }
                }
            }
        }
    }
}
Also used : SculkVeinBlock(frozenblock.wild.mod.blocks.SculkVeinBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Example 10 with StructureWorldAccess

use of net.minecraft.world.StructureWorldAccess in project wildmod by Osmiooo.

the class RareActivatorFeature method generate.

@Override
public boolean generate(FeatureContext<DefaultFeatureConfig> context) {
    StructureWorldAccess world = context.getWorld();
    BlockPos pos = context.getOrigin();
    if (blockTagsInSphere(context.getOrigin(), 6, SculkTags.RARE_ACTIVATORS, context.getWorld()).isEmpty() && world.getBlockState(context.getOrigin()).getBlock() == sculk.getBlock()) {
        if (context.getWorld().getBlockEntity(context.getOrigin()) == null) {
            ;
            BlockState activator = SculkTags.RARE_ACTIVATORS.getRandom(new Random(context.getWorld().getSeed())).getDefaultState();
            if (SculkTags.GROUND_ACTIVATORS.contains(activator.getBlock())) {
                world.setBlockState(pos, activator, 0);
            } else {
                BlockState stateUp = world.getBlockState(pos.up());
                if (stateUp == water && activator.contains(waterLogged)) {
                    world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
                } else if (stateUp.getBlock() != waterBlock) {
                    if (stateUp == vein.with(waterLogged, true) && activator.contains(waterLogged)) {
                        world.setBlockState(pos.up(), activator.with(waterLogged, true), 0);
                    } else {
                        world.setBlockState(pos.up(), activator, 0);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) StructureWorldAccess(net.minecraft.world.StructureWorldAccess)

Aggregations

StructureWorldAccess (net.minecraft.world.StructureWorldAccess)13 BlockPos (net.minecraft.util.math.BlockPos)11 Random (java.util.Random)4 BlockState (net.minecraft.block.BlockState)4 Block (net.minecraft.block.Block)2 SettingsManager (carpet.settings.SettingsManager)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 Codec (com.mojang.serialization.Codec)1 RugSettings (de.rubixdev.rug.RugSettings)1 SculkVeinBlock (frozenblock.wild.mod.blocks.SculkVeinBlock)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 IntPoint2D (net.cr24.primeval.util.IntPoint2D)1 Blocks (net.minecraft.block.Blocks)1 CommandManager (net.minecraft.server.command.CommandManager)1 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)1