Search in sources :

Example 46 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class TropicraftTrees method create.

private static AbstractTreeGrower create(FeatureProvider featureProvider) {
    return new AbstractTreeGrower() {

        @Nullable
        @Override
        protected ConfiguredFeature<TreeConfiguration, ?> getConfiguredFeature(Random random, boolean beehive) {
            return null;
        }

        @Override
        public boolean growTree(ServerLevel world, ChunkGenerator generator, BlockPos pos, BlockState sapling, Random random) {
            ConfiguredFeature<?, ?> feature = featureProvider.getFeature(world.getServer(), random, this.hasFlowers(world, pos));
            if (feature == null) {
                return false;
            }
            world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_INVISIBLE);
            if (feature.place(world, generator, random, pos)) {
                return true;
            } else {
                world.setBlock(pos, sapling, Block.UPDATE_INVISIBLE);
                return false;
            }
        }

        private boolean hasFlowers(LevelAccessor world, BlockPos origin) {
            BlockPos min = origin.offset(-2, -1, -2);
            BlockPos max = origin.offset(2, 1, 2);
            for (BlockPos pos : BlockPos.MutableBlockPos.betweenClosed(min, max)) {
                if (world.getBlockState(pos).is(BlockTags.FLOWERS)) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) AbstractTreeGrower(net.minecraft.world.level.block.grower.AbstractTreeGrower) LevelAccessor(net.minecraft.world.level.LevelAccessor) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) ChunkGenerator(net.minecraft.world.level.chunk.ChunkGenerator) TreeConfiguration(net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration)

Example 47 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class ReedsFeature method generateTall.

private boolean generateTall(WorldGenLevel world, BlockPos pos, int height, BlockPos.MutableBlockPos mutablePos) {
    for (int y = 0; y < height; y++) {
        mutablePos.setY(pos.getY() + y);
        BlockState state = REEDS.setValue(ReedsBlock.TYPE, y == height - 1 ? ReedsBlock.Type.TOP : ReedsBlock.Type.BOTTOM).setValue(ReedsBlock.WATERLOGGED, world.getBlockState(mutablePos).is(Blocks.WATER));
        world.setBlock(mutablePos, state, Constants.BlockFlags.BLOCK_UPDATE);
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState)

Example 48 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class TropicraftFeatureUtil method isSoil.

public static boolean isSoil(final LevelAccessor world, final BlockPos pos) {
    final BlockState blockState = world.getBlockState(pos);
    final Block block = blockState.getBlock();
    return block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.GRASS_BLOCK || block == Blocks.PODZOL;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block)

Example 49 with BlockState

use of net.minecraft.world.level.block.state.BlockState 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;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) BlockPos(net.minecraft.core.BlockPos) WorldGenLevel(net.minecraft.world.level.WorldGenLevel)

Example 50 with BlockState

use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.

the class SteepPathProcessor method canPlaceLadderAt.

// Check that there is a solid block behind the ladder at this pos, and return the correct ladder state
// Returns null if placement is not possible
private BlockState canPlaceLadderAt(LevelReader level, BlockPos pos, Direction dir) {
    BlockPos check = pos.relative(dir);
    BlockState state = level.getBlockState(check);
    if (!state.isAir()) {
        BlockState ladderState = getLadderState(dir);
        if (ladderState.canSurvive(level, pos)) {
            return ladderState;
        }
    }
    return null;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos)

Aggregations

BlockState (net.minecraft.world.level.block.state.BlockState)141 BlockPos (net.minecraft.core.BlockPos)75 Direction (net.minecraft.core.Direction)18 Level (net.minecraft.world.level.Level)14 Block (net.minecraft.world.level.block.Block)14 ArrayList (java.util.ArrayList)10 ServerLevel (net.minecraft.server.level.ServerLevel)10 SoundType (net.minecraft.world.level.block.SoundType)10 Vec3 (net.minecraft.world.phys.Vec3)10 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)9 Random (java.util.Random)8 ItemStack (net.minecraft.world.item.ItemStack)7 FluidState (net.minecraft.world.level.material.FluidState)7 AABB (net.minecraft.world.phys.AABB)6 BuildBlock (com.wuest.prefab.structures.base.BuildBlock)5 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)5 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)4 HashMap (java.util.HashMap)4