Search in sources :

Example 1 with DoubleBlockHalf

use of net.minecraft.state.properties.DoubleBlockHalf in project upgrade-aquatic by team-abnormals.

the class FloweringRushBlock method onBlockHarvested.

public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
    DoubleBlockHalf doubleblockhalf = state.get(HALF);
    BlockPos blockpos = doubleblockhalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    if (blockstate.getBlock() == this && blockstate.get(HALF) != doubleblockhalf) {
        worldIn.playEvent(player, 2001, blockpos, Block.getStateId(blockstate));
        if (!worldIn.isRemote && !player.isCreative()) {
            spawnDrops(state, worldIn, pos, (TileEntity) null, player, player.getHeldItemMainhand());
            spawnDrops(blockstate, worldIn, pos, (TileEntity) null, player, player.getHeldItemMainhand());
        }
        if (blockstate.get(HALF) == DoubleBlockHalf.LOWER) {
            worldIn.destroyBlock(blockpos, false);
        }
    }
    super.onBlockHarvested(worldIn, pos, state, player);
}
Also used : BlockState(net.minecraft.block.BlockState) DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with DoubleBlockHalf

use of net.minecraft.state.properties.DoubleBlockHalf in project upgrade-aquatic by team-abnormals.

the class TallBeachgrassBlock method onBlockHarvested.

public void onBlockHarvested(World worldIn, BlockPos pos, BlockState state, PlayerEntity player) {
    DoubleBlockHalf doubleblockhalf = state.get(HALF);
    BlockPos blockpos = doubleblockhalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down();
    BlockState blockstate = worldIn.getBlockState(blockpos);
    if (blockstate.getBlock() == this && blockstate.get(HALF) != doubleblockhalf) {
        worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 35);
        worldIn.playEvent(player, 2001, blockpos, Block.getStateId(blockstate));
        if (!worldIn.isRemote && !player.isCreative() && player.getHeldItemMainhand().getItem() instanceof ShearsItem) {
            spawnAsEntity(worldIn, pos, new ItemStack(UABlocks.BEACHGRASS.get()));
            spawnAsEntity(worldIn, pos.up(), new ItemStack(UABlocks.BEACHGRASS.get()));
        } else if (!worldIn.isRemote && !player.isCreative() && !(player.getHeldItemMainhand().getItem() instanceof ShearsItem)) {
            Random rand = new Random();
            if (rand.nextFloat() < 0.125F) {
                spawnAsEntity(worldIn, pos, new ItemStack(Items.BEETROOT_SEEDS));
            }
        }
    }
    super.onBlockHarvested(worldIn, pos, state, player);
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf) BlockPos(net.minecraft.util.math.BlockPos) ShearsItem(net.minecraft.item.ShearsItem) ItemStack(net.minecraft.item.ItemStack)

Example 3 with DoubleBlockHalf

use of net.minecraft.state.properties.DoubleBlockHalf in project FarmersDelight by vectorwing.

the class WildRiceBlock method updateShape.

@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
    BlockState currentState = super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
    DoubleBlockHalf half = stateIn.getValue(HALF);
    if (!currentState.isAir()) {
        worldIn.getLiquidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn));
    }
    if (facing.getAxis() != Direction.Axis.Y || half == DoubleBlockHalf.LOWER != (facing == Direction.UP) || facingState.getBlock() == this && facingState.getValue(HALF) != half) {
        return half == DoubleBlockHalf.LOWER && facing == Direction.DOWN && !stateIn.canSurvive(worldIn, currentPos) ? Blocks.AIR.defaultBlockState() : stateIn;
    } else {
        return Blocks.AIR.defaultBlockState();
    }
}
Also used : DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf)

Example 4 with DoubleBlockHalf

use of net.minecraft.state.properties.DoubleBlockHalf in project FarmersDelight by vectorwing.

the class WildRiceBlock method removeBottomHalf.

protected static void removeBottomHalf(World world, BlockPos pos, BlockState state, PlayerEntity player) {
    DoubleBlockHalf half = state.getValue(HALF);
    if (half == DoubleBlockHalf.UPPER) {
        BlockPos floorPos = pos.below();
        BlockState floorState = world.getBlockState(floorPos);
        if (floorState.getBlock() == state.getBlock() && floorState.getValue(HALF) == DoubleBlockHalf.LOWER) {
            world.setBlock(floorPos, Blocks.WATER.defaultBlockState(), 35);
            world.levelEvent(player, 2001, floorPos, Block.getId(floorState));
        }
    }
}
Also used : DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with DoubleBlockHalf

use of net.minecraft.state.properties.DoubleBlockHalf in project minecolonies by ldtteam.

the class BlockScarecrow method use.

@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
    // If the world is server, open the inventory of the field.
    if (!worldIn.isClientSide) {
        // Get the entity of the bottom half
        DoubleBlockHalf half = state.getValue(HALF);
        final TileEntity entity = worldIn.getBlockEntity(half == DoubleBlockHalf.UPPER ? pos.below() : pos);
        if (entity instanceof ScarecrowTileEntity) {
            NetworkHooks.openGui((ServerPlayerEntity) player, (ScarecrowTileEntity) entity, pos);
        } else {
            return ActionResultType.FAIL;
        }
    }
    // This must succeed in Remote to stop more right click interactions like placing blocks
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) DoubleBlockHalf(net.minecraft.state.properties.DoubleBlockHalf) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity)

Aggregations

DoubleBlockHalf (net.minecraft.state.properties.DoubleBlockHalf)12 BlockPos (net.minecraft.util.math.BlockPos)8 BlockState (net.minecraft.block.BlockState)5 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Random (java.util.Random)1 DoorBlock (net.minecraft.block.DoorBlock)1 TrapDoorBlock (net.minecraft.block.TrapDoorBlock)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ItemStack (net.minecraft.item.ItemStack)1 ShearsItem (net.minecraft.item.ShearsItem)1 SoundEvent (net.minecraft.util.SoundEvent)1 World (net.minecraft.world.World)1