use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class CoffeePlantFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
final BlockPos genPos = new BlockPos((pos.getX() + random.nextInt(8)) - random.nextInt(8), pos.getY(), (pos.getZ() + random.nextInt(8)) - random.nextInt(8));
// Find a suitable place to generate
if (!world.isEmptyBlock(genPos) || world.getBlockState(genPos.below()).getBlock() != GRASS_BLOCK.getBlock() || world.isEmptyBlock(genPos.below(2))) {
return false;
}
Direction viableDirection = null;
// Scan for potential water spot
for (final Direction dir : Direction.Plane.HORIZONTAL) {
final int neighborx = genPos.getX() + dir.getStepX();
final int neighborz = genPos.getZ() + dir.getStepZ();
if (!world.isEmptyBlock(new BlockPos(neighborx, pos.getY() - 1, neighborz))) {
viableDirection = dir;
break;
}
}
if (viableDirection == null) {
return false;
}
final BlockPos waterPos = new BlockPos(genPos.getX() + viableDirection.getStepX(), pos.getY() - 1, genPos.getZ() + viableDirection.getStepZ());
world.setBlock(waterPos, WATER, Constants.BlockFlags.DEFAULT);
world.setBlock(genPos.below(), FARMLAND, Constants.BlockFlags.DEFAULT);
for (final Direction dir : Direction.Plane.HORIZONTAL) {
world.setBlock(waterPos.relative(dir), GRASS_BLOCK, Constants.BlockFlags.DEFAULT);
}
for (int i = 0; i < 3; ++i) {
final BlockPos upPos = genPos.above(i);
if (world.isEmptyBlock(upPos)) {
world.setBlock(upPos, COFE, Constants.BlockFlags.DEFAULT);
} else {
break;
}
}
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class UndergroundSeaPickleFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
BlockState surface = world.getBlockState(pos.below());
if (!surface.is(Blocks.STONE) && !surface.is(Blocks.DIRT)) {
return false;
}
if (world.getBlockState(pos).is(Blocks.WATER) && world.getBlockState(pos.above()).is(Blocks.WATER)) {
int count = random.nextInt(random.nextInt(4) + 1) + 1;
if (surface.is(Blocks.DIRT)) {
count = Math.min(count + random.nextInt(2), 4);
}
BlockState pickle = Blocks.SEA_PICKLE.defaultBlockState().setValue(SeaPickleBlock.PICKLES, count);
world.setBlock(pos, pickle, Block.UPDATE_CLIENTS);
return true;
}
return false;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class UndergrowthFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
int size = 2;
if (rand.nextInt(LARGE_BUSH_CHANCE) == 0) {
size = 3;
}
if (!isValidPosition(world, pos)) {
return false;
}
if (goesBeyondWorldSize(world, pos.getY(), size)) {
return false;
}
if (!TropicraftFeatureUtil.isSoil(world, pos.below())) {
return false;
}
world.setBlock(pos.below(), Blocks.DIRT.defaultBlockState(), 3);
setBlock(world, pos, TropicraftBlocks.MAHOGANY_LOG.get().defaultBlockState());
int count = 0;
for (int round = 0; round < 64; ++round) {
BlockPos posTemp = pos.offset(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));
if (isValidPosition(world, posTemp) && posTemp.getY() < 255) {
for (int y = posTemp.getY(); y < posTemp.getY() + size; y++) {
int bushWidth = size - (y - posTemp.getY());
for (int x = posTemp.getX() - bushWidth; x < posTemp.getX() + bushWidth; x++) {
int xVariance = x - posTemp.getX();
for (int z = posTemp.getZ() - bushWidth; z < posTemp.getZ() + bushWidth; z++) {
int zVariance = z - posTemp.getZ();
final BlockPos newPos = new BlockPos(x, y, z);
if ((Math.abs(xVariance) != bushWidth || Math.abs(zVariance) != bushWidth || rand.nextInt(2) != 0) && isValidPosition(world, newPos)) {
setBlock(world, newPos, TropicraftBlocks.KAPOK_LEAVES.get().defaultBlockState());
}
}
}
}
++count;
}
}
return count > 0;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class LargePalmTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
NoneFeatureConfiguration config = context.config();
pos = pos.immutable();
int height = random.nextInt(7) + 7;
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
if (!getSapling().canSurvive(getSapling().defaultBlockState(), world, pos)) {
return false;
}
if (world.getBlockState(pos.below()).getBlock() == Blocks.GRASS_BLOCK) {
world.setBlock(pos.below(), Blocks.DIRT.defaultBlockState(), 3);
}
// Place trunk
for (int y = 0; y <= height; y++) {
placeLog(world, pos.getX(), pos.getY() + y, pos.getZ());
}
final int i = pos.getX(), j = pos.getY(), k = pos.getZ();
// Wheeee, auto-generated code!
placeLeaf(world, i + 0, j + height + 1, k + -7);
placeLeaf(world, i + -1, j + height + 1, k + -6);
placeLeaf(world, i + 1, j + height + 1, k + -6);
placeLeaf(world, i + -5, j + height + 1, k + -5);
placeLeaf(world, i + 5, j + height + 1, k + -5);
placeLeaf(world, i + -6, j + height + 1, k + -1);
placeLog(world, i + 0, j + height + 1, k + -1);
placeLeaf(world, i + 6, j + height + 1, k + -1);
placeLeaf(world, i + -7, j + height + 1, k + 0);
placeLog(world, i + -1, j + height + 1, k + 0);
placeLog(world, i + 0, j + height + 1, k + 0);
placeLog(world, i + 1, j + height + 1, k + 0);
placeLeaf(world, i + 7, j + height + 1, k + 0);
placeLeaf(world, i + -6, j + height + 1, k + 1);
placeLog(world, i + 0, j + height + 1, k + 1);
placeLeaf(world, i + 6, j + height + 1, k + 1);
placeLeaf(world, i + -5, j + height + 1, k + 5);
placeLeaf(world, i + 5, j + height + 1, k + 5);
placeLeaf(world, i + -1, j + height + 1, k + 6);
placeLeaf(world, i + 1, j + height + 1, k + 6);
placeLeaf(world, i + 0, j + height + 1, k + 7);
placeLeaf(world, i + 0, j + height + 2, k + -6);
placeLeaf(world, i + -4, j + height + 2, k + -5);
placeLeaf(world, i + -1, j + height + 2, k + -5);
placeLeaf(world, i + 1, j + height + 2, k + -5);
placeLeaf(world, i + 4, j + height + 2, k + -5);
placeLeaf(world, i + -5, j + height + 2, k + -4);
placeLeaf(world, i + -3, j + height + 2, k + -4);
placeLeaf(world, i + -1, j + height + 2, k + -4);
placeLeaf(world, i + 1, j + height + 2, k + -4);
placeLeaf(world, i + 3, j + height + 2, k + -4);
placeLeaf(world, i + 5, j + height + 2, k + -4);
placeLeaf(world, i + -4, j + height + 2, k + -3);
placeLeaf(world, i + -2, j + height + 2, k + -3);
placeLeaf(world, i + -1, j + height + 2, k + -3);
placeLeaf(world, i + 1, j + height + 2, k + -3);
placeLeaf(world, i + 2, j + height + 2, k + -3);
placeLeaf(world, i + 4, j + height + 2, k + -3);
placeLeaf(world, i + -3, j + height + 2, k + -2);
placeLeaf(world, i + -1, j + height + 2, k + -2);
placeLeaf(world, i + 1, j + height + 2, k + -2);
placeLeaf(world, i + 3, j + height + 2, k + -2);
placeLeaf(world, i + -5, j + height + 2, k + -1);
placeLeaf(world, i + -4, j + height + 2, k + -1);
placeLeaf(world, i + -3, j + height + 2, k + -1);
placeLeaf(world, i + -2, j + height + 2, k + -1);
placeLeaf(world, i + -1, j + height + 2, k + -1);
placeLeaf(world, i + 0, j + height + 2, k + -1);
placeLeaf(world, i + 1, j + height + 2, k + -1);
placeLeaf(world, i + 2, j + height + 2, k + -1);
placeLeaf(world, i + 3, j + height + 2, k + -1);
placeLeaf(world, i + 4, j + height + 2, k + -1);
placeLeaf(world, i + 5, j + height + 2, k + -1);
placeLeaf(world, i + -6, j + height + 2, k + 0);
placeLeaf(world, i + -1, j + height + 2, k + 0);
placeLeaf(world, i + 0, j + height + 2, k + 0);
placeLeaf(world, i + 1, j + height + 2, k + 0);
placeLeaf(world, i + 6, j + height + 2, k + 0);
placeLeaf(world, i + -5, j + height + 2, k + 1);
placeLeaf(world, i + -4, j + height + 2, k + 1);
placeLeaf(world, i + -3, j + height + 2, k + 1);
placeLeaf(world, i + -2, j + height + 2, k + 1);
placeLeaf(world, i + -1, j + height + 2, k + 1);
placeLeaf(world, i + 0, j + height + 2, k + 1);
placeLeaf(world, i + 1, j + height + 2, k + 1);
placeLeaf(world, i + 2, j + height + 2, k + 1);
placeLeaf(world, i + 3, j + height + 2, k + 1);
placeLeaf(world, i + 4, j + height + 2, k + 1);
placeLeaf(world, i + 5, j + height + 2, k + 1);
placeLeaf(world, i + -3, j + height + 2, k + 2);
placeLeaf(world, i + -1, j + height + 2, k + 2);
placeLeaf(world, i + 1, j + height + 2, k + 2);
placeLeaf(world, i + 3, j + height + 2, k + 2);
placeLeaf(world, i + -4, j + height + 2, k + 3);
placeLeaf(world, i + -2, j + height + 2, k + 3);
placeLeaf(world, i + -1, j + height + 2, k + 3);
placeLeaf(world, i + 1, j + height + 2, k + 3);
placeLeaf(world, i + 2, j + height + 2, k + 3);
placeLeaf(world, i + 4, j + height + 2, k + 3);
placeLeaf(world, i + -5, j + height + 2, k + 4);
placeLeaf(world, i + -3, j + height + 2, k + 4);
placeLeaf(world, i + -1, j + height + 2, k + 4);
placeLeaf(world, i + 1, j + height + 2, k + 4);
placeLeaf(world, i + 3, j + height + 2, k + 4);
placeLeaf(world, i + 5, j + height + 2, k + 4);
placeLeaf(world, i + -4, j + height + 2, k + 5);
placeLeaf(world, i + -1, j + height + 2, k + 5);
placeLeaf(world, i + 1, j + height + 2, k + 5);
placeLeaf(world, i + 4, j + height + 2, k + 5);
placeLeaf(world, i + 0, j + height + 2, k + 6);
placeLeaf(world, i + 0, j + height + 3, k + -5);
placeLeaf(world, i + -4, j + height + 3, k + -4);
placeLeaf(world, i + 0, j + height + 3, k + -4);
placeLeaf(world, i + 4, j + height + 3, k + -4);
placeLeaf(world, i + -3, j + height + 3, k + -3);
placeLeaf(world, i + 0, j + height + 3, k + -3);
placeLeaf(world, i + 3, j + height + 3, k + -3);
placeLeaf(world, i + -2, j + height + 3, k + -2);
placeLeaf(world, i + 0, j + height + 3, k + -2);
placeLeaf(world, i + 2, j + height + 3, k + -2);
placeLeaf(world, i + -1, j + height + 3, k + -1);
placeLeaf(world, i + 0, j + height + 3, k + -1);
placeLeaf(world, i + 1, j + height + 3, k + -1);
placeLeaf(world, i + -5, j + height + 3, k + 0);
placeLeaf(world, i + -4, j + height + 3, k + 0);
placeLeaf(world, i + -3, j + height + 3, k + 0);
placeLeaf(world, i + -2, j + height + 3, k + 0);
placeLeaf(world, i + -1, j + height + 3, k + 0);
placeLeaf(world, i + 1, j + height + 3, k + 0);
placeLeaf(world, i + 2, j + height + 3, k + 0);
placeLeaf(world, i + 3, j + height + 3, k + 0);
placeLeaf(world, i + 4, j + height + 3, k + 0);
placeLeaf(world, i + 5, j + height + 3, k + 0);
placeLeaf(world, i + -1, j + height + 3, k + 1);
placeLeaf(world, i + 0, j + height + 3, k + 1);
placeLeaf(world, i + 1, j + height + 3, k + 1);
placeLeaf(world, i + -2, j + height + 3, k + 2);
placeLeaf(world, i + 0, j + height + 3, k + 2);
placeLeaf(world, i + 2, j + height + 3, k + 2);
placeLeaf(world, i + -3, j + height + 3, k + 3);
placeLeaf(world, i + 0, j + height + 3, k + 3);
placeLeaf(world, i + 3, j + height + 3, k + 3);
placeLeaf(world, i + -4, j + height + 3, k + 4);
placeLeaf(world, i + 0, j + height + 3, k + 4);
placeLeaf(world, i + 4, j + height + 3, k + 4);
placeLeaf(world, i + 0, j + height + 3, k + 5);
for (int c = 0; c < 4; c++) {
spawnCoconuts(world, new BlockPos(i, j + height + 1, k).relative(Direction.from2DDataValue(i)), random, 2, getLeaf());
}
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class RainforestVinesFeature method place.
@Override
public boolean place(FeaturePlaceContext<RainforestVinesConfig> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
RainforestVinesConfig config = context.config();
BlockPos.MutableBlockPos mutablePos = pos.mutable();
int maxY = Math.min(pos.getY() + config.height, world.getHeight());
for (int y = pos.getY(); y < maxY; ++y) {
for (int i = 0; i < config.rollsPerY; i++) {
mutablePos.set(pos);
mutablePos.move(rand.nextInt(config.xzSpread * 2) - config.xzSpread, 0, rand.nextInt(config.xzSpread * 2) - config.xzSpread);
mutablePos.setY(y);
if (world.isEmptyBlock(mutablePos)) {
for (Direction direction : DIRECTIONS) {
mutablePos.move(direction);
BlockState attaching = world.getBlockState(mutablePos);
if ((attaching.getBlock() == Blocks.GRASS_BLOCK && rand.nextInt(4) == 0) || attaching.is(BlockTags.LEAVES)) {
if (direction != Direction.DOWN && VineBlock.isAcceptableNeighbour(world, mutablePos, direction)) {
mutablePos.move(direction.getOpposite());
int len = rand.nextInt(3) + 2;
for (int j = 0; j < len && world.isEmptyBlock(mutablePos); j++) {
world.setBlock(mutablePos, Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(direction), true), Block.UPDATE_CLIENTS);
mutablePos.move(Direction.DOWN);
}
break;
}
}
}
}
}
}
return true;
}
Aggregations