use of net.minecraft.world.level.levelgen.Column in project SolarCraftRepository by FINDERFEED.
the class CeilingDripstoneLikeCrystals method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
BlockPos origin = context.origin();
WorldGenLevel world = context.level();
Optional<Column> optionalColumn = Column.scan(world, origin, 40, BlockBehaviour.BlockStateBase::isAir, state -> state.is(Tags.Blocks.STONE));
if (optionalColumn.isPresent()) {
Column column = optionalColumn.get();
if (column.getCeiling().isPresent() && column.getFloor().isPresent()) {
int floor = column.getFloor().getAsInt();
BlockPos pos = new BlockPos(origin.getX(), column.getCeiling().getAsInt(), origin.getZ());
int height = pos.getY() - floor;
if (height > 10) {
int crystalHeight = Math.round(height * 0.5f);
int maxRandomCrystalHeight = FinderfeedMathHelper.clamp(7, crystalHeight, 15);
crystalHeight = 6 + world.getRandom().nextInt(maxRandomCrystalHeight - 3);
int maxRad = crystalHeight / 2;
maxRad = FinderfeedMathHelper.clamp(1, maxRad, 4);
ArrayList<BlockPos> fillPositions = new ArrayList<>();
for (int x = -maxRad; x <= maxRad; x++) {
for (int z = -maxRad; z <= maxRad; z++) {
BlockPos test = pos.offset(x, 0, z);
if (world.getBlockState(test).isAir()) {
boolean end = true;
for (int i = 1; i <= 3; i++) {
BlockPos above = test.above(i);
if (world.getBlockState(test.above(i)).is(Tags.Blocks.STONE)) {
end = false;
break;
}
fillPositions.add(above);
}
if (end) {
fillPositions.clear();
return false;
}
}
}
}
for (BlockPos fillPos : fillPositions) {
double X = (fillPos.getX() - pos.getX());
double Z = (fillPos.getZ() - pos.getZ());
double r = Math.sqrt(X * X + Z * Z);
if (r <= maxRad) {
world.setBlock(fillPos, BlocksRegistry.RADIANT_CRYSTAL.get().defaultBlockState(), 3);
}
}
for (int x = -maxRad; x <= maxRad; x++) {
for (int y = 0; y <= crystalHeight; y++) {
for (int z = -maxRad; z <= maxRad; z++) {
BlockPos test = pos.offset(x, -y, z);
if (isValidPlace(world, pos, test, crystalHeight, maxRad)) {
world.setBlock(test, BlocksRegistry.RADIANT_CRYSTAL.get().defaultBlockState(), 3);
}
}
}
}
return true;
} else {
return false;
}
}
} else {
return false;
}
return false;
}
use of net.minecraft.world.level.levelgen.Column in project SolarCraftRepository by FINDERFEED.
the class CrystalCaveOreCrystal method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> ctx) {
WorldGenLevel world = ctx.level();
if (AVAILABLE_TO_SPAWN == null) {
initList(world);
}
BlockPos pos = ctx.origin();
Random random = ctx.random();
BlockState stateAtPos = world.getBlockState(pos);
if (!(stateAtPos.isAir())) {
return false;
}
Optional<Column> column = Column.scan(world, pos, 30, (state) -> state.is(Blocks.AIR) || state.is(Blocks.CAVE_AIR), (state) -> state.is(Blocks.STONE));
if (column.isPresent() && column.get().getFloor().isPresent()) {
Rotation rot = Rotation.getRandom(random);
StructureManager manager = world.getLevel().getStructureManager();
StructureTemplate templ = manager.getOrCreate(ORE_CRYSTAL);
StructurePlaceSettings set = new StructurePlaceSettings().addProcessor(BlockIgnoreProcessor.AIR).setRandom(random).setRotation(rot).setBoundingBox(BoundingBox.infinite());
BlockPos blockpos1 = templ.getZeroPositionWithTransform(pos.offset(-templ.getSize().getX() / 2, 0, -templ.getSize().getZ() / 2), Mirror.NONE, rot);
blockpos1 = new BlockPos(blockpos1.getX(), column.get().getFloor().getAsInt() - 2, blockpos1.getZ());
templ.placeInWorld(world, blockpos1, blockpos1, set, random, 4);
templ.filterBlocks(blockpos1, set, Blocks.SEA_LANTERN).forEach((info) -> {
setBlock(world, info.pos, AVAILABLE_TO_SPAWN.get(world.getRandom().nextInt(AVAILABLE_TO_SPAWN.size())).defaultBlockState());
});
} else {
return false;
}
return true;
}
use of net.minecraft.world.level.levelgen.Column in project FrostRealm by baguchan.
the class LargeIceFeature method place.
public boolean place(FeaturePlaceContext<LargeDripstoneConfiguration> p_159967_) {
WorldGenLevel worldgenlevel = p_159967_.level();
BlockPos blockpos = p_159967_.origin();
LargeDripstoneConfiguration largedripstoneconfiguration = p_159967_.config();
Random random = p_159967_.random();
if (!isEmptyOrWater(worldgenlevel, blockpos)) {
return false;
} else {
Optional<Column> optional = Column.scan(worldgenlevel, blockpos, largedripstoneconfiguration.floorToCeilingSearchRange, DripstoneUtils::isEmptyOrWater, LargeIceFeature::isIceBase);
if (optional.isPresent() && optional.get() instanceof Column.Range) {
Column.Range column$range = (Column.Range) optional.get();
if (column$range.height() < 4) {
return false;
} else {
int i = (int) ((float) column$range.height() * largedripstoneconfiguration.maxColumnRadiusToCaveHeightRatio);
int j = Mth.clamp(i, largedripstoneconfiguration.columnRadius.getMinValue(), largedripstoneconfiguration.columnRadius.getMaxValue());
int k = Mth.randomBetweenInclusive(random, largedripstoneconfiguration.columnRadius.getMinValue(), j);
LargeIceFeature.LargeDripstone LargeIceFeature$largedripstone = makeDripstone(blockpos.atY(column$range.ceiling() - 1), false, random, k, largedripstoneconfiguration.stalactiteBluntness, largedripstoneconfiguration.heightScale);
LargeIceFeature.LargeDripstone LargeIceFeature$largedripstone1 = makeDripstone(blockpos.atY(column$range.floor() + 1), true, random, k, largedripstoneconfiguration.stalagmiteBluntness, largedripstoneconfiguration.heightScale);
LargeIceFeature.WindOffsetter LargeIceFeature$windoffsetter;
if (LargeIceFeature$largedripstone.isSuitableForWind(largedripstoneconfiguration) && LargeIceFeature$largedripstone1.isSuitableForWind(largedripstoneconfiguration)) {
LargeIceFeature$windoffsetter = new LargeIceFeature.WindOffsetter(blockpos.getY(), random, largedripstoneconfiguration.windSpeed);
} else {
LargeIceFeature$windoffsetter = LargeIceFeature.WindOffsetter.noWind();
}
boolean flag = LargeIceFeature$largedripstone.moveBackUntilBaseIsInsideStoneAndShrinkRadiusIfNecessary(worldgenlevel, LargeIceFeature$windoffsetter);
boolean flag1 = LargeIceFeature$largedripstone1.moveBackUntilBaseIsInsideStoneAndShrinkRadiusIfNecessary(worldgenlevel, LargeIceFeature$windoffsetter);
if (flag) {
LargeIceFeature$largedripstone.placeBlocks(worldgenlevel, random, LargeIceFeature$windoffsetter);
}
if (flag1) {
LargeIceFeature$largedripstone1.placeBlocks(worldgenlevel, random, LargeIceFeature$windoffsetter);
}
return true;
}
} else {
return false;
}
}
}
Aggregations