Search in sources :

Example 11 with MutableBlockPos

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

the class SplineHelper method canGenerate.

public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
    int count = spline.size();
    Vector3f vec = spline.get(0);
    MutableBlockPos mut = new MutableBlockPos();
    float x1 = start.getX() + vec.x() * scale;
    float y1 = start.getY() + vec.y() * scale;
    float z1 = start.getZ() + vec.z() * scale;
    for (int i = 1; i < count; i++) {
        vec = spline.get(i);
        float x2 = start.getX() + vec.x() * scale;
        float y2 = start.getY() + vec.y() * scale;
        float z2 = start.getZ() + vec.z() * scale;
        for (float py = y1; py < y2; py += 3) {
            if (py - start.getY() < 10)
                continue;
            float lerp = (py - y1) / (y2 - y1);
            float x = Mth.lerp(lerp, x1, x2);
            float z = Mth.lerp(lerp, z1, z2);
            mut.set(x, py, z);
            if (!canReplace.apply(world.getBlockState(mut))) {
                return false;
            }
        }
        x1 = x2;
        y1 = y2;
        z1 = z2;
    }
    return true;
}
Also used : Vector3f(com.mojang.math.Vector3f) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 12 with MutableBlockPos

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

the class SplineHelper method canGenerate.

public static boolean canGenerate(List<Vector3f> spline, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
    int count = spline.size();
    Vector3f vec = spline.get(0);
    MutableBlockPos mut = new MutableBlockPos();
    float x1 = start.getX() + vec.x();
    float y1 = start.getY() + vec.y();
    float z1 = start.getZ() + vec.z();
    for (int i = 1; i < count; i++) {
        vec = spline.get(i);
        float x2 = start.getX() + vec.x();
        float y2 = start.getY() + vec.y();
        float z2 = start.getZ() + vec.z();
        for (float py = y1; py < y2; py += 3) {
            if (py - start.getY() < 10)
                continue;
            float lerp = (py - y1) / (y2 - y1);
            float x = Mth.lerp(lerp, x1, x2);
            float z = Mth.lerp(lerp, z1, z2);
            mut.set(x, py, z);
            if (!canReplace.apply(world.getBlockState(mut))) {
                return false;
            }
        }
        x1 = x2;
        y1 = y2;
        z1 = z2;
    }
    return true;
}
Also used : Vector3f(com.mojang.math.Vector3f) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 13 with MutableBlockPos

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

the class BlocksHelper method downRayRep.

public static int downRayRep(LevelAccessor world, BlockPos pos, int maxDist) {
    final MutableBlockPos POS = TL_POS.get();
    POS.set(pos);
    for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
        POS.setY(POS.getY() - 1);
    }
    return pos.getY() - POS.getY();
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 14 with MutableBlockPos

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

the class BlocksHelper method raycastSqr.

public static int raycastSqr(LevelAccessor world, BlockPos pos, int dx, int dy, int dz, int maxDist) {
    final MutableBlockPos POS = TL_POS.get();
    POS.set(pos);
    for (int j = 1; j < maxDist && (world.getBlockState(POS)).getMaterial().isReplaceable(); j++) {
        POS.move(dx, dy, dz);
    }
    return (int) pos.distSqr(POS);
}
Also used : MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

Example 15 with MutableBlockPos

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

the class BrainTreeBlock method randomTick.

@Override
@SuppressWarnings("deprecation")
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
    if (!world.isClientSide() && random.nextInt(1024) == 0 && BiomeAPI.getFromBiome(world.getBiome(pos)) == EdenBiomes.BRAINSTORM) {
        int px = pos.getX() + MHelper.randRange(-16, 16, random);
        int pz = pos.getZ() + MHelper.randRange(-16, 16, random);
        int py = world.getHeight(Types.WORLD_SURFACE, px, pz);
        LightningBolt bolt = EntityType.LIGHTNING_BOLT.create(world);
        bolt.setVisualOnly(true);
        bolt.teleportTo(px, py, pz);
        world.addFreshEntity(bolt);
    }
    if (state.getValue(ACTIVE)) {
        hitLighting(world, random, pos);
        world.setBlockAndUpdate(pos, state.setValue(ACTIVE, false));
    } else if (random.nextInt(4) == 0) {
        world.setBlockAndUpdate(pos, state.setValue(ACTIVE, true));
        Vec3i[] offsets = MHelper.getOffsets(random);
        MutableBlockPos p = new MutableBlockPos();
        for (Vec3i offset : offsets) {
            p.set(pos).move(offset);
            BlockState sideBlock = world.getBlockState(p);
            if (sideBlock.getBlock() instanceof BrainTreeBlock && sideBlock.getValue(ACTIVE)) {
                world.setBlockAndUpdate(p, sideBlock.setValue(ACTIVE, false));
                hitLighting(world, random, p);
            }
        }
    }
}
Also used : LightningBolt(net.minecraft.world.entity.LightningBolt) Vec3i(net.minecraft.core.Vec3i) BlockState(net.minecraft.world.level.block.state.BlockState) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos)

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