use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class UpTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
NoneFeatureConfiguration config = context.config();
pos = pos.immutable();
final int height = rand.nextInt(4) + 6;
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
if (!getSapling().canSurvive(getSapling().defaultBlockState(), world, pos)) {
return false;
}
world.setBlock(pos.below(), Blocks.DIRT.defaultBlockState(), 3);
for (int y = j; y < j + height; y++) {
placeLog(world, i, y, k);
if (rand.nextInt(5) == 0) {
int x = rand.nextInt(3) - 1 + i;
int z = k;
if (x - i == 0) {
z += rand.nextBoolean() ? 1 : -1;
}
placeLeaf(world, x, y, z);
}
if (y == j + height - 1) {
placeLog(world, i + 1, y, k);
placeLog(world, i - 1, y, k);
placeLog(world, i, y, k + 1);
placeLog(world, i, y, k - 1);
}
}
final int radius = rand.nextInt(2) + 3;
genCircle(world, i, j + height, k, radius, 0, getLeaf(), false);
genCircle(world, i, j + height + 1, k, radius + 2, radius, getLeaf(), false);
genCircle(world, i, j + height + 2, k, radius + 3, radius + 2, getLeaf(), false);
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class NormalPalmTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
pos = pos.immutable();
int height = random.nextInt(4) + 6;
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);
}
int i = pos.getX(), j = pos.getY(), k = pos.getZ();
placeLeaf(world, i, j + height + 2, k);
placeLeaf(world, i, j + height + 1, k + 1);
placeLeaf(world, i, j + height + 1, k + 2);
placeLeaf(world, i, j + height + 1, k + 3);
placeLeaf(world, i, j + height, k + 4);
placeLeaf(world, i + 1, j + height + 1, k);
placeLeaf(world, i + 2, j + height + 1, k);
placeLeaf(world, i + 3, j + height + 1, k);
placeLeaf(world, i + 4, j + height, k);
placeLeaf(world, i, j + height + 1, k - 1);
placeLeaf(world, i, j + height + 1, k - 2);
placeLeaf(world, i, j + height + 1, k - 3);
placeLeaf(world, i, j + height, k - 4);
placeLeaf(world, i - 1, j + height + 1, k);
placeLeaf(world, i - 1, j + height + 1, k - 1);
placeLeaf(world, i - 1, j + height + 1, k + 1);
placeLeaf(world, i + 1, j + height + 1, k - 1);
placeLeaf(world, i + 1, j + height + 1, k + 1);
placeLeaf(world, i - 2, j + height + 1, k);
placeLeaf(world, i - 3, j + height + 1, k);
placeLeaf(world, i - 4, j + height, k);
placeLeaf(world, i + 2, j + height + 1, k + 2);
placeLeaf(world, i + 2, j + height + 1, k - 2);
placeLeaf(world, i - 2, j + height + 1, k + 2);
placeLeaf(world, i - 2, j + height + 1, k - 2);
placeLeaf(world, i + 3, j + height, k + 3);
placeLeaf(world, i + 3, j + height, k - 3);
placeLeaf(world, i - 3, j + height, k + 3);
placeLeaf(world, i - 3, j + height, k - 3);
for (int j1 = 0; j1 < height + 2; j1++) {
BlockPos logPos = pos.above(j1);
if (TreeFeature.validTreePos(world, logPos)) {
placeLog(world, logPos);
}
}
spawnCoconuts(world, new BlockPos(i, j + height, k), random, 2, getLeaf());
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class TallRainforestTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
pos = pos.immutable();
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
final int height = rand.nextInt(15) + 15;
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
if (!isSoil(world, pos.below())) {
return false;
}
if (!isSoil(world, pos.east().below())) {
return false;
}
if (!isSoil(world, pos.west().below())) {
return false;
}
if (!isSoil(world, pos.north().below())) {
return false;
}
if (!isSoil(world, pos.south().below())) {
return false;
}
setState(world, new BlockPos(i, j - 1, k), Blocks.DIRT.defaultBlockState());
setState(world, new BlockPos(i - 1, j - 1, k), Blocks.DIRT.defaultBlockState());
setState(world, new BlockPos(i + 1, j - 1, k), Blocks.DIRT.defaultBlockState());
setState(world, new BlockPos(i, j - 1, k - 1), Blocks.DIRT.defaultBlockState());
setState(world, new BlockPos(i, j - 1, k + 1), Blocks.DIRT.defaultBlockState());
for (int y = j; y < j + height; y++) {
placeLog(world, i, y, k);
placeLog(world, i - 1, y, k);
placeLog(world, i + 1, y, k);
placeLog(world, i, y, k - 1);
placeLog(world, i, y, k + 1);
if (y - j > height / 2 && rand.nextInt(SMALL_LEAF_CHANCE) == 0) {
int nx = rand.nextInt(3) - 1 + i;
int nz = rand.nextInt(3) - 1 + k;
genCircle(world, new BlockPos(nx, y + 1, nz), 1, 0, getLeaf(), false);
genCircle(world, nx, y, nz, 2, 1, getLeaf(), false);
}
if (y - j > height - (height / 4) && y - j < height - 3 && rand.nextInt(SECOND_CANOPY_CHANCE) == 0) {
int nx = i + rand.nextInt(9) - 4;
int nz = k + rand.nextInt(9) - 4;
int leafSize = rand.nextInt(3) + 5;
genCircle(world, nx, y + 3, nz, leafSize - 2, 0, getLeaf(), false);
genCircle(world, nx, y + 2, nz, leafSize - 1, leafSize - 3, getLeaf(), false);
genCircle(world, nx, y + 1, nz, leafSize, leafSize - 1, getLeaf(), false);
placeBlockLine(world, new int[] { i, y - 2, k }, new int[] { nx, y + 2, nz }, getLog());
}
}
int leafSize = rand.nextInt(5) + 9;
genCircle(world, i, j + height, k, leafSize - 2, 0, getLeaf(), false);
genCircle(world, i, j + height - 1, k, leafSize - 1, leafSize - 4, getLeaf(), false);
genCircle(world, i, j + height - 2, k, leafSize, leafSize - 1, getLeaf(), false);
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class EIHFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
byte height = 5;
int i = pos.getX();
int j = pos.getY() + 1;
int k = pos.getZ();
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
if (!TropicraftFeatureUtil.isSoil(world, pos.below()) && world.getBlockState(pos.below()).getMaterial() != Material.SAND) {
return false;
}
setBlock(world, i + 0, j + 0, k + 2, EIH_STATE.get());
setBlock(world, i + 0, j + 0, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 0, k + 4, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + 4, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + 1, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + 1, k + 4, EIH_STATE.get());
setBlock(world, i + 0, j + 1, k + 4, EIH_STATE.get());
setBlock(world, i + -1, j + 1, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 1, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 1, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + 1, k + 1, EIH_STATE.get());
setBlock(world, i + -1, j + 1, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 2, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + 2, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 2, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + 2, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + 3, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 3, k + 2, EIH_STATE.get());
setBlock(world, i + 0, j + 3, k + 1, EIH_STATE.get());
setBlock(world, i + 0, j + 3, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 4, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + 3, k + -1, EIH_STATE.get());
setBlock(world, i + 0, j + 3, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 2, k + -1, EIH_STATE.get());
setBlock(world, i + 0, j + 4, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 4, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + 4, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 5, k + -1, EIH_STATE.get());
setBlock(world, i + 0, j + 5, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 5, k + 1, EIH_STATE.get());
setBlock(world, i + -1, j + 5, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + 3, k + 4, EIH_STATE.get());
setBlock(world, i + -1, j + 4, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + 6, k + -1, EIH_STATE.get());
setBlock(world, i + 0, j + 6, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + 6, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 6, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + 6, k + 1, EIH_STATE.get());
setBlock(world, i + 1, j + 5, k + 0, EIH_STATE.get());
setBlock(world, i + 1, j + 5, k + 1, EIH_STATE.get());
setBlock(world, i + 1, j + 4, k + 1, EIH_STATE.get());
setBlock(world, i + 1, j + 4, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 2, k + 1, EIH_STATE.get());
setBlock(world, i + 0, j + 2, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 1, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 0, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + 6, k + 1, EIH_STATE.get());
setBlock(world, i + 0, j + 5, k + 0, LAVA_STATE);
setBlock(world, i + -1, j + 4, k + 0, LAVA_STATE);
setBlock(world, i + -1, j + 5, k + 0, LAVA_STATE);
setBlock(world, i + -1, j + 3, k + 0, LAVA_STATE);
setBlock(world, i + -1, j + 4, k + 1, LAVA_STATE);
setBlock(world, i + -1, j + 3, k + 1, LAVA_STATE);
setBlock(world, i + -1, j + 2, k + 1, LAVA_STATE);
setBlock(world, i + -1, j + 3, k + 2, LAVA_STATE);
setBlock(world, i + -1, j + 2, k + 2, LAVA_STATE);
setBlock(world, i + -1, j + 1, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + 3, k + 4, EIH_STATE.get());
setBlock(world, i + -2, j + 3, k + 3, EIH_STATE.get());
setBlock(world, i + -2, j + 2, k + 3, EIH_STATE.get());
setBlock(world, i + -2, j + 1, k + 3, EIH_STATE.get());
setBlock(world, i + -2, j + 1, k + 4, EIH_STATE.get());
setBlock(world, i + -2, j + 0, k + 4, EIH_STATE.get());
setBlock(world, i + -2, j + 0, k + 3, EIH_STATE.get());
setBlock(world, i + -2, j + 0, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + 0, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + 1, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + 1, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + 2, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + 2, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 3, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 4, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 5, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 6, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 6, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + 6, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + 5, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + 5, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + 4, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + 4, k + 3, EIH_STATE.get());
setBlock(world, i + -2, j + 5, k + 0, LAVA_STATE);
setBlock(world, i + -2, j + 4, k + 0, LAVA_STATE);
setBlock(world, i + -2, j + 3, k + 0, LAVA_STATE);
setBlock(world, i + -2, j + 4, k + 1, LAVA_STATE);
setBlock(world, i + -2, j + 3, k + 1, LAVA_STATE);
setBlock(world, i + -2, j + 2, k + 1, LAVA_STATE);
setBlock(world, i + -2, j + 3, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + 2, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + 1, k + 2, LAVA_STATE);
setBlock(world, i + -3, j + 0, k + 0, EIH_STATE.get());
setBlock(world, i + -3, j + 0, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + 0, k + 3, EIH_STATE.get());
setBlock(world, i + -3, j + 0, k + 4, EIH_STATE.get());
setBlock(world, i + -3, j + 1, k + 4, EIH_STATE.get());
setBlock(world, i + -3, j + 1, k + 3, EIH_STATE.get());
setBlock(world, i + -3, j + 2, k + 3, EIH_STATE.get());
setBlock(world, i + -3, j + 1, k + 0, EIH_STATE.get());
setBlock(world, i + -3, j + 1, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + 2, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + 2, k + 1, EIH_STATE.get());
setBlock(world, i + -3, j + 2, k + 0, EIH_STATE.get());
setBlock(world, i + -3, j + 3, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + 4, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + 3, k + 1, EIH_STATE.get());
setBlock(world, i + -3, j + 3, k + 0, EIH_STATE.get());
setBlock(world, i + -3, j + 3, k + -1, EIH_STATE.get());
setBlock(world, i + -3, j + 4, k + -1, EIH_STATE.get());
setBlock(world, i + -3, j + 5, k + -1, EIH_STATE.get());
setBlock(world, i + -3, j + 6, k + -1, EIH_STATE.get());
setBlock(world, i + -3, j + 6, k + 0, EIH_STATE.get());
setBlock(world, i + -3, j + 6, k + 1, EIH_STATE.get());
setBlock(world, i + -4, j + 5, k + 0, EIH_STATE.get());
setBlock(world, i + -4, j + 4, k + 0, EIH_STATE.get());
setBlock(world, i + -4, j + 4, k + 1, EIH_STATE.get());
setBlock(world, i + 0, j + 4, k + 0, LAVA_STATE);
setBlock(world, i + 0, j + 4, k + 1, LAVA_STATE);
setBlock(world, i + -3, j + 4, k + 0, LAVA_STATE);
setBlock(world, i + -3, j + 4, k + 1, LAVA_STATE);
setBlock(world, i + -3, j + 5, k + 0, LAVA_STATE);
setBlock(world, i + -4, j + 5, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + 1, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 1, k + -1, EIH_STATE.get());
setBlock(world, i + -2, j + 0, k + -1, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + -1, EIH_STATE.get());
setBlock(world, i + -3, j + -1, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + -1, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + -1, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + -1, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + -1, k + 1, EIH_STATE.get());
setBlock(world, i + -1, j + -1, k + 1, EIH_STATE.get());
setBlock(world, i + -3, j + -1, k + 2, EIH_STATE.get());
setBlock(world, i + 0, j + -1, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + -1, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + -1, k + 3, EIH_STATE.get());
setBlock(world, i + -3, j + -2, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + -2, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + -2, k + 3, EIH_STATE.get());
setBlock(world, i + 0, j + -2, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + -2, k + 1, EIH_STATE.get());
setBlock(world, i + -2, j + -2, k + 1, EIH_STATE.get());
setBlock(world, i + -3, j + -2, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + -2, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + -2, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + -2, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + -3, k + 2, EIH_STATE.get());
setBlock(world, i + -1, j + -3, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + 0, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + 0, k + 2, LAVA_STATE);
setBlock(world, i + -1, j + -1, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + -1, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + -2, k + 2, LAVA_STATE);
setBlock(world, i + -1, j + -2, k + 2, LAVA_STATE);
setBlock(world, i + -2, j + -3, k + 3, EIH_STATE.get());
setBlock(world, i + -1, j + -3, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + -3, k + 2, EIH_STATE.get());
setBlock(world, i + -3, j + -3, k + 2, EIH_STATE.get());
setBlock(world, i + -2, j + -3, k + 1, EIH_STATE.get());
setBlock(world, i + -1, j + -3, k + 1, EIH_STATE.get());
setBlock(world, i + -3, j + -3, k + 0, EIH_STATE.get());
setBlock(world, i + -2, j + -3, k + 0, EIH_STATE.get());
setBlock(world, i + -1, j + -3, k + 0, EIH_STATE.get());
setBlock(world, i + 0, j + -3, k + 0, EIH_STATE.get());
// Coords of the first eye
final int eyeOneX = i;
final int eyeOneY = j + 5;
final int eyeOneZ = k + 1;
// Coords of the second eye
final int eyeTwoX = i - 3;
final int eyeTwoY = j + 5;
final int eyeTwoZ = k + 1;
final int eyeRand = world.getRandom().nextInt(9);
// Place eyes
placeEye(world, eyeOneX, eyeOneY, eyeOneZ, eyeRand);
placeEye(world, eyeTwoX, eyeTwoY, eyeTwoZ, eyeRand);
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class SingleUndergrowthFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel level = context.level();
context.chunkGenerator();
Random rand = context.random();
BlockPos pos = context.origin();
context.config();
int size = 2;
if (rand.nextInt(LARGE_BUSH_CHANCE) == 0) {
size = 3;
}
if (!isValidPosition(level, pos)) {
return false;
}
if (goesBeyondWorldSize(level, pos.getY(), size)) {
return false;
}
if (!TropicraftFeatureUtil.isSoil(level, pos.below())) {
return false;
}
level.setBlock(pos.below(), Blocks.DIRT.defaultBlockState(), 3);
int count = 0;
if (isValidPosition(level, pos) && pos.getY() < 255) {
for (int y = pos.getY(); y < pos.getY() + size; y++) {
int bushWidth = size - (y - pos.getY());
for (int x = pos.getX() - bushWidth; x < pos.getX() + bushWidth; x++) {
int xVariance = x - pos.getX();
for (int z = pos.getZ() - bushWidth; z < pos.getZ() + bushWidth; z++) {
int zVariance = z - pos.getZ();
final BlockPos newPos = new BlockPos(x, y, z);
if ((Math.abs(xVariance) != bushWidth || Math.abs(zVariance) != bushWidth || rand.nextInt(2) != 0) && isValidPosition(level, newPos)) {
setBlock(level, newPos, TropicraftBlocks.KAPOK_LEAVES.get().defaultBlockState());
}
}
}
}
++count;
}
setBlock(level, pos, TropicraftBlocks.MAHOGANY_LOG.get().defaultBlockState());
return count > 0;
}
Aggregations