BetterEnd/src/main/java/ru/betterend/world/features/UnderwaterPlantFeature.java
2021-06-11 15:47:04 +03:00

37 lines
1.3 KiB
Java

package ru.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.blocks.BaseDoublePlantBlock;
import ru.bclib.util.BlocksHelper;
import java.util.Random;
public class UnderwaterPlantFeature extends UnderwaterPlantScatter {
private final Block plant;
public UnderwaterPlantFeature(Block plant, int radius) {
super(radius);
this.plant = plant;
}
@Override
public boolean canGenerate(WorldGenLevel world, Random random, BlockPos center, BlockPos blockPos, float radius) {
return super.canSpawn(world, blockPos) && plant.canSurvive(plant.defaultBlockState(), world, blockPos);
}
@Override
public void generate(WorldGenLevel world, Random random, BlockPos blockPos) {
if (plant instanceof BaseDoublePlantBlock) {
int rot = random.nextInt(4);
BlockState state = plant.defaultBlockState().setValue(BaseDoublePlantBlock.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(BaseDoublePlantBlock.TOP, true));
}
else {
BlocksHelper.setWithoutUpdate(world, blockPos, plant);
}
}
}