Search in sources :

Example 1 with BooleanProperty

use of net.minecraft.state.property.BooleanProperty in project Biome-Makeover by Lemonszz.

the class IvyBlock method scheduledTick.

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
    Pair<Integer, Integer> nearbyCount = getNearbyIvyCount(world, pos);
    if (nearbyCount.getLeft() >= 6 && nearbyCount.getRight() >= 1)
        return;
    Direction checkDirection = getRandomStateSide(state, random);
    if (checkDirection == null)
        return;
    Direction direction = Direction.random(random);
    while (direction == checkDirection.getOpposite()) direction = Direction.random(random);
    BlockPos offsetPos = pos.offset(direction);
    BlockState offsetState = world.getBlockState(offsetPos);
    BooleanProperty dirProperty = getPropertyForDirection(direction);
    if (!state.get(dirProperty) && isValidPlaceFace(world, direction, offsetPos, offsetState)) {
        if (hasAdjacentSide(direction, state))
            world.setBlockState(pos, state.with(dirProperty, true));
    } else if (hasAdjacentSide(direction, state) && canReplace(offsetState)) {
        BlockPos hitPos = offsetPos.offset(checkDirection);
        BlockState hitState = world.getBlockState(hitPos);
        if (isValidPlaceFace(world, direction, hitPos, hitState)) {
            placeOrAddTo(world, offsetPos, checkDirection);
            return;
        }
        BlockPos creepPos = pos.offset(direction).offset(checkDirection);
        BlockState creepState = world.getBlockState(creepPos);
        if (canReplace(creepState)) {
            hitPos = pos.offset(checkDirection);
            hitState = world.getBlockState(hitPos);
            if (isValidPlaceFace(world, direction, hitPos, hitState)) {
                placeOrAddTo(world, creepPos, direction.getOpposite());
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BooleanProperty(net.minecraft.state.property.BooleanProperty) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.math.Direction)

Example 2 with BooleanProperty

use of net.minecraft.state.property.BooleanProperty in project AurorasDecorations by LambdAurora.

the class BurntVineBlock method getPlacementShape.

private BlockState getPlacementShape(BlockState state, BlockView world, BlockPos pos) {
    var upPos = pos.up();
    if (state.get(UP)) {
        state = state.with(UP, shouldConnectTo(world, upPos, Direction.DOWN));
    }
    BlockState blockState = null;
    var it = Direction.Type.HORIZONTAL.iterator();
    while (true) {
        Direction facing;
        BooleanProperty facingProperty;
        do {
            if (!it.hasNext()) {
                return state;
            }
            facing = it.next();
            facingProperty = getFacingProperty(facing);
        } while (!state.get(facingProperty));
        boolean shouldHaveSide = this.shouldHaveSide(world, pos, facing);
        if (!shouldHaveSide) {
            if (blockState == null) {
                blockState = world.getBlockState(upPos);
            }
            shouldHaveSide = blockState.isOf(Blocks.VINE) && blockState.get(facingProperty);
        }
        state = state.with(facingProperty, shouldHaveSide);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) BooleanProperty(net.minecraft.state.property.BooleanProperty) Direction(net.minecraft.util.math.Direction)

Aggregations

BlockState (net.minecraft.block.BlockState)2 BooleanProperty (net.minecraft.state.property.BooleanProperty)2 Direction (net.minecraft.util.math.Direction)2 BlockPos (net.minecraft.util.math.BlockPos)1