use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class ReedsFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos origin = context.origin();
if (!world.getBlockState(origin).is(Blocks.WATER) || !world.isEmptyBlock(origin.above())) {
return false;
}
boolean generated = false;
BlockPos.MutableBlockPos bottomPos = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
for (int i = 0; i < 32; i++) {
int x = origin.getX() + random.nextInt(8) - random.nextInt(8);
int z = origin.getZ() + random.nextInt(8) - random.nextInt(8);
int y = world.getHeight(Heightmap.Types.OCEAN_FLOOR, x, z);
bottomPos.set(x, y, z);
generated |= this.generateOne(world, bottomPos, random, mutablePos);
}
return generated;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class CurvedPalmTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
pos = pos.immutable();
final int height = 9 + random.nextInt(3);
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);
}
final int x = pos.getX(), y = pos.getY(), z = pos.getZ();
int dir = this.pickDirection(world, random, x, z);
this.setDir(dir);
this.setOrigin(x, z);
// x bb check
for (int xx = 0; xx < 4; xx++) {
for (int yy = 0; yy < height; yy++) {
final BlockPos posWithDir = getPosWithDir(xx, yy + y, 0);
if (!isAir(world, posWithDir)) {
return false;
}
}
}
// z bb check
for (int xx = 0; xx < 9; xx++) {
for (int zz = 0; zz < 9; zz++) {
for (int yy = height - 3; yy < height + 4; yy++) {
if (!isAir(world, getPosWithDir(xx + TOP_OFFSET, yy + y, zz))) {
return false;
}
}
}
}
// generate curved trunk
for (int xx = 0, yy = 0; yy < height; yy++) {
placeBlockWithDir(world, xx, yy + y, 0, getLog());
if (yy == 0 || yy == 1 || yy == 3) {
xx++;
placeBlockWithDir(world, xx, yy + y, 0, getLog());
}
if (yy == height - 2) {
spawnCoconuts(world, getPosWithDir(xx, yy + y, 0), random, 2, getLeaf());
}
}
// reset origin
setOrigin(getActualXAt(TOP_OFFSET, 0), getActualZAt(TOP_OFFSET, 0));
// inner leaf placement
for (int yy = 1; yy < 5; yy++) {
if (yy == 4) {
this.placeBlockWithDir(world, 1, yy + y + height - 1, 0, getLeaf());
} else {
this.placeBlockWithDir(world, 0, yy + y + height - 1, 0, getLeaf());
}
}
// outer leaf placement
for (int curDir = 0; curDir < 4; curDir++) {
setDir(curDir);
int yy = height - 1;
placeBlockWithDir(world, 1, yy - 1 + y, 1, getLeaf());
placeBlockWithDir(world, 2, yy - 2 + y, 1, getLeaf());
placeBlockWithDir(world, 1, yy - 2 + y, 2, getLeaf());
placeBlockWithDir(world, 2, yy - 3 + y, 2, getLeaf());
placeBlockWithDir(world, 1, yy + 1 + y, 1, getLeaf());
placeBlockWithDir(world, 2, yy + 2 + y, 1, getLeaf());
placeBlockWithDir(world, 1, yy + 2 + y, 2, getLeaf());
placeBlockWithDir(world, 2, yy + 3 + y, 2, getLeaf());
for (int xx = 1; xx < 5; xx++) {
if (xx == 4) {
yy--;
}
placeBlockWithDir(world, xx, yy + y, 0, getLeaf());
}
}
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class FruitTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<FruitTreeConfig> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
FruitTreeConfig config = context.config();
pos = pos.immutable();
int height = rand.nextInt(3) + 4;
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
BlockState sapling = config.sapling;
if (!sapling.canSurvive(world, pos)) {
return false;
}
setDirtAt(world, pos.below());
for (int y = (pos.getY() - 3) + height; y <= pos.getY() + height; y++) {
int presizeMod = y - (pos.getY() + height);
int size = 1 - presizeMod / 2;
for (int x = pos.getX() - size; x <= pos.getX() + size; x++) {
int localX = x - pos.getX();
for (int z = pos.getZ() - size; z <= pos.getZ() + size; z++) {
int localZ = z - pos.getZ();
if ((Math.abs(localX) != size || Math.abs(localZ) != size || rand.nextInt(2) != 0 && presizeMod != 0) && TreeFeature.isAirOrLeaves(world, new BlockPos(x, y, z))) {
BlockPos leafPos = new BlockPos(x, y, z);
if (rand.nextBoolean()) {
// Set fruit-bearing leaves here
setBlock(world, leafPos, config.fruitLeaves);
} else {
// Set plain fruit tree leaves here
setBlock(world, leafPos, config.leaves);
}
}
}
}
}
// Tree stem
for (int y = 0; y < height; y++) {
BlockPos logPos = pos.above(y);
if (TreeFeature.validTreePos(world, logPos)) {
setBlock(world, logPos, config.wood);
}
}
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class TualungFeature 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();
int height = rand.nextInt(maxHeight - baseHeight) + baseHeight + j;
int branches = rand.nextInt(3) + 3;
if (goesBeyondWorldSize(world, pos.getY(), height - j)) {
return false;
}
if (height + 6 > 256) {
return false;
}
if (!isBBAvailable(world, pos, height - j)) {
return false;
}
if (!getSapling().canSurvive(getSapling().defaultBlockState(), world, pos)) {
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 < 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);
}
for (int x = 0; x < branches; x++) {
int branchHeight = rand.nextInt(4) + 2 + height;
int bx = rand.nextInt(15) - 8 + i;
int bz = rand.nextInt(15) - 8 + k;
placeBlockLine(world, new int[] { i + sign((bx - i) / 2), height, k + sign((bz - k) / 2) }, new int[] { bx, branchHeight, bz }, getLog());
genCircle(world, bx, branchHeight, bz, 2, 1, getLeaf(), false);
genCircle(world, bx, branchHeight + 1, bz, 3, 2, getLeaf(), false);
}
return true;
}
use of net.minecraft.world.level.WorldGenLevel in project Tropicraft by Tropicraft.
the class MangroveTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<TreeConfiguration> pContext) {
WorldGenLevel world = pContext.level();
BlockPos pos = pContext.origin();
TreeConfiguration config = pContext.config();
BlockPos placePos = this.findPlacePos(world, pos, config);
if (placePos == null)
return false;
BlockPos soilPos = placePos.below();
BlockState soilState = world.getBlockState(soilPos);
// Force placement: put dirt under the current position so that the tree always places
boolean replaceSoil = soilState.is(TropicraftTags.Blocks.MUD) || soilState.getFluidState().is(FluidTags.WATER) || soilState.is(Tags.Blocks.SAND) || (world.getBlockState(soilPos.below()).getFluidState().is(FluidTags.WATER));
try {
if (replaceSoil)
world.setBlock(soilPos, Blocks.DIRT.defaultBlockState(), Block.UPDATE_ALL);
return this.backing.place(new FeaturePlaceContext<>(world, pContext.chunkGenerator(), pContext.random(), pos, config));
} finally {
if (replaceSoil)
world.setBlock(soilPos, soilState, Block.UPDATE_ALL);
}
}
Aggregations