Search in sources :

Example 1 with Config

use of com.teamresourceful.resourcefulbees.config.Config in project ResourcefulBees by Resourceful-Bees.

the class BeeNestFeature method place.

@Override
public boolean place(@NotNull WorldGenLevel worldIn, @NotNull ChunkGenerator generator, @NotNull Random rand, @NotNull BlockPos pos, @NotNull NoneFeatureConfiguration config) {
    if (!Config.GENERATE_BEE_NESTS.get()) {
        return false;
    }
    Biome biome = worldIn.getBiome(pos);
    Optional<ResourceKey<Biome>> biomeKey = worldIn.getBiomeName(pos);
    Biome.BiomeCategory category = biome.getBiomeCategory();
    boolean headsOrTails = rand.nextBoolean();
    BlockPos newPos = getYPos(worldIn, rand, category, pos);
    if (newPos.getY() == 0) {
        return false;
    }
    Direction direction;
    BlockPos finalNewPos = newPos.mutable();
    List<Direction> possibleDirections = ALLOWED_DIRECTIONS.stream().filter(dir -> worldIn.isEmptyBlock(finalNewPos.relative(dir, 1))).collect(Collectors.toList());
    if (!possibleDirections.isEmpty()) {
        direction = possibleDirections.get(rand.nextInt(possibleDirections.size()));
    } else {
        return false;
    }
    Block nest;
    BlockState platformBlockState = null;
    switch(category) {
        case THEEND:
            nest = ModBlocks.PURPUR_BEE_NEST.get();
            break;
        case NETHER:
            nest = getNetherNest(headsOrTails, biomeKey.orElse(null));
            platformBlockState = Blocks.OBSIDIAN.defaultBlockState();
            break;
        case SAVANNA:
        case DESERT:
        case MESA:
            nest = ModBlocks.ACACIA_BEE_NEST.get();
            break;
        case JUNGLE:
            nest = ModBlocks.JUNGLE_BEE_NEST.get();
            break;
        case BEACH:
        case OCEAN:
            nest = ModBlocks.PRISMARINE_BEE_NEST.get();
            platformBlockState = isFrozenBiome(biomeKey.orElse(null)) ? Blocks.PACKED_ICE.defaultBlockState() : Blocks.STRIPPED_OAK_WOOD.defaultBlockState();
            break;
        case ICY:
        case TAIGA:
            platformBlockState = Blocks.PACKED_ICE.defaultBlockState();
            nest = ModBlocks.SPRUCE_BEE_NEST.get();
            break;
        case MUSHROOM:
            nest = selectNest(headsOrTails, ModBlocks.RED_MUSHROOM_BEE_NEST.get(), ModBlocks.BROWN_MUSHROOM_BEE_NEST.get());
            break;
        case SWAMP:
            nest = ModBlocks.OAK_BEE_NEST.get();
            platformBlockState = Blocks.STRIPPED_SPRUCE_WOOD.defaultBlockState();
            break;
        case FOREST:
            nest = selectNest(headsOrTails, ModBlocks.BIRCH_BEE_NEST.get(), ModBlocks.DARK_OAK_BEE_NEST.get());
            break;
        case RIVER:
            platformBlockState = isFrozenBiome(biomeKey.orElse(null)) ? Blocks.PACKED_ICE.defaultBlockState() : Blocks.OAK_WOOD.defaultBlockState();
            nest = overworldBlocks.next();
            break;
        default:
            platformBlockState = Blocks.OAK_WOOD.defaultBlockState();
            nest = overworldBlocks.next();
    }
    BlockState newState = nest.defaultBlockState().setValue(BeehiveBlock.FACING, direction);
    BlockPos belowHive = newPos.offset(0, -1, 0);
    if (worldIn.getBlockState(belowHive).getBlock().equals(Blocks.WATER)) {
        generateHivePlatform(worldIn, belowHive, platformBlockState, direction, Blocks.WATER);
    }
    if (category.equals(Biome.BiomeCategory.NETHER) && worldIn.getBlockState(belowHive).getBlock().equals(Blocks.LAVA)) {
        generateHivePlatform(worldIn, belowHive, platformBlockState, direction, Blocks.LAVA);
    }
    worldIn.setBlock(newPos, newState, 1);
    setNestBees(newPos, biomeKey.orElse(null), worldIn, rand);
    return true;
}
Also used : NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) Config(com.teamresourceful.resourcefulbees.config.Config) ModBlocks(com.teamresourceful.resourcefulbees.registry.ModBlocks) Direction(net.minecraft.core.Direction) EntityType(net.minecraft.world.entity.EntityType) Biomes(net.minecraft.world.level.biome.Biomes) BlockState(net.minecraft.world.level.block.state.BlockState) RandomCollection(com.teamresourceful.resourcefulbees.utils.RandomCollection) Random(java.util.Random) Biome(net.minecraft.world.level.biome.Biome) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) MathUtils(com.teamresourceful.resourcefulbees.utils.MathUtils) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) WorldGenLevel(net.minecraft.world.level.WorldGenLevel) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) EnumSet(java.util.EnumSet) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) ResourceKey(net.minecraft.resources.ResourceKey) Collectors(java.util.stream.Collectors) Blocks(net.minecraft.world.level.block.Blocks) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) Feature(net.minecraft.world.level.levelgen.feature.Feature) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Codec(com.mojang.serialization.Codec) CompoundTag(net.minecraft.nbt.CompoundTag) Entity(net.minecraft.world.entity.Entity) BeeRegistry(com.teamresourceful.resourcefulbees.registry.BeeRegistry) BlockPos(net.minecraft.core.BlockPos) CustomBeeData(com.teamresourceful.resourcefulbees.api.beedata.CustomBeeData) ResourcefulBees(com.teamresourceful.resourcefulbees.ResourcefulBees) Heightmap(net.minecraft.world.level.levelgen.Heightmap) Optional(java.util.Optional) Block(net.minecraft.world.level.block.Block) NotNull(org.jetbrains.annotations.NotNull) Biome(net.minecraft.world.level.biome.Biome) BlockState(net.minecraft.world.level.block.state.BlockState) BeehiveBlock(net.minecraft.world.level.block.BeehiveBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) ResourceKey(net.minecraft.resources.ResourceKey)

Aggregations

Codec (com.mojang.serialization.Codec)1 ResourcefulBees (com.teamresourceful.resourcefulbees.ResourcefulBees)1 CustomBeeData (com.teamresourceful.resourcefulbees.api.beedata.CustomBeeData)1 Config (com.teamresourceful.resourcefulbees.config.Config)1 BeeRegistry (com.teamresourceful.resourcefulbees.registry.BeeRegistry)1 ModBlocks (com.teamresourceful.resourcefulbees.registry.ModBlocks)1 TieredBeehiveTileEntity (com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity)1 MathUtils (com.teamresourceful.resourcefulbees.utils.MathUtils)1 RandomCollection (com.teamresourceful.resourcefulbees.utils.RandomCollection)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ResourceKey (net.minecraft.resources.ResourceKey)1 Entity (net.minecraft.world.entity.Entity)1 EntityType (net.minecraft.world.entity.EntityType)1