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;
}
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;
}
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();
}
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);
}
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);
}
}
}
}
Aggregations