@ Override public EnumActionResult onItemUse ( EntityPlayer player , World world , BlockPos pos , EnumHand hand , EnumFacing side , float hitX , float hitY , float hitZ ) { ItemStack itemStack = player . getHeldItem ( hand ) ; if ( itemStack . isEmpty ( ) ) return EnumActionResult . FAIL ; if ( ! player . canPlayerEdit ( pos . offset ( side ) , side , itemStack ) ) return EnumActionResult . FAIL ; //first check if the block clicked can be merged with the one in hand IBlockState placedState = checkMerge ( itemStack , player , world , pos , side , hitX , hitY , hitZ ) ; BlockPos p = pos ; //can't merge, offset the placed position to where the block should be placed in the world if ( placedState == null ) { p = pos . offset ( side ) ; float x = hitX - side . getFrontOffsetX ( ) ; float y = hitY - side . getFrontOffsetY ( ) ; float z = hitZ - side . getFrontOffsetZ ( ) ; //check for merge at the new position too placedState = checkMerge ( itemStack , player , world , p , side , x , y , z ) ; } if ( placedState == null ) return super . onItemUse ( player , world , pos , hand , side , hitX , hitY , hitZ ) ; //block can be merged Block block = placedState . getBlock ( ) ; if ( world . checkNoEntityCollision ( placedState . getCollisionBoundingBox ( world , p ) ) && world . setBlockState ( p , placedState , 3 ) ) { SoundType soundType = block . getSoundType ( placedState , world , pos , player ) ; world . playSound ( player , pos , soundType . getPlaceSound ( ) , SoundCategory . BLOCKS , ( soundType . getVolume ( ) + 1.0F ) / 2.0F , soundType . getPitch ( ) * 0.8F ) ; itemStack . shrink ( 1 ) ; } return EnumActionResult . SUCCESS ; }
onItemUse needs to be overriden to be able to handle merged blocks and components .