Search in sources :

Example 31 with MutableBlockPos

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

the class DepthScatterFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    Random random = featurePlaceContext.random();
    BlockPos center = featurePlaceContext.origin();
    WorldGenLevel level = featurePlaceContext.level();
    int posX = center.getX() & 0xFFFFFFF0;
    int posZ = center.getZ() & 0xFFFFFFF0;
    MutableBlockPos pos = new MutableBlockPos();
    int iterations = MHelper.randRange(minCount, maxCount, random);
    for (int n = 0; n < iterations; n++) {
        int wx = posX | random.nextInt(16);
        int wz = posZ | random.nextInt(16);
        int wy = random.nextInt(256);
        int radius = MHelper.randRange(minRadius, maxRadius, random);
        int count = (int) (radius * radius * MHelper.randRange(0.7F, 2F, random));
        float multiplier = radius / 3.0F;
        for (int i = 0; i < count; i++) {
            int px = wx + Mth.floor(Mth.clamp(random.nextGaussian() * multiplier, -radius, radius));
            int py = wy + Mth.floor(Mth.clamp(random.nextGaussian() * multiplier, -radius, radius));
            int pz = wz + Mth.floor(Mth.clamp(random.nextGaussian() * multiplier, -radius, radius));
            pos.set(px, py, pz);
            BlockState state = level.getBlockState(pos);
            for (Block b : scatterIn) {
                if (state.is(b)) {
                    BlocksHelper.setWithoutUpdate(level, pos, block);
                    break;
                }
            }
        }
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 32 with MutableBlockPos

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

the class FloorScatterFeature method place.

@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
    Random random = featurePlaceContext.random();
    BlockPos center = featurePlaceContext.origin();
    WorldGenLevel level = featurePlaceContext.level();
    MutableBlockPos pos = new MutableBlockPos();
    int count = MHelper.randRange(100, 200, random);
    for (int i = 0; i < count; i++) {
        int px = center.getX() + Mth.floor(Mth.clamp(random.nextGaussian() * 2, -8, 8));
        int py = center.getY() + Mth.floor(Mth.clamp(random.nextGaussian() * 2, -8, 8));
        int pz = center.getZ() + Mth.floor(Mth.clamp(random.nextGaussian() * 2, -8, 8));
        pos.set(px, py, pz);
        for (Block floor : floors) {
            if (level.getBlockState(pos).is(floor) && (!checkAir || level.getBlockState(pos.above()).isAir())) {
                BlocksHelper.setWithoutUpdate(level, pos, block);
                break;
            }
        }
    }
    return true;
}
Also used : Random(java.util.Random) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 33 with MutableBlockPos

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

the class GravityController method getGraviliteMultiplier.

public static double getGraviliteMultiplier(Entity entity) {
    MutableBlockPos pos = entity.blockPosition().mutable();
    int dist = 8;
    for (int i = 0; i < 8; i++) {
        if (entity.level.getBlockState(pos).is(EdenBlocks.GRAVILITE_BLOCK)) {
            dist = i;
            break;
        }
        pos.setY(pos.getY() - 1);
    }
    if (dist == 8) {
        return 1.0;
    }
    float delta = Mth.clamp((dist + (float) (entity.getY() - (int) entity.getY())) / 8F, 0, 1);
    return Mth.lerp(delta, 0.1, 1.0);
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 34 with MutableBlockPos

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

the class GravityController method getCompressorMultiplier.

public static double getCompressorMultiplier(Entity entity) {
    MutableBlockPos pos = entity.blockPosition().mutable();
    int power = 0;
    int dist = 64;
    for (int i = 0; i < 64; i++) {
        BlockState state = entity.level.getBlockState(pos);
        if (state.is(EdenBlocks.GRAVITY_COMPRESSOR)) {
            power = state.getValue(BlockStateProperties.POWER);
            dist = i;
            break;
        }
        pos.setY(pos.getY() - 1);
    }
    if (dist == 64) {
        return 1.0;
    }
    float delta = Mth.clamp((dist + (float) (entity.getY() - (int) entity.getY())) / 64F, 0, 1);
    delta = (1 - delta) * (power / 15F);
    return power > 0 ? Mth.lerp(delta, 1.0, -1.0) : Mth.lerp(delta, 1.0, 0.1);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 35 with MutableBlockPos

use of net.minecraft.core.BlockPos.MutableBlockPos in project Applied-Energistics-2 by AppliedEnergistics.

the class GrowingCrystalEntity method getAcceleratorCount.

private int getAcceleratorCount(BlockPos pos) {
    int count = 0;
    MutableBlockPos testPos = new MutableBlockPos();
    for (Direction direction : Direction.values()) {
        if (this.isPoweredAccelerator(testPos.setWithOffset(pos, direction))) {
            count++;
        }
    }
    return count;
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) Direction(net.minecraft.core.Direction)

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