Search in sources :

Example 26 with MutableBlockPos

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

the class TallMushroomFeature method placeBlock.

@Override
protected void placeBlock(WorldGenLevel level, BlockPos pos, BlockState state) {
    byte height = (byte) level.getRandom().nextInt(4);
    MutableBlockPos p = pos.mutable();
    for (byte i = 0; i <= height; i++) {
        state = state.setValue(EdenBlockProperties.TEXTURE_4, (int) i);
        if (i == height)
            state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
        if (level.getBlockState(p.above()).isAir()) {
            BlocksHelper.setWithoutUpdate(level, p, state);
            p.setY(p.getY() + 1);
        } else {
            state = state.setValue(EdenBlockProperties.TEXTURE_4, 3);
            BlocksHelper.setWithoutUpdate(level, p, state);
            return;
        }
    }
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 27 with MutableBlockPos

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

the class VolvoxFeature method addSmallPlants.

private void addSmallPlants(WorldGenLevel level, BlockPos center, List<BlockPos> blocks, Random random) {
    MutableBlockPos pos = new MutableBlockPos();
    BlockState mold1 = EdenBlocks.SYMBIOTIC_MOLD.defaultBlockState();
    BlockState mold2 = EdenBlocks.SYMBIOTIC_MOLD_EMISSIVE.defaultBlockState();
    BlockState vine1 = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
    BlockState vine2 = EdenBlocks.EDEN_VINE.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
    blocks.forEach(p -> {
        if (random.nextInt(8) == 0) {
            for (Direction offset : BlocksHelper.DIRECTIONS) {
                BlockPos side = pos.set(p).move(offset);
                if (level.getBlockState(side).isAir()) {
                    BlockState state = SixSidePlant.class.cast(EdenBlocks.PARIGNUM).getAttachedState(level, side);
                    if (state != null) {
                        BlocksHelper.setWithoutUpdate(level, side, state);
                    }
                }
            }
        }
        pos.set(p).move(Direction.DOWN);
        BlockState state = level.getBlockState(pos);
        if (state.getFluidState().isEmpty() && state.getMaterial().isReplaceable()) {
            int plant = random.nextInt(8);
            if (plant == 0) {
                if (pos.getY() < center.getY()) {
                    return;
                }
                BlocksHelper.setWithoutUpdate(level, pos, mold2);
            } else if (plant < 4) {
                BlocksHelper.setWithoutUpdate(level, pos, mold1);
            } else if (plant < 6) {
                if (pos.getY() < center.getY() && random.nextInt(3) > 0) {
                    return;
                }
                byte length = (byte) MHelper.randRange(3, 6, random);
                for (byte i = 0; i <= length; i++) {
                    pos.move(Direction.DOWN);
                    state = level.getBlockState(pos);
                    pos.move(Direction.UP);
                    if (!state.getFluidState().isEmpty() || !state.getMaterial().isReplaceable()) {
                        BlocksHelper.setWithoutUpdate(level, pos, vine2);
                        break;
                    }
                    BlocksHelper.setWithoutUpdate(level, pos, i == length ? vine2 : vine1);
                    pos.move(Direction.DOWN);
                }
            }
        }
    });
}
Also used : SixSidePlant(paulevs.edenring.blocks.SixSidePlant) BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction)

Example 28 with MutableBlockPos

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

the class GraviliteCrystalFeature method makeCluster.

private void makeCluster(WorldGenLevel level, BlockPos center, int height, Random random, BlockState pillar, BlockState crystalTop, BlockState crystalBottom) {
    float radius = height * 0.2F;
    MutableBlockPos pos = new MutableBlockPos();
    int count = (int) MHelper.randRange(radius * 5, radius * 10, random);
    for (int i = 0; i < count; i++) {
        int px = Mth.floor(Mth.clamp((float) random.nextGaussian() * radius * 0.3F, -radius, radius) + 0.5F);
        int pz = Mth.floor(Mth.clamp((float) random.nextGaussian() * radius * 0.3F, -radius, radius) + 0.5F);
        pos.setX(px + center.getX());
        pos.setZ(pz + center.getZ());
        int h = Mth.floor(height - MHelper.length(px, pz) * 3 - random.nextInt(2));
        int minY = center.getY() - h;
        int maxY = center.getY() + h;
        pos.setY(center.getY());
        if (!level.getBlockState(pos).isAir()) {
            continue;
        }
        for (int py = minY; py <= maxY; py++) {
            pos.setY(py);
            if (level.getBlockState(pos).isAir()) {
                BlocksHelper.setWithoutUpdate(level, pos, pillar);
            }
        }
        pos.setY(minY - 1);
        if (level.getBlockState(pos).isAir() && level.getBlockState(pos.above()).equals(pillar)) {
            BlocksHelper.setWithoutUpdate(level, pos, crystalBottom);
        }
        pos.setY(maxY + 1);
        if (level.getBlockState(pos).isAir() && level.getBlockState(pos.below()).equals(pillar)) {
            BlocksHelper.setWithoutUpdate(level, pos, crystalTop);
        }
    }
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 29 with MutableBlockPos

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

the class SDFCave method place.

// private static SDF sdf = makeSDF();
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    ChunkAccess chunk = level.getChunk(center);
    int minX = center.getX() & 0xFFFFFFF0;
    int minZ = center.getZ() & 0xFFFFFFF0;
    int minY = level.getMinBuildHeight();
    int maxY = level.getMaxBuildHeight();
    Random random = new Random();
    final float[] buffer = new float[27];
    /*InterpolationCell cell = new InterpolationCell(pos -> {
			NOISE.getDistances(0, pos.getX() * 0.01, pos.getY() * 0.01, pos.getZ() * 0.01, buffer, random);
			float f1f2 = buffer[0] / buffer[2];
			return f1f2 > 0.85F ? 1.0F : 0.0F;
		}, 5, 65, 4, 4, new BlockPos(minX, minY, minZ));
		
		Function<BlockPos, Float> test = pos -> {
			NOISE.getDistances(0, pos.getX() * 0.01, pos.getY() * 0.01, pos.getZ() * 0.01, buffer, random);
			float f1f2 = buffer[0] / buffer[2];
			return f1f2 > 0.85F ? 1.0F : 0.0F;
		};*/
    BlockState diamond = Blocks.DIAMOND_BLOCK.defaultBlockState();
    MutableBlockPos pos = new MutableBlockPos();
    MutableBlockPos posWorld = new MutableBlockPos();
    for (int x = 0; x < 16; x++) {
        posWorld.setX(minX | x);
        pos.setX(x);
        for (int z = 0; z < 16; z++) {
            posWorld.setZ(minZ | z);
            pos.setZ(z);
            byte index = 0;
            float[] accumulation = new float[8];
            for (int y = minY; y < maxY; y++) {
                posWorld.setY(minY + y);
                pos.setY(y);
                if (isTerrain(chunk.getBlockState(pos))) {
                    float noise = getNoise(posWorld, buffer, random);
                    accumulation[index++] = noise;
                    if (index >= accumulation.length) {
                        index = 0;
                    }
                    float average = 0;
                    for (byte i = 0; i < accumulation.length; i++) {
                        noise = MHelper.max(noise, accumulation[i]);
                        average += accumulation[i];
                    }
                    noise = (noise + (average / accumulation.length)) * 0.5F;
                    if (noise > 0.9F) {
                        chunk.setBlockState(pos, CAVE_AIR, false);
                    }
                /*else if (noise > 0.85F) {
							chunk.setBlockState(pos, diamond, false);
						}*/
                }
            }
        }
    }
    return true;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 30 with MutableBlockPos

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

the class CeilScatterFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    WorldGenLevel level = featurePlaceContext.level();
    BlockPos center = featurePlaceContext.origin();
    Random random = featurePlaceContext.random();
    Biome biome = level.getBiome(center).value();
    MutableBlockPos pos = center.mutable();
    int maxY = getYOnSurfaceWG(level, center.getX(), center.getZ());
    for (int y = maxY - 1; y > 5; y--) {
        pos.setY(y);
        if (level.getBlockState(pos).isAir()) {
            pos.setY(y + 1);
            if (level.getBlockState(pos).isFaceSturdy(level, pos, Direction.DOWN)) {
                int count = MHelper.randRange(5, 20, random);
                for (int n = 0; n < count; n++) {
                    int px = center.getX() + Mth.floor(Mth.clamp(random.nextGaussian() * 2 + 0.5F, -8, 8));
                    int pz = center.getZ() + Mth.floor(Mth.clamp(random.nextGaussian() * 2 + 0.5F, -8, 8));
                    if (level.getBiome(pos.set(px, y, pz)).value() != biome)
                        continue;
                    for (int i = 5; i > -5; i--) {
                        pos.set(px, y + i, pz);
                        if (level.getBlockState(pos).isAir()) {
                            pos.setY(pos.getY() + 1);
                            if (level.getBlockState(pos).isFaceSturdy(level, pos, Direction.DOWN)) {
                                pos.setY(pos.getY() - 1);
                                generate(level, pos, random);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : Biome(net.minecraft.world.level.biome.Biome) 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)

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