Search in sources :

Example 16 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.

the class SmallIslandFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    if (getYOnSurface(level, center.getX(), center.getZ()) > 0) {
        return false;
    }
    int size = MHelper.randRange(5, 9, random);
    MutableBlockPos pos = center.mutable();
    if (center.getY() == 0) {
        pos.setY(MHelper.randRange(64, 192, random));
    }
    makeCircle(level, pos, EdenBlocks.EDEN_GRASS_BLOCK.defaultBlockState(), size - 1, random);
    pos.setY(pos.getY() - 1);
    makeCircle(level, pos, EdenBlocks.EDEN_GRASS_BLOCK.defaultBlockState(), size, random);
    pos.setY(pos.getY() - 1);
    makeCircle(level, pos, Blocks.DIRT.defaultBlockState(), size - 1, random);
    pos.setY(pos.getY() - 1);
    makeCircle(level, pos, Blocks.STONE.defaultBlockState(), size - 2, random);
    if (size > 5) {
        pos.setY(pos.getY() - 1);
        makeCircle(level, pos, Blocks.STONE.defaultBlockState(), size - 4, random);
    }
    return true;
}
Also used : Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 17 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.

the class SmallIslandFeature method makeCircle.

private void makeCircle(WorldGenLevel level, BlockPos pos, BlockState state, int radius, Random random) {
    MutableBlockPos mut = pos.mutable();
    int r2 = radius * radius;
    for (int x = -radius; x <= radius; x++) {
        int x2 = x * x;
        mut.setX(pos.getX() + x);
        for (int z = -radius; z <= radius; z++) {
            int z2 = z * z;
            mut.setZ(pos.getZ() + z);
            BlockState worldState = level.getBlockState(mut);
            if (x2 + z2 <= r2 - random.nextInt(radius)) {
                if (worldState.isAir() || worldState.getMaterial().isReplaceable()) {
                    BlockState setState = state;
                    if (state.is(EdenBlocks.EDEN_GRASS_BLOCK) && !level.getBlockState(mut.above()).isAir()) {
                        setState = Blocks.DIRT.defaultBlockState();
                    }
                    BlocksHelper.setWithoutUpdate(level, mut, setState);
                }
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 18 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.

the class StoneLayer method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    int posX = center.getX() & 0xFFFFFFF0;
    int posZ = center.getZ() & 0xFFFFFFF0;
    ChunkAccess chunk = level.getChunk(center.getX() >> 4, center.getZ() >> 4);
    MutableBlockPos pos = new MutableBlockPos();
    for (int x = 0; x < 16; x++) {
        int wx = x | posX;
        pos.setX(x);
        for (int z = 0; z < 16; z++) {
            int wz = z | posZ;
            pos.setZ(z);
            float offset = (float) OFFSET_NOISE.eval(wx * 0.03, wz * 0.03);
            offset += (float) OFFSET_NOISE.eval(wx * 0.07, wz * 0.07) * 0.5F;
            int maxY = chunk.getHeight(Types.WORLD_SURFACE_WG, x, z);
            for (int y = 0; y < maxY; y++) {
                pos.setY(y);
                if (noise.eval(wx * 0.01, y * 0.1 + offset, wz * 0.01) > 0.45F && chunk.getBlockState(pos).is(Blocks.STONE)) {
                    chunk.setBlockState(pos, block.defaultBlockState(), false);
                }
            }
        }
    }
    return true;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 19 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.

the class AuritisTreeFeature method makeCircle.

private void makeCircle(WorldGenLevel level, BlockPos pos, BlockState leaves, int radius, int offset, boolean generateVines, Random random) {
    BlockState bottom = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
    BlockState middle = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
    BlockState top = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
    MutableBlockPos mut = pos.mutable();
    for (int x = -radius; x <= radius; x++) {
        int ax = Mth.abs(x);
        mut.setX(pos.getX() + x);
        for (int z = -radius; z <= radius; z++) {
            int az = Mth.abs(z);
            mut.setZ(pos.getZ() + z);
            if (ax != radius || az != radius || ax != az) {
                BlockState state = level.getBlockState(mut);
                if (state.isAir() || state.is(EdenBlocks.EDEN_MOSS)) {
                    int distance = ax + az + offset;
                    if (distance == 0) {
                        continue;
                    }
                    BlocksHelper.setWithoutUpdate(level, mut, leaves.setValue(BlockStateProperties.DISTANCE, distance));
                    if (generateVines && random.nextInt(16) == 0) {
                        int h = MHelper.randRange(3, 6, random);
                        for (int i = 1; i <= h; i++) {
                            mut.setY(pos.getY() - i);
                            if (!level.getBlockState(mut).isAir()) {
                                if (i == 1) {
                                    break;
                                }
                                mut.setY(mut.getY() + 1);
                                BlocksHelper.setWithoutUpdate(level, mut, bottom);
                                break;
                            }
                            BlocksHelper.setWithoutUpdate(level, mut, i == 1 ? top : i == h ? bottom : middle);
                        }
                        mut.setY(pos.getY());
                    }
                }
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 20 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project EdenRing by paulevsGitch.

the class BalloonMushroomTreeFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    Block below = level.getBlockState(center.below()).getBlock();
    if (!(below instanceof GrassBlock) && below != Blocks.DIRT) {
        return false;
    }
    MutableBlockPos pos = center.mutable();
    int h = MHelper.randRange(5, 9, random);
    for (int i = 1; i <= h; i++) {
        pos.setY(center.getY() + i);
        if (!level.getBlockState(pos).isAir()) {
            h = i - 1;
        }
    }
    if (h < 5) {
        h = random.nextInt(4);
        pos.setY(center.getY());
        BlockState tall = EdenBlocks.TALL_BALLOON_MUSHROOM.defaultBlockState();
        for (byte i = 0; i <= h; i++) {
            BlockState state = tall.setValue(EdenBlockProperties.TEXTURE_4, (int) i);
            if (i == h)
                state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
            if (level.getBlockState(pos.above()).isAir()) {
                BlocksHelper.setWithoutUpdate(level, pos, state);
                pos.setY(pos.getY() + 1);
            } else {
                state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
                BlocksHelper.setWithoutUpdate(level, pos, state);
                return true;
            }
        }
        return true;
    }
    BlockState stem = EdenBlocks.BALLOON_MUSHROOM_STEM.defaultBlockState();
    if (h > 5 && random.nextInt(6) == 0) {
        for (int i = 0; i < h; i++) {
            pos.setY(center.getY() + i);
            BlocksHelper.setWithoutUpdate(level, pos, stem);
        }
        BlockState head = EdenBlocks.BALLOON_MUSHROOM_BLOCK.defaultBlockState();
        BlockState fur = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.FUR);
        for (int x = -1; x < 2; x++) {
            pos.setX(center.getX() + x);
            for (int z = -1; z < 2; z++) {
                pos.setZ(center.getZ() + z);
                pos.setY(center.getY() + h - 1);
                if (level.getBlockState(pos).isAir()) {
                    BlocksHelper.setWithoutUpdate(level, pos, fur);
                }
                for (int y = 0; y < 3; y++) {
                    pos.setY(center.getY() + h + y);
                    if (level.getBlockState(pos).isAir()) {
                        BlocksHelper.setWithoutUpdate(level, pos, head);
                    }
                }
            }
        }
    } else {
        BlockState thin = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.THIN);
        BlockState thin_up = stem.setValue(EdenBlockProperties.BALLOON_MUSHROOM_STEM, BalloonMushroomStemState.THIN_TOP);
        int hMax = h - 1;
        for (int i = 0; i < h; i++) {
            pos.setY(center.getY() + i);
            BlocksHelper.setWithoutUpdate(level, pos, i == hMax ? thin_up : thin);
        }
        pos.setY(center.getY() + h);
        BlocksHelper.setWithoutUpdate(level, pos, EdenBlocks.BALLOON_MUSHROOM_BLOCK);
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) GrassBlock(net.minecraft.world.level.block.GrassBlock) Block(net.minecraft.world.level.block.Block) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) GrassBlock(net.minecraft.world.level.block.GrassBlock)

Aggregations

MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)60 BlockPos (net.minecraft.core.BlockPos)32 BlockState (net.minecraft.world.level.block.state.BlockState)31 Random (java.util.Random)16 WorldGenLevel (net.minecraft.world.level.WorldGenLevel)16 Direction (net.minecraft.core.Direction)11 ArrayList (java.util.ArrayList)8 Block (net.minecraft.world.level.block.Block)4 Level (net.minecraft.world.level.Level)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists (com.google.common.collect.Lists)2 Vector3f (com.mojang.math.Vector3f)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2 Nullable (javax.annotation.Nullable)2 AccessLevel (lombok.AccessLevel)2